In: Computer Science
Design document for a MinHeap
Create a design document and run a manual paper and pencil approach to the implementation, insert and deletion of a MinHeap.
Use the input values:
50, 30, 45, 15, 65, 25, 10, 25, 15, 5
Part-1
1. Show insert of each item to the Heap implemented as array and show all the state of the array on the process of each insertion.
2. Show the first index and the last index of the heap in your array.
3. Show the formed array that is your Heap.
4. Draw a binary tree representation of your Heap from the array.
Part-2
1. Delete element, one at a time, from the Heap formed above by swapping the root with the last element in the array.
2. Show deletion of each item from the Heap from the array and show all the state of the array on the process of each deletion.
3. Show clearly the first index and the last index of your Heap after each deletion.
4. Show the final array, verify it is sorted.
A Heap is a special Tree-based data structure in which the tree is a complete binary tree. Generally, Heaps can be of two types:
Process of Insertion: Elements can be inserted to the heap following a similar approach as discussed above for deletion. The idea is to:
Heapify:
Process of Deletion:
Since deleting an element at any intermediary position in the heap
can be costly, so we can simply replace the element to be deleted
by the last element and delete the last element of the Heap.
Heapify: