Heaps Flashcards
What are the properties of a heap ADT? (2)
- key(v) <= key(parent(v))
2. Complete binary tree
What is the big Oh for a heap for the following:
- Space?
- Height?
- Insertion?
- RemoveMin?
- O(n)
- O(logn)
- O(logn)
- O(logn)
What different ways are there to implement a heap? Give a brief description of operations for each.
- Arraylist-based implementation. The left child is placed at 2i and the right child is placed at 2i+1
What is heap-sort? Give its runtime complexity and an explanation of why it is that value?
O(nlogn)
explanation? Nami angazi
What are the 3 steps of removing a node in a heap?
- swap the root and the last node
- Remove the root at the last node position
- Perform downheap
Bottom-up heap construction run-time algorithm? Why is it better than just inserting it into a heap?
Runtime algo is O(n), yet the inserting n times into a heap would yield O(nlogn). So BU construction is faster
What is the point of adaptable PQs?
When we have a priority queue but we want to make edits to the keys or values of the entries. APQ are an extension of PQs
State and explain the methods that are found in a APQ but not a PQ
remove(k) : Will remove an entry with the key k and return the value
replaceKey(e,k)
replaceValue(e,v)
What is the point of location-aware entries in an APQ?
So that traversals/searching are not necessary since the position will make future updated easier
What does a location-aware entry store?
- key
- position
- value
In what 2 ways can a APQ be implemented?
Arraylist and Heap
State the difference between the runtimes of arraylist vs heap APQ implementation
analysis table