Download Chapter 12: Binary Search Trees Sheet 5 Exercises 12.1-1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Corecursion wikipedia , lookup

Transcript
Chapter 12: Binary Search Trees
Sheet 5
Exercises
12.1-1
For the set of keys {1, 4, 5, 10, 16, 17, 21}, draw binary search trees of
height 2, 3, 4, 5, and 6.
12.1-2
What is the difference between the binary-search-tree property and
the min-heap property (see page 129)? Can the min-heap property be
used to print out the keys of an n-node tree in sorted order in O(n)
time? Explain how or why not.
12.1-4
Give recursive algorithms that perform preorder and postorder tree
walks in (n) time on a tree of n nodes.
12.2-1
Suppose that we have numbers between 1 and 1000 in a binary search
tree and
want to search for the number 363. Which of the following sequences
could not be the sequence of nodes examined?
a. 2, 252, 401, 398, 330, 344, 397, 363.
b. 924, 220, 911, 244, 898, 258, 362, 363.
c. 925, 202, 911, 240, 912, 245, 363.
d. 2, 399, 387, 219, 266, 382, 381, 278, 363.
e. 935, 278, 347, 621, 299, 392, 358, 363.
12.2-2
Write recursive versions of the TREE-MINIMUM and TREE-MAXIMUM
procedures.
12.2-3
Write the TREE-PREDECESSOR procedure.
12.3-1
Give a recursive version of the TREE-INSERT procedure.
12.3-3
We can sort a given set of n numbers by first building a binary search
tree containing these numbers (using TREE-INSERT repeatedly to insert
the numbers one by one) and then printing the numbers by an inorder
tree walk. What are the worst-case and best-case running times for this
sorting algorithm?
12.3-5
Is the operation of deletion “commutative” in the sense that deleting x
and then y from a binary search tree leaves the same tree as deleting y
and then x? Argue why it is or give a counterexample.
12.4-1
Prove equation