COP 3503 – Final Exam Practice Problems - SOLUTIONS
1.
For the binary tree shown below, show the output of a preorder traversal of the tree.
For
additional practice do: inorder, postorder, and level order traversals
.
Preorder –
A, B, C, D, E, F, G, H, I
Additional Practice:
Inorder –
B, D, C, A, F, H, G, I, E
Postorder – D, C, B, H, I, G, F, E, A
Levelorder
- A, B, E, C, F, D, G, H, I
2.
Define and explain the following terms:
(1) a greedy algorithm –
a locally optimal decision is made by the algorithm without regards to the future
consequences or overall optimality of the decision made at that point.
(2) divide and conquer algorithm
a recursive algorithm that consists of two parts: (1) recursively dividing the problem
into smaller and smaller subproblems ultimately arriving at the base case, and (2) the
solution of the original problem is formed from the solutions to the subproblems.
3.
Show the contents of a stack after each of the following operations.
What is the final value of the
stack?
(1) push (20)
(2) push (15)
(3) push (pop( ) - pop( ))
(4) push (10)
(5) push( pop( ) + pop( ))
(6) top( )
1
A
B
E
C
F
G
D
H
I