Basic Algorithms, v22.0310, Fall'98: Homework 4

Due date: Monday November 2, 1998.

Hand in solution in hard copy, STAPLED together.

Doing this homework is useful in preparing for your midterm!

This homework contains some problems that you should do just for your own benefit, and some that you must hand in. The ones that you must hand in are marked with "**".


  1. ** Show that after n-1 passes in the execution of bubble-sort on a sequence of n elements the sequence is sorted.
  2. Do problem C-4.9 on page 142. (Min and Max of sequence of numbers)
  3. Do problem R-5.6 on page 194. (Programs on trees)
  4. ** Do problem R-5.10 on page 195. (Reconstructing binary trees from traversals)
  5. Do problem R-5.17 on page 196. (Bounds on binary trees)
  6. ** Do problem C-5.5 on page 198. (Tree isomorphism)
  7. ** Do problem R-6.5 on page 241. (Omega-bound on a sum)
    HINT: consider the sum of log i from i=n/2 to n, which is clearly less than the sum you are given, from i=1 to n.
  8. Do problem C-6.4 on page 242. (Finding the k-th smallest)
  9. ** Do problem C-6.6 on page 243. (Reporting all keys less than a given one.)
    HINT: recall that a heap is also a binary tree, so you have access to operations associated with binary trees, such as finding the root, and finding the parent, left child, and right child of a node.