Docsity

CMSC 420 Homework 2: Tries and BST, Assignments of Data Structures and Algorithms

Toggle sidebar
bg1
Spring 2002 Sharat
CMSC 420: Homework 2: Tries and BST
•Handed out: 3/7 Due: 3/14 before class starts. Late homeworks will not be accepted.
•Optional questions do not carry points but may be important for “grade-fence sitters.” Answer optional questions on a
separate piece of paper to be retained by the instructor. Otherwise, please answer in the space provided
1. (30 points) (Pessimistic Patricia Tries). Assume lower case Roman alphabet a..z, parent pointers, and the find() method
as in the slides (page 7–8).
(a) Implement remove(String x, TrieNode p) in time proportional to length of x.
(b) Show pictures similar to the one for insert when the strings bull, stop, buy, bid, bell, bear, sell, and stock are removed
in order.
pf3
pf4

Partial preview of the text

Download CMSC 420 Homework 2: Tries and BST and more Assignments Data Structures and Algorithms in PDF only on Docsity!

Spring 2002 Sharat

CMSC 420: Homework 2: Tries and BST

  • Handed out: 3/7 Due: 3/14 before class starts. Late homeworks will not be accepted.
  • Optional questions do not carry points but may be important for “grade-fence sitters.” Answer optional questions on a separate piece of paper to be retained by the instructor. Otherwise, please answer in the space provided
  1. (30 points) (Pessimistic Patricia Tries). Assume lower case Roman alphabet a..z, parent pointers, and the find() method as in the slides (page 7–8).

(a) Implement remove(String x, TrieNode p) in time proportional to length of x.

(b) Show pictures similar to the one for insert when the strings bull, stop, buy, bid, bell, bear, sell, and stock are removed in order.

  1. (Optional) Give an efficient implementation of restructure(x) presented in rebalance(z). Contrast it with the imple- mentation discussed in class.
  2. (20 points) (Vanilla BST). The notion of ‘average’ on page 12 is different from the notion of “expected” on page 13.

(a) Prove the above statement using the first four odd numbers.

(b) Which notion do you prefer? Why?

(b) Use a constructor of the form Node(Key k, Node toRight, Boolean iAmLeaf) to complete in O(log n) time Node i n s e r t ( Key k , Node p ) {

(c) (Optional) Implement remove(Key k, Node p)

(d) Draw four figures to show the execution of your insert code that generates the figure above.