Question

A max-heap with 10 elements is given in the following array format. The following three sub-questions...

A max-heap with 10 elements is given in the following array format. The following three sub-questions all refer to this max heap.

i 1 2 3 4 5 6 7 8 9 10
A[i] 99 90 80 70 60 50 40 30 20 10

Show the result after applying heap-increase-key(A, 9, 95) to the max-heap at the top of this page:

i 1 2 3 4 5 6 7 8 9 10
A[i]

Show the result after applying heap-extract-max(A) to the max-heap at the top of this page:

i 1 2 3 4 5 6 7 8 9 10
A[i]

Show the result after applying max-heap-insert(A, 95) to the max-heap at the top of this page:

i 1 2 3 4 5 6 7 8 9 10
A[i]

The answer needs to be filled out in the tables please.


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer -1

Answer - 2-

Answer - 3

for references please go through the code below

please wait sp,e modification are required

void MinHeap: :decreasekey(int i, int new_val) harr[1] new-val; while (i !- 0 &&harr[parent(i)] > harr[i]) swap (&harr[i], 1 = parent (i); &harr[parent(i)]);

void MinHeap::insertKey(int k) if (heap_sizecapacity) cout << "noverflow: Could not insertkey In"; return / First insert the new key at the end heap_size++; int i heapsize - 1; harr[i]k; - // Fix the min heap property if it is violated while (i!- 0 && harr[parent(i)] harr[i]) swap(&harr[i], &harr[parent (i)]); i - parent (i);

int MinHeap: :extractMin() (heap-size <= 0) return INT_MAX; (heap-size-1) if if heap_size--; return harr[0]; // Store the minimum value, and int root = harr[0]; harr[0] = harr[heap-size-1]; heap_size--; MinHeapify(0); remove it from heap return root;

Add a comment
Know the answer?
Add Answer to:
A max-heap with 10 elements is given in the following array format. The following three sub-questions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This question is about the min-heap. A min-heap with 10 elements is given in the following...

    This question is about the min-heap. A min-heap with 10 elements is given in the following array format. The following three sub-questions all refer to this min-heap i 1 2 3 4 5 6 7 8 9 10 A[i] 11 22 33 44 55 66 77 88 99 100 Show the result after applying heap-decrease-key(A, 6, 12) to the min-heap at the top of this page: i 1 2 3 4 5 6 7 8 9 10 A[i] Show the...

  • Consider the following max-heap: i 0 1 2 3 4 5 6 7 8 pq[i] -...

    Consider the following max-heap: i 0 1 2 3 4 5 6 7 8 pq[i] - 30 18 28 17 6 20 2 9 Show the resulting heap as array after performing delmax().

  • Please ignore red marks. Thanks 6. (8 pts) Illustrate the algorithmic operations on the maximum binary...

    Please ignore red marks. Thanks 6. (8 pts) Illustrate the algorithmic operations on the maximum binary heap data sti 'perations on the maximum binary heap data structure as directed. BUILD-MAX-HEAP(A) MAX-HEAPIFY (A. i) 1 A heap-size = A.length 11 = LEFT() 2 for i = A.length/2) downto 1 2 r = RIGHT() 3 MAX-HEAPIFY (A,i) 3 if / S 4.heap-size and All > A[i] HEAP-EXTRACT-MAX (A) 4 largest = 1 5 else largest = 1 1 if A.heap-size <1 6...

  • Question 3. a. Draw the binary min heap represented by the following array: (5 points) 1...

    Question 3. a. Draw the binary min heap represented by the following array: (5 points) 1 2 4 6 7 Value 4 9 12 29 17 14 16 b. Show the result of calling deleteMin twice on the heap you drew in part (a). Show the heap after each deleteMin, and circle the final heap. (5 points) c. Starting with the heap you ended up with in part (b), insert values 11 & 2 in that order. Draw the heap...

  • Consider the min-priority queue implemented by a binary heap. (The max-priority queue is treated in §6.5...

    Consider the min-priority queue implemented by a binary heap. (The max-priority queue is treated in §6.5 Priority queues in the textbook.) Show the binary tree implemented by the array A = 〈5, 8, 9, 11, 10, 12, 10, 12, 15, 11, 14, 13, 16, 15〉. Show the binary tree resulting from Heap-Insert(A, 6) where A is the array in (a). Show the binary tree resulting from Extract-Min(A) where A is the array in (a). Show the binary tree resulting from...

  • Using C++, data structures, C++ STL, inputs and expected outputs are shown below. Max Heap Heap...

    Using C++, data structures, C++ STL, inputs and expected outputs are shown below. Max Heap Heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either > (in a max heap) or s (in a min heap) the key of C. The node at the "top" of the heap (with no parents) is called the root node. In binary-tree based heap, it...

  • PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores...

    PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores integers and and implements a minimum priority queue. (Your program can be "hard coded" for integers - it does not need to use templates, generics, or polymorphism.) Your data structure must always store its internal data as a heap. Your toString function should return a string with the heap values as a comma separated list, also including the size of the heap as well....

  • Write a program in Java to implement the max-priority queue using max-heap data structure. Implement the...

    Write a program in Java to implement the max-priority queue using max-heap data structure. Implement the max-heap data structure using an integer array of 10 cells. (Do not use Java in-built PriorityQueue class.) [In a max-heap, the root node and the intermediate node vales are always greater than their children.] First, take 10 integer values from the user and insert them in the max-priority queue. Then print the elements of the queue. After that, delete two elements from the queue...

  • NOTE:  Completing the Third Chart is the most important. This is one question with three parts. (4 pts) Is the following array-based tree a min-heap or a max-heap or not a heap at all? 85 91 S8 95 1...

    NOTE:  Completing the Third Chart is the most important. This is one question with three parts. (4 pts) Is the following array-based tree a min-heap or a max-heap or not a heap at all? 85 91 S8 95 100 92 a. Min-heap b. Max-heap c. Not a heap 5 pts) Turn the following array-based binary tree into a max-heap. Show your work step by step. (You will not need all the columns) 34 7 12 47 19 5 pts) Show...

  • Write a Java program, In this project, you are going to build a max-heap using array...

    Write a Java program, In this project, you are going to build a max-heap using array representation. In particular, your program should: • Implement two methods of building a max-heap. o Using sequential insertions (its time complexity: ?(?????), by successively applying the regular add method). o Using the optimal method (its time complexity: ?(?), the “smart” way we learned in class). For both methods, your implementations need to keep track of how many swaps (swapping parent and child) are required...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT