CSE 373 Data Structures Sp08, Homework 2
Due at the BEGINNING of class, Friday, 4/18/08
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
- Weiss, 2.1.
- 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.
- Weiss question 2.8(b).
- Weiss question 2.11.
- Show that the function 18n + 4n2 + 373 is O(n2).
(You will need to use the definition of O(f(n))
to do this.)
- (Unbalanced binary search trees)
- Draw a picture of the integer-valued BST that
results when these values are inserted in this order: 5, 17, 10,
3, 4, 8, 20, 39, 12.
- Which nodes are the leaves of this tree? Which node is the root?
- What is the depth of the node containing 3? What is the
height of the node containing 5?
- 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.
- Draw the sequence of trees that result if we perform these operations successively on
the original tree from part (a):
add(9)
, delete(3)
, add(13)
, delete(5)
.
- Draw a single binary tree such that each node contains a single
character, a preorder traversal of the tree yields EXAMFUN,
and an inorder traversal yields MAFXUEN.