







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Professor: Earls; Class: Data Structures; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Spring 2011;
Typology: Exams
1 / 13
This page cannot be seen from the preview
Don't miss anything!








75 minutes permitted
Print your name, netID, and lab section day/time neatly in the space provided below; print your name at the upper right corner of every page.
(a) You are given a BinarySearchTree class whose insert method inserts its parameter into the binary search tree, using the usual algorithm. Express, using big-O notation, the order of growth of the worst-case running time of the following code, as n increases. Justify your answer. BinarySearchTree bst; // creates an empty binary search tree for (int i = 1; i <= n; i++) // this is the n we are talking about above bst.insert(i);
Given the following two classes:
class IntTriple { class TreeNode { public: public: int first; int element; int second; TreeNode* left; int third; TreeNode* right; }; };
you want a function Verify that takes one parameter, a pointer to a TreeNode. This function should return an object of type IntTriple, whose member variable first will hold 1 if the parameter pointer points to a binary search tree, and which will instead hold 0 if the parameter pointer points to a binary tree that is NOT a binary search tree. You can use the other two variables of the IntTriple however you like. Please note that if the parameter pointer is NULL, then that is considered to be a binary search tree (although an empty one).
IntTriple Verify(TreeNode* ptr) { // your code goes here
(Verifier, continued)
(List of Tree Values, continued)
(a) Explain convincingly that Level-Order traversal on a binary tree of n nodes is O(n).
(c) The AVL Tree balance property was that for any node, the two subtrees of that node differed by at most 1 in height. Why not 0? That is, explain convincingly that requiring each node to have two subtrees of equal height would be problematic.
(d) In the red-black tree insertion algorithm, all the cases for handling a red-parent-with- red-child conflict (we’ll refer to this as a “red-red conflict”) assume that there is another level above the red-red conflict – i.e. they assume that the upper red node in the red-red conflict has a parent. We did not have any case to handle the situation where you have a red node, and the parent of that node happens to be red, but that red parent node has no parent itself. Explain convincingly why we do not need such a case.
(scratch paper)