Download lab3sum15

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

Collatz conjecture wikipedia , lookup

Transcript
CSE 2320 Lab Assignment 3
Due August 5, 2015
Goals:
1.
2.
3.
Understanding of red-black trees.
Understanding of recursive binary tree processing.
Understanding of subtree root ranks in binary search trees for supporting ranking queries.
Requirements:
1.
Modify the provided C code for maintaining a red-black tree to process a sequence of commands (standard input) from the
following list:
0 - Exit the program
1 x - Insert positive integer key x, unless x is already present in the tree. (Error message if x is a duplicate.) Besides
inserting the key, odd subtree root ranks must be updated. The odd subtree root rank of a node is the number of odd keys
in the subtree to the left.
2 x - Find the odd rank of x, i.e. the number of odd keys in the tree that are smaller than x (error message if x is not in the
tree). The numbers to the left of each node in the diagram below are the odd ranks.
3 k - Find the smallest and largest keys with odd rank k (error message if there is no key with odd rank k).
4 - Perform an audit on the odd subtree root rank at each node to give a final indication that the tree is “clean” or “corrupt”.
Each command must be echoed to standard output. Commands 1, 2, and 3 must be processed in Q(log n ) time.
2.
Submit your C program on Blackboard by 5:45 p.m. on August 5. One of the comment lines should include the
compilation command used on OMEGA.
Getting Started:
1.
Commands 2 and 3 should not be based on directly applying tree traversal.
2.
Command 4 should traverse the tree, compute the odd size of each subtree, and verify the stored odd sizes. You may
leave the code alone for checking 1) the inorder key property, 2) that there is no downward path with consecutive red
nodes, and 3) that the black-heights are consistent.
6 120
6
1 22
1
0 11
0
7 175
1
2 70
1
6 132
0
3 93
1
2 44
1
1 33
0
6 144
0
81
2 56 2 0
0
2 68
0
5 115
1
4 105
0
8 191
0
180
6 167 8
0
0
6 156
0
10 215
1
9 203
0