Question: implement these methods of heap and heap sort using c++ Operations performed upon the heap Since the heap is implemented as an array-based complete binary

 implement these methods of heap and heap sort using c++ Operations

implement these methods of heap and heap sort using c++

Operations performed upon the heap Since the heap is implemented as an array-based complete binary tree, traversing the tree can be done by simply calculating the index of the next node (or element) to traverse to (or move). How the tree is indexed has been discussed in lecture and is also provided in your text book and the tree lecture slides. Most of the heap operations function were discussed class (and slides) so the below paragraphs will provide a brief overview; it is assumed that you were present and paid attention in class. Adds/Inserts an item to the heap. An item added to the heap is positioned as the last element of the array at location heapsize + 1, where heapsize is the number of elements in the array. It then performs the bubble-up operation on that new item. During bubble-up, the newly added item is checked to see if it, at its current position, meets the heap order property when compared to its parent. If it does not, the bubble-up operation moves the new item up the tree until it is in a position that meets the heap order property. Bubble-up can be done iterative or recursively. Removes/Deletes an item from the heap. Deletions from the heap removes the root from the tree where the root is the first element in the array; the element is either element zero or one depending on how the array is indexed. After removing the root, the last element in the heap is moved (i.e., a simple assignment operation) to the array location of the former root and then the bubble-down operation is performed on the "new root". The bubble-down operation checks if the "new root" meets the heap order property by comparing it with the value of its children. If it does not, bubble-down will move the "new root" down the tree until it is in a position that meets the heap order property. Otherwise, if the "new root" meets the heap-order property, bubble-down isn't performed. Builds a heap from a populated array. Build_heap is an iterative process that starts at the center of the tree (the node at index [heapsize/2], assuming root is at 1) and iterates up to the root node. At each iteration (i.e., node), it executes the bubble down process starting at the array element of its current position. Your assignment is to write a dynamic array-based Heap class. Your Heap class will support both a min-heap structure and a max-heap structure, specified by passing a Boolean argument to the constructor at the creation of a Heap object. Since this is an array-based heap, the "node data" is the priority. You are to implement three operations described above and all other methods specified in the below UML

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!