1 - We are performing the following operations on the ADTs below. Show the value
ID: 675380 • Letter: 1
Question
1- We are performing the following operations on the ADTs below. Show the value returned by the
peek and remove operations.
Add 20, 7, 5, 8. Remove (a). Add 10, 14. Peek (a). Add 9. Remove (b). Add 3, 11. Peek (b).
a) Min Priority Queue
Remove (a)= ________ Peek (a) = _________ Remove (b) = ________ Peek (b) = _________
b) Max Priority Queue
Remove (a)= ________ Peek (a) = _________ Remove (b) = ________ Peek (b) = _________
2 - Draw the max heap (in tree form) that results from the following values added to the heap in the
given order. Show the steps.
1 3 5 2 7 4 8 6 9
3 - Starting from the heap represented by the given array, show the heap that results after performing 3
removes. Give both the tree and array representations after each remove.
1 3 2 5 9 7 4 6 8
Explanation / Answer
1- We are performing the following operations on the ADTs below. Show the value returned by the
peek and remove operations.
Add 20, 7, 5, 8. Remove (a). Add 10, 14. Peek (a). Add 9. Remove (b). Add 3, 11. Peek (b).
a) Min Priority Queue
Add 20, 7, 5, 8
MinPQ: head |5|7|8|20|
Remove (a)= 5
MinPQ: head |7|8|20|
Add 10, 14:
MinPQ: head |7|8|10|14|20|
Peek (a) = 7
MinPQ: head |7|8|10|14|20|
Add 9:
MinPQ: head |7|8|9|10|14|20|
Remove (b) = 7
MinPQ: head |8|9|10|14|20|
Add 3, 11:
MinPQ: head |3|8|9|11|10|14|20|
Peek (b) = 3
MinPQ: head |3|8|9|11|10|14|20|
b) Max Priority Queue
Add 20, 7, 5, 8
MaxPQ: head |20|8|7|5|
Remove (a)= 20
MaxPQ: head |8|7|5|
Add 10, 14:
MaxPQ: head |14|10|8|7|5|
Peek (a) = 14
MaxPQ: head |14|10|8|7|5|
Add 9:
MaxPQ: head |14|10|9|8|7|5|
Remove (b) =14
MaxPQ: head |10|9|8|7|5|
Add 3, 11:
MaxPQ: head |11|10|9|8|7|5|3|
Peek (b) = 11
MaxPQ: head |11|10|9|8|7|5|3|
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.