COP 3503 – Final Exam Practice Problems - SOLUTIONS
For the binary tree shown below, show the output of a preorder traversal of the tree.
additional practice do: inorder, postorder, and level order traversals
A, B, C, D, E, F, G, H, I
B, D, C, A, F, H, G, I, E
Postorder – D, C, B, H, I, G, F, E, A
- A, B, E, C, F, D, G, H, I
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.
Show the contents of a stack after each of the following operations.
What is the final value of the
(1) push (20)
(2) push (15)
(3) push (pop( ) - pop( ))
(4) push (10)
(5) push( pop( ) + pop( ))
(6) top( )