Trees
Which of the following best describes the running time of finding the minimum item in a right-heavy BST (i.e., a BST with no left children)? A. Constant B. Logarithmic in the number of nodes C. Linear in the height of the tree D. Linear in the number of nodes
A
Which of the following best describes the running time of finding any item in a balanced BST? A. Constant B. Logarithmic in the number of nodes C. Linear in the height of the tree D. Linear in the number of nodes
B
Which of the following best describes the running time of inserting any item in a self-balancing BST? A. Constant B. Logarithmic in the number of nodes C. Linear in the height of the tree D. Linear in the number of nodes
B
Which of the following best describes the running time of finding any item in any BST? A. Constant B. Logarithmic in the number of nodes C. Linear in the height of the tree D. Linear in the number of nodes
C
A binary tree is ________ if all levels, except possibly the last level, contain all possible nodes and all nodes in the last level are as far left as possible.
Complete
Which of the following best describes the running time of finding the minimum item in a left-heavy BST (i.e., a BST with no right children)? A. Constant B. Logarithmic C. Linear in the height of the tree D. Linear in the number of nodes
D
True/False: In a BST, if we are removing a node with two children, we can replace it with the smallest item from its left subtree and it will still be a BST.
False
A binary tree is _______ if every node contains 0 or 2 children.
Full
Consider a left-heavy BST (i.e., all right children are null). What is the running-time behavior of last()? Let N be the number of items in the BST. Let h be the height of the BST. Give the most accurate formula to describe the running-time behavior.
O(1)/1/Constant
Consider a left-heavy BST (i.e., all right children are null). What is the running-time behavior of first()? Let N be the number of items in the BST. Let h be the height of the BST. Give the most accurate formula to describe the running-time behavior.
O(N)/N/Linear
For any BST, what is the behavior of insertion in the worst case?
O(N)/N/Linear
Consider a randomly-constructed BST. What is the running-time behavior of add(x), where x is an item smaller than all of the items currently contained in the BST? Let N be the number of items in the BST. Let h be the height of the BST. Give the most accurate formula to describe the running-time behavior.
O(h)/h
Consider a balanced BST. What is the running-time behavior of add(x), where x is an item smaller than all of the items currently contained in the BST? Let N be the number of items in the BST. Let h be the height of the BST. Give the most accurate formula to describe the running-time behavior.
O(logN)/LogN/Logarithmic
For a balanced BST, what is the behavior of insertion in the average case?
O(logN)/LogN/Logarithmic
A binary tree is _________, if all internal nodes have 2 children and all leaf nodes are at the same level.
Perfect
True/False: The height of a tree is max(right child subtree height, left child subtree height) + 1
True
Which tree traversal will visit the nodes in ascending order: 15, 30, 31, 40, 43, 45, 50?
inorder/in order
What is the height of a tree with a single node?
0
A BST is height balanced if for any node, the heights of the node's left and right subtrees differ by only 0 or ____.
1
How many comparisons are required for a worst case search of a tree with a root node and one child with height 1?
2
Construct a BST by adding 30, 50, 45, 40, 15, 43, 31 (one at a time, in that order). How many leaf nodes are in the tree?
3
What is the worst case (largest) number of comparisons given a perfect BST with N nodes = 7?
3
Construct a BST by adding 30, 50, 45, 40, 15, 43, 31 (one at a time, in that order). What is the height of the tree?
4
What is the worst case (largest) number of comparisons given a perfect BST with N nodes = 31?
5
Level order traversal of a binary tree uses which of the following? A) FIFO Queue B) Priority Queue C) Stack
A
