Name: ________________________________

Honor Code Acknowledgment: ___________________


Random Quiz # 11

CPS 100, Spring 1996

Due: March 1


Problem 1: Russian Tea Leaves (2 points)

True or False: In an AVL tree all the leaves are at the same level (height)

Problem 1: Tight Rope (4 points)

The function IsHeightBalanced below determines whether a tree is height-balanced (for all nodes, left and right subtrees differ by no more than one). bool IsHeightBalanced(TNode * tree) // postcondition: returns true if tree is balanced, else returns false { if (tree != 0) { if (IsHeightBalanced(tree->left) && IsHeightBalanced(tree->right) && abs(Height(tree->left) - Height(tree->right)) <= 1) { return true; } return false; } return true; } The complexity of this function is greater than O(n). What is the complexity and why?






Write an auxiliary function, so that the body of IsHeightBalanced will be // some variable definitions return IsAuxBalanced(tree,hleft,hright); and so that IsAuxBalanced works in O(n) time.