Question: Java Programming - Algorithms I created code to run heapSort and recorded timet on 7 different input files. I'm a beginner coder and my program
Java Programming - Algorithms
I created code to run heapSort and recorded timet on 7 different input files. I'm a beginner coder and my program won't even run the files. Please correct my code. For clarity sake, the seven input file , each file contains random numbers. For example, 100_input.txt contains 100 elements, 1000_input.txt contains 1000 elements. I cannot attach the actual input txt files. Please provide properly formatted code. Thanks in advance. Professor wanted me to use this pseudocode to make our code:

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class heapSort { public void heapSort(int arr[]) { int n = arr.length; BuildMaxHeap(arr, n); // One by one extract an element from heap for (int i=n-2; i>=0; i--) { // Move current root to end int temp = arr[0]; arr[0] = arr[i]; arr[i] = temp; // call max heapify on the reduced heap MaxHeapify(arr, i, 0); } } void BuildMaxHeap(int arr[], int n){ // Build heap (rearrange array) for (int i = n / 2 - 1; i >= 0; i--) MaxHeapify(arr, n, i); } // To heapify a subtree rooted with node i which is // an index in arr[]. n is size of heap void MaxHeapify(int arr[], int n, int i) { int largest = i; // Initialize largest as root int l = 2*i + 1; // left = 2*i + 1 int r = 2*i + 2; // right = 2*i + 2 // If left child is larger than root if (l arr[largest]) largest = l; // If right child is larger than largest so far if (r arr[largest]) largest = r; // If largest is not root if (largest != i) { int swap = arr[i]; arr[i] = arr[largest]; arr[largest] = swap; // Recursively heapify the affected sub-tree MaxHeapify(arr, n, largest); } } public static void main(String args[]) throws FileNotFoundException { int arr[], temp[]; String Filename[] = new String[] { "input_100.txt", "input_1000.txt", "input_5000.txt", "input_10000.txt", "input_50000.txt", "input_100000.txt", "input_500000.txt" }; // Save filenames in a variable double times[] = new double[Filename.length]; int file1 = 0, file2 = 0, file3 = 0, file4 = 0, file5 = 0, file6 = 0, file7 = 0; Scanner number; for (int n = 0; n HEAPSORT(A) 1 BuILD-MAX-HEAP (A) 2 forA.length downto 2 exchange A1 with Ali] A.heap-size - A.heap-size -1 4 5MAX-HEAPIFY(A, 1) BUILD-MAX-HEAP(A) 1 A.heap-size - A.length 2 for LA.length/2] downto 1 3MAX-HEAPIFY (A, i) MAX-HEAPIFY (A, i) 1LEFT(i) 2 r -RIGHT(i) 3 ifl A[largest] largest - 1 largest = r 8 if largest ^ i 9exchange A[i] with A[largest 10MAX-HEAPIFY (A, largest)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
