Homework 5: Trees and Heaps

Due: Friday, May 3rd, before 9:00 pm


Instructions: Your solutions to the following problems must be typed, converted to PDF, and submitted on Blackboard. It is okay to discuss concepts underlying the problems with other students, but all final solutions must be your own work.

All solutions must be typed, converted to PDF, and submitted on Blackboard. No other format is acceptable. Scans or photos of hand-written solutions will not be accepted.


Exercise #1: (5 points) Explain how to use an AVL tree to sort n comparable elements in O(n log n) time.

Exercise #2: (5 points) Consider a modified red-black tree which satisfies all the usual conditions for a red-black tree except that the root may be either black or red. Suppose a modified red-black tree T has a red root node. If we recolor the root node black, is the resulting tree a “normal” red-black tree?

Exercise #3: (10 points) What is the largest and smallest number of nodes in a red-black tree with black-height k?

Exercise #4: (10 points) Show that an n-element heap has maximum height .

Exercise #5: (5 points) In a max-heap with distinct values (keys), where might the smallest element reside?

Exercise #6: (15 points) A d-ary heap is a complete tree in which every internal node (except possibly one) has exactly d children.

  1. Describe how to represent a d-ary heap in an array.
  2. What are the formulas for the children and parent nodes?
  3. What is the maximum height of a d-ary heap with n nodes?