

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Due by 11:59 PM Friday 13 Feb 2009
This color indicates recent changes since the homework was first released.
Submit your work via Handin. Name your file
Do the following problems from Chapter 7 of the text. As always, we do not want just the āanswersā, we want the reasoning behind the answers.
(a) Compute the average depth of a node in a perfect binary tree of height h and n = nodes (give a formula). (Give an exact answer for h = 5.) (b) What is the average case effort for a successful search in this tree? (c) What is the worst case effort of a failed search in the tree? (d) What is the average case effort of a failed search in this tree?
For this problem, we want you to be more precise than Big Oh. Specifi- cally, we expect exact formulas in terms of h and n that are both simple and accurate to within 0.5 of the exact answer. Assume that the cost of finding the root is 1, the rootās children 2, and so on.
(a) Your program should perform these steps. (i) It should input an integer h, which is the height of a perfect binary tree. (ii) It should generate in order the integers 1 to 2h+1^ ā 1 and insert these into a set, reporting on the total runtime to do this. (iii) Next, it should loop over these same integers and check if each is in the set, reporting on the total runtime. (iv) The program should next create a vector of the integers used above and randomly shuffle them. After clearing the previous set, it should rebuild it by inserting all of the integers, now in random order, reporting the total runtime. (b) When tested to be correct, run your program for h = 7, 10, 13, 16, 19 (if runtimes are reasonable) and create a 3 x 5 table of the runtimes from the above tests. (c) Discuss your results. Do you think that the set container could be implemented via a vector, a hash table, a binary search tree without balancing, or a binary search tree with balancing? Give reasons.