CPSC 327 | Data Structures and Algorithms | Spring 2024 |
There is not a redo opportunity for exam 2, however, there will be an optional section on the final exam covering similar material. A better grade on that section will replace the exam 2 grade.
While it is valid to swap with either the predecessor or the successor when removing an element without a leaf child, when the problem says to swap with the successor, you should swap with the successor...
When dealing with underflows in a 2-4 tree, prefer transfer to merge — transfer from an immediate sibling (via the parent) if possible, and only merge if there isn't a suitable sibling. Each underflow is considered separately, so even if a previous underflow for a single remove operation was resolved with a merge, it's still transfer first if possible when dealing with the next underflow.
Be careful to think through --- and include in your answer --- enough detail, without going overboard and including too much. It's not necessary to explain well-known standard operations such as how to insert or remove in a binary search tree, but it is important to mention things which affect the running time or where there is a choice with different running times or which deviate from the standard. For example, for removeMin in an unsorted array, what happens once the min element is found? There are at least two options (shifting, swapping with the last element) with different running times, so this is an important part of the answer. Finding the predecessor in a balanced search tree is another case --- that's not find, insert, remove (the standard operations) and so needs some explanation about how it can be carried out.
If you introduce something, like a min pointer or counts, to help with the implementation of one operation, don't forget to address how it is updated — a min pointer is handy for finding the minimum, but what happens when that minimum is removed? How are subtree sizes updated when restructuring occurs?
A hashtable with $n$ elements does not have O($n$) traversal --- even the empty array slots have to be visited, so traversal is O($N$).
Again, be sure to include sufficient details and especially don't forget to fully address how stored information or additional data structures are updated on insert and remove operations.
The problem stipulated O($\log n$) for all operations, though also that you should beat that where possible. In particular, how can both get operations be done in $O(1)$ time?