In Java build a max-heap in two ways 1) use sequential insertion 2) use the opti
ID: 3600375 • Letter: I
Question
In Java build a max-heap in two ways
1) use sequential insertion
2) use the optimal method ( Repeatedly apply reheap operations on all nonleaf nodes)
The software must be able to allow users to test the software by the following 2 choices:
a. Test 1: Use 20 sets of 100 randomly generated integers to build 20 max-heaps. In this test, the software should inform the user the average swaps needed for building these max-heaps. b. Test 2: use 100 fixed values from 1, 2, 3, ..., and 100.
The software must print on screen and in the output.txt the following results:
a. Test 1: i. The average number of swaps needed to build the max-heaps, for the both methods mentioned in 1.
b. Test 2: for each method mentioned in 1,
i. The first 10 integers in your array;
ii. The number of swaps for both methods mentioned in 1.
iii. Then perform 10 removals on the heap and output the first 10 integers.
No duplicate numbers are allowed
Explanation / Answer
#include using namespace std; // A function to heapify the array. void MaxHeapify(int a[], int i, int n) { int j, temp; temp = a[i]; j = 2*i; while (j a[j]) break; // Switching value with the parent node if temp = 1; i--) MaxHeapify(a, i, n); } int main() { int n, i; coutn; n++; int arr[n]; for(i = 1; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.