CS323 - AVL Tree homework

1. Insert in AVL tree

• Consider the following AVL tree:

• Questions:

 Give the binary search tree after the insert operation put("www") before rebalancing the AVL tree In your answer, lable the nodes x, y and z that will be used in the tri-node restructure operation. The node x is the first unbalance node, node y is a child node of x and node z is a child node of y. Show the AVL tree after the rebalancing operation:

2. Insert in AVL tree

• Consider the same AVL tree:

• Questions:

 Give the binary search tree after the insert operation put("abm") before rebalancing the AVL tree Mark in your answer the nodes x, y and z used in the rebalance operation. The node x is the first unbalance node, node y is a child node of x and node z is a child node of y. Show the AVL tree after the rebalancing operation

3. Delete in AVL tree

• Consider the same AVL tree:

• Questions:

 Give the binary search tree after the insert operation remove("cap") before rebalancing the AVL tree Mark in your answer the nodes x, y and z used in each of the rebalance operation(s). The node x is the first unbalance node, node y is a child node of x and node z is a child node of y. Show the AVL tree after each rebalancing operation

4. Delete in AVL tree

• Consider the same AVL tree:

• Questions:

 Give the binary search tree after the insert operation remove("sac") before rebalancing the AVL tree Mark in your answer the nodes x, y and z used in each of the rebalance operation(s). The node x is the first unbalance node, node y is a child node of x and node z is a child node of y. Show the AVL tree after each rebalancing operation

5. Developing an algorithm to find the successor node in a BST

• I will use 4 examples to help you figure out what to do to find the successor of a node in a BST.

• Find the path from the node klm to its successor (notice that klm has a non-empty right subtree):

• Find the path from the node sad to its successor (notice that klm has a non-empty right subtree):

• Find the path from the node cap to its successor (notice that cap does not has a right subtree):

• Find the path from the node sac to its successor (notice that sac does not has a right subtree):

Can you figure out what to do to find the successor node for a node p ???

You will now write an algorithm to do this.

• Download the program files given below and write the succ(BSTEntry p) method in Java that returns the successor node of p. The succ(BSTEntry p) will return null if p does not have a successor.

Turn question 5 in using this command:

 /home/cs323000/turnin BST.java pj3

Turn in

• Turn in Questions 1 to 4 in class (paper assignment)

• Turn in Question 5 using the above turnin command (programming assignment)