CSE 373 Data Structures 09wi, Homework 2

Due at the BEGINNING of class, Friday, 1/23/09

Here are some questions on complexity, algorithm analysis, and the basics of binary trees. You only need to turn in written solutions, although you will need to run some code for one of the problems.

Problems

  1. Order the functions given in Weiss, 2.1 from slowest growth rate to fastest growth rate. IN ADDITION add these functions in: log N, log2 N.  If any of the functions grow at the same rate, be sure to indicate this.
  2. Weiss, question 2.7. For parts (b) and (c), please turn in a printout of your Java code, (no electronic submission required). Hints: you will want to use assorted large values of n to get meaningful experimental results. You may find the library function System.nanoTime() to be useful in timing code fragments.  Note that there are THREE parts to this question, do all 3.  a) calculate big-O, b) run the code *for several values of N* (4 or more) and time it, c) talk about what you see.  For part c, be sure to say something about what you saw in your run-times, are they what you expected based on your big-O calculations?  If not, any ideas why not?  Graphing the values you got from part b might be useful for your discussion. Remember that when giving the big-O running time we do always want the tightest bound we can get.
  3. Weiss question 2.15.
  4. Weiss question 2.27.
  5. Show that the function 100n + 10n3 + 373 is O(n3). (You will need to use the definition of O(f(n)) to do this.)
  6. (Unbalanced binary search trees)
    1. Draw a picture of the integer-valued BST that results when these values are inserted in this order: 6, 21, 11, 13, 4, 8, 30, 55, 12.
    2. Which nodes are the leaves of this tree? Which node is the root?
    3. What is the depth of the node containing 13? What is the height of the node containing 21?
    4. Write down the order in which the node values are reached by (i) a preorder, (ii) an inorder, and (iii) a postorder traversal of the tree.
    5. Draw the sequence of trees (thus draw 4 trees) that result if we perform these operations successively on the original tree from part (a): add(9), delete(6), add(10), delete(4) (You may use either deletion routine described in lecture – do NOT use lazy deletion.).