Self-Review Questions
- What is the worst-case runtime complexity of finding the smallest item in a min-heap?
O(1)
- What is the worst-case runtime complexity of finding the largest item in a min-heap?
O(n)
- What is the worst-case runtime complexity of deleteMin in a min-heap?
O(log n)
- What is the worst-case runtime complexity of building a heap by insertion?
O(n log n)
- Is a heap full or complete binary tree?
complete
- What is the worst-time runtime complexity of sorting an array of N elements using heapsort?
O(n log n)
- Given a sequence of numbers:
1, 2, 3, 4, 5
- Draw a binary min-heap (in a tree form) by inserting the above numbers reading them from left to right
- Show a tree that can be the result after the call to deleteMin() on the above heap
- Given a sequence of numbers:
1, 2, 3, 4, 5
- Draw a binary max-heap (in a tree form) by inserting the above numbers reading them from left to right
- Show a tree that can be the result after the call to deleteMax() on the above heap