Title: Outline
1Outline
- What makes a problem nifty?
- Mathematical Reasoning
- Teaser nifty problems
- Inverse Binary Tree Traversal
2Mathematical Reasoning
Applying mathematical techniques, concepts and
processes, either explicitly or implicitly, in
the solution of problems in other words,
mathematical modes of thought that help us to
solve problems in any domain. In its most
general interpretation, every problem-solving
activity requires mathematical thinking. For
example, basic logic, be it used explicitly or
implicitly is required for all problem-solving
activities.
3Logic Conditional
- A teacher said to a student, If you receive an
A on the final exam, then you will pass the
course.'' - Suppose the student did not pass the course.
Which of the following conclusions are valid? - The student received an A on the final exam.
- The student did not receive an A on the final
exam. - The student flunked the final exam.
- If the student passed the course, then he or she
received an A on the final exam. - None of these conclusions is valid.
4Inductive Reasoning
- There are two bugs in a gallon jar. Every
- minute, the number of bugs doubles. If the jar
- is filled in 30 minutes, how long does it take
- for the jar to become half filled with bugs?
5Inductive Reasoning 2
- Consider this same problem, but starting with
- four bugs instead of two. How long does it
- take for the jar to become half filled with
- bugs?
6Logical Problem Solving
A light bulb is hanging in a room. In another
room there are three switches, of which only one
lights the bulb. Initially, all switches are
'off' and the bulb is not lit. Determine
which of the three switches lights the bulb by
visiting the room with the bulb only once.
7Which of the following predicate logic statements
are true for the natural numbers 0,1,2,3, ...
. " x (x gt 17 Ú x lt 12)
" x y (y gt x) y " x (y gt
x) y " x (x gt y) " x
(x gt 17 23 lt x)
8Modeling
Problem Domain
Math logic model
argument
Problem Domain
Logical Conclusion
9Models of Computation
All models of computation can be reasoned about
using mathematics. Assignment rule for
sequential computations r 2i
Pre Condition i ß i 1 r 2i-1
r ß 2 r r 2i
Post Condition
10Reverse Binary Tree Traversal
The following are the inorder and postorder
traversals of a binary tree whose 10 nodes are
labeled 0, 1, 2, , 9 . inorder 4
1 5 6 2 0 8 3 9 7
postorder 4 6 5 2 1 8 9 7 3
0 Draw the corresponding tree T with the nodes
labeled.
11Generalize
Let n 0 with traversal sequences inorder
i0 i1 i2 in postorder p0 p1
p2 pn (no duplicates and inorder
perm(postorder) ) Construct the corresponding
binary tree
12Series of Questions
- What binary tree corresponds to n 0 ?
- inorder postorder empty sequence
- Give a binary tree with 5 nodes
- 0, 1, 2, 3 and 4 whose inorder and
postorder sequences are the same.
13Progress toward generalization
- inorder of T 4 1 5 6 2 0
8 3 9 7 - postorder of T 4 6 5 2 1 8 9
7 3 0 - Give the set of nodes in the left subtree of
T. - Give the set of nodes in the right subtree of
T. - Give the inorder traversal of the left subtree of
T. - Give the inorder traversal of the right subtree
of T. - Give the postorder traversal of the left subtree
of T. - The postorder traversal of the right subtree of
T is? - The label of the root of the left subtree of T
is? - The label of the root of the right subtree of T
is?
14Progress toward generalization (cont)
- inorder of T i0 i1 i2 in
- postorder of T p0 p1 p2 pn
- Give the set of nodes in the left subtree of
T. - Give the set of nodes in the right subtree of
T. - Give the inorder traversal of the left subtree of
T. - Give the inorder traversal of the right subtree
of T. - Give the postorder traversal of the left subtree
of T. - The postorder traversal of the right subtree of
T is? - The label of the root of the left subtree of T
is? - The label of the root of the right subtree of T
is?
15Implementation using Standard ML
Represent the inorder and postorder traveral
sequences as lists in Standard ML val
inorder 4, 1, 5, 6, 2, 0, 8, 3, 9, 7
Develop a Standard ML function definition
createBT a list X a list ? a BinaryTree
which creates the corresponding binary tree T
given the inorder and postorder traversals.
16Binary Tree Constructor
datatype 'a BinaryTree bt_empty bt
of 'a 'a BinaryTree 'a BinaryTree bt( 5,
bt( 4, bt_empty, bt_empty ), bt_empty )
5
4
17fun createBT( , )
bt_empty createBT( inorder, postorder )
if not ( permutation( inorder, postorder ) )
then raise invalid_tree else let
val root last( postorder )
val num_nodes_in_LST position( inorder,
root ) 1 val inorder_left_subtree
first_N( inorder, num_nodes_in_LST )
val postorder_left_subtree first_N(
postorder, num_nodes_in_LST ) val
left_subtree createBT( inorder_left_subtree,
postorder_left_subtree ) val
num_nodes_in_RST length( inorder )
num_nodes_in_LST 1 val
inorder_right_subtree last_N( inorder,
num_nodes_in_RST ) val
postorder_right_subtree remove_last( last_N(
postorder,
num_nodes_in_RST 1) ) val
right_subtree createBT( inorder_right_subtree,
postorder_right_subtree ) in bt(
root, left_subtree, right_subtree ) end
18Resources
- Math Thinking Group
- http//www.math-in-cs.org
- Communication of the ACM (Sept 2003 issue on math
in CS education) - SIGCSE Math CountS
- http//blue.butler.edu/phenders/InRoads
- ITiCSE 2002 materials development group
- http//blue.butler.edu/phenders/iticse2002
- phenders_at_butler.edu
19Resources cont.
- My Foundations of Computing courses
- http//www.butler.edu/csse/cs151 (fall)
- http//www.butler.edu/csse/cs252 (spring)
- Communication of the ACM (Sept 2003 issue on math
in CS education) - Keith Devlin viewpoint article CACM The Real
Reasons Why Software Engineers need Math Oct
2002 - http//blue.butler.edu/phenders/iticse2002
- Alumni survey of FOCS course at SUNY Stony Brook
- http//www.ic.sunysb.edu/cse113/survey/