Docsity

CS231 Algorithms Problem Set 5: Evaluating False Algorithms Claims, Assignments of Algorithms and Programming

Toggle sidebar
bg1
1
Wellesley College โ—Š CS231 Algorithms โ—Š October 25, 1996
Handout #21
PROBLEM SET 5
Due: Friday, November 1
Reading: CLR Section 5.5; pp. 197-199; Sections 11.2 & 11.4; Chapter 13 (skim 13.4);
Chapter 14; Sections 15.1 & 15.2.
Animations: Binary Search Trees, Red Black Trees
Suggested Problems: 13.1-2, 13.1-2, 13.1-5; 13.2-1; 13-3.5; 13.4-2; 13-2; 14.1-4,
14.1-5, 14.3-1, 14.3-2, 14.3-5, 14.4-1; 19.1-3, 19-2.
Problem 1 [10]: Dr. Ima Fleik of the Snake Oil Institute of Learning has just submitted a
paper to an algorithms conference in which she claims the following amazing results:
1. An O(n) worst-case running time comparison-based algorithm for constructing a
binary search tree of n elements.
2. An O(n) worst-case running time comparison-based algorithm for enumerating the
elements of a heap in sorted order.
The program chair of the conference has asked you to read Dr. Fleik's paper and evaluate these
two claims. Unfortunately, her algorithms are inscrutable and her analyses are impenetrable. But
then it hits you that you can prove both of her claims are false from first principles by applying
the decision model for comparison sorts to Tree Sort and to Heap Sort. Write a brief but
convincing note to the program chair explaining why Dr. Fleik's claims are false.
Problem 2 [10]: Exercise 13.2-2 on p. 250 of CLR. Note: one of the sets may be
empty.
Problem 3 [25]:
a. Insert the letters A L G O R I T H M S one-by-one into an initially empty red-
black tree by carefully following the algorithm in CLR Section 14.3. (Concentrate
more on the pictures than the code.) Assume that letters earlier in the alphabet are less
than those later in the alphabet. For each letter, show the tree that results from
inserting it into the current tree. Double check that each such tree satisfies all
properties of a red-black tree. (If it doesn't, you have made a mistake and should
correct it before proceeding.)
b. Delete the letters A G L M H in order from the final tree of part a by carefully
following the algorithm in CLR Section 14.4. (Again, concentrate on the pictures.)
For each letter, show the tree that results from deleting it from the current tree.
Double check that each such tree satisfies all properties of a red-black tree.
Problem 4 [30]: CLR Problem 14-2 (p. 278)
Problem 5 [25]: CLR Problem 15.2-1 (p. 289). Specify what information needs to be kept at
each node, and carefully describe how this information can be kept up-to-date by Insert and
Delete while maintaining a worst-case time of ฮ˜(lg(n)) for both of these operations.
pf3

Partial preview of the text

Download CS231 Algorithms Problem Set 5: Evaluating False Algorithms Claims and more Assignments Algorithms and Programming in PDF only on Docsity!

Wellesley College โ—Š CS231 Algorithms โ—Š October 25, 1996 Handout #

PROBLEM SET 5 Due: Friday, November 1

Reading: CLR Section 5.5; pp. 197-199; Sections 11.2 & 11.4; Chapter 13 (skim 13.4); Chapter 14; Sections 15.1 & 15.2.

Animations: Binary Search Trees, Red Black Trees

Suggested Problems: 13.1-2, 13.1-2, 13.1-5; 13.2-1; 13-3.5; 13.4-2; 13-2; 14.1-4, 14.1-5, 14.3-1, 14.3-2, 14.3-5, 14.4-1; 19.1-3, 19-2.

Problem 1 [10]: Dr. Ima Fleik of the Snake Oil Institute of Learning has just submitted a paper to an algorithms conference in which she claims the following amazing results:

  1. An O(n) worst-case running time comparison-based algorithm for constructing a binary search tree of n elements.
  2. An O(n) worst-case running time comparison-based algorithm for enumerating the elements of a heap in sorted order.

The program chair of the conference has asked you to read Dr. Fleik's paper and evaluate these two claims. Unfortunately, her algorithms are inscrutable and her analyses are impenetrable. But then it hits you that you can prove both of her claims are false from first principles by applying the decision model for comparison sorts to Tree Sort and to Heap Sort. Write a brief but convincing note to the program chair explaining why Dr. Fleik's claims are false.

Problem 2 [10]: Exercise 13.2-2 on p. 250 of CLR. Note: one of the sets may be empty.

Problem 3 [25]:

a. Insert the letters A L G O R I T H M S one-by-one into an initially empty red- black tree by carefully following the algorithm in CLR Section 14.3. (Concentrate more on the pictures than the code.) Assume that letters earlier in the alphabet are less than those later in the alphabet. For each letter, show the tree that results from inserting it into the current tree. Double check that each such tree satisfies all properties of a red-black tree. (If it doesn't, you have made a mistake and should correct it before proceeding.)

b. Delete the letters A G L M H in order from the final tree of part a by carefully following the algorithm in CLR Section 14.4. (Again, concentrate on the pictures.) For each letter, show the tree that results from deleting it from the current tree. Double check that each such tree satisfies all properties of a red-black tree.

Problem 4 [30]: CLR Problem 14-2 (p. 278)

Problem 5 [25]: CLR Problem 15.2-1 (p. 289). Specify what information needs to be kept at each node, and carefully describe how this information can be kept up-to-date by Insert and

Delete while maintaining a worst-case time of ฮ˜(lg(n)) for both of these operations.

Extra Credit [20 points]: Exercise 11.4-5 on p. 216 of CLR. Express your algorithm in pseudocode. Your algorithm should print out the keys in an inorder traversal; i.e., the key of every node should be printed out after the key of every node in its left subtree but before every node in its right subtree. Your algorithm should run in O(1) space (i.e., no recursion or explicit stacks), and you should not modify the tree. However, you may assume that you can compare two pointers for equality. Remember that each node holds a pointer to its parent in addition to its left and right subtrees. Hint: if you were exploring a cave system that branched out like a binary tree, what strategy would you use to explore the whole system?