### CS171, Homework 9

• Attention !

• This is a paper homework and must be turned in in class

• Binary Search Tree (50 pts)

• Each question in this set will use the following Binary Search Tree as the starting tree:

• Questions: (5 pts each)

 Show the BST after executing the operation put(75) Show the BST after executing the operation remove(15) Show the BST after executing the operation remove(90) Show the BST after executing the operation remove(30) Show the BST after executing the operation remove(50) Show the BST after executing the statement root.right = null Show the BST after executing the statement root.right.left = null Show the BST after executing the statement root.right.right = null Show the BST after executing the statement root.left.right = null Show the BST after executing the statement root.left.left = null

(You have to draw the BST for each answer separately !)

• Heap

• Each question in this set will use the following Complete Binary Tree as the starting heap:

• Questions: (5 pts each)

 Show the Heap after executing the operation put(60) Show the Heap after executing the operation put(11) Show the Heap after executing the operation remove(12) Show the Heap after executing the operation remove(40) Show the Heap after executing the operation remove(10)

(You have to draw the Heap for each answer separately !)

• Updating a value in a node of a Heap (25 pts)

• Suppose we want to implement an update() method for the heap:

 The update() method will update the value in a specific node We will need to fix the heap after the update

• Example 1:

• Initial Heap:

• Suppose we perform the following update:

• We fix the heap as follows:

• Example 2:

• Initial Heap:

• Suppose we perform the following update:

• We fix the heap as follows:

• Write the update(k, x) that updates the heap element a[k] with the value x (and then fixes the heap !)

 ``` public void update( int k, double x ) { // Write the method on the sheet paper that you use // for the homework answers } ```