Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 The C function popMinHeap() given below is supposed to delete the smallest integer from a inin heap which is stored in an integer array
2 The C function popMinHeap() given below is supposed to delete the smallest integer from a inin heap which is stored in an integer array heap[]. After executing popMinHeap(), the heap remains as a min heap structure. Variable n indicates the number of keys contained in array heap[]. Unfortunately, popMinHeap() has some bugs. Please correct all the bugs in the program. DO NOT rewrite the entire program, just show your modification with the line number. (10 points) 1 int pop MinHeap(int *n, int* heap) { int parent, child, min, tmp; 3 min = heap[1]; tmp = heap[n--]; 4 parent = 1; child = 2; 5 while (child heap(child + 1])) 7 child++; 8 if (tmp > heap[child]) break; 9 heap[parent] = heap (child); parent = child; 10 child = parent*2; } 11 heap[parent] = tmp: 12 return min; 13]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started