1. A binary tree is made of nodes, where each node contains a "left" reference, a "right" reference, and a data element. The ________ node in the tree is called the root.
2. Binary trees are particularly useful where data is being added on a regular basis and needs to be organised into a logical structure so that it can be searched. That is, where the data is dynamic
3. Binary trees can be used to hold an ordered set of data. In an ordered binary tree all items to the left of the root will have a smaller key than those on the right of the root. This applies equally to all the _________
4. To insert data into an ordered tree the following ____________ algorithm can be used.
5. Another common use of a binary tree is to hold an algebraic expression, for example: X + Y * 2
6. Read the excerpt below about pre-order and fill in the blanks for no.1. In pre-order, what happens first?
7. In the following example, what is the root node, left most node, and right most node?
8. In this example, pre-order traversal would:
9. What travsersal method would be necessary to produce an output of: 0,1,2,3,4,5,6,7,8,9,10?
10. Can you spot the mistake in the following excerpt about a Binary SEARCH tree?
11. Searching in a BST always starts at the ____ We compare a data stored at the _____ with the key we are searching for
12. If a '5' is added to this BST, where is it likely to go?
13. In the following example, if we wanted to delete the '8', follow the method mentioned below and predict what the new 'root' node will be.
14. If the node to be deleted has only one child the procedure of deletion is identical to _____________________- just bypass the node being deleted
15. Another way of stating the rule that defines a Binary Search Tree is as follows: Fill in the blanks
16. In a BST that holds words, as might be in an unsorted dictionary, the order is always random.
17. If the letter 'F' was added to this BST, it would be placed immediately to the left of the letter 'E'
18. In the following Python (class based) representation of a Binary tree, what is the output?
class Node:
def __init__(self, data):
self.left = None
self.right = None
self.data = data
def insert(self, data):
# Compare the new value with the parent node
if self.data:
if data < self.data:
if self.left is None:
self.left = Node(data)
else:
self.left.insert(data)
elif data > self.data:
if self.right is None:
self.right = Node(data)
else:
self.right.insert(data)
else:
self.data = data
# Print the tree
def PrintTree(self):
if self.left:
self.left.PrintTree()
print( self.data),
if self.right:
self.right.PrintTree()
# Use the insert method to add nodes
root = Node(11)
root.insert(5)
root.insert(15)
root.insert(2)
root.PrintTree()
11,5,15,2
2,5,11,15
11
15,11,5,2
19. A very common interview question is: Given a binary tree, check whether or not it is a binary search tree. Explain the basis of this coded solution.
20. What is the worst case time complexity for search, insert and delete operations in a general Binary Search Tree?