Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C or C++) Please I need HELP with this program in C or C++ Filename #items lowest Num8.txt 23 Num 16.txt 24 Num32.txt 23 1

(C or C++) Please I need HELP with this program in C or C++

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

Filename #items lowest Num8.txt 23 Num 16.txt 24 Num32.txt 23 1 Num64.txt 2 1 Num 128.txt 27 1 Num256.txt 28 1 Num512.txt 29 1 Num 1024.txt 210 1 Num2048.txt 211 1 Num4096.txt 212 1 Num8192.txt 213 1 Num16284.txt 214 1 highest Description 8 no omissions, no duplicates 16 no omissions, no duplicates 32 no omissions, no duplicates 64 no omissions, no duplicates 128 omissions/duplicates possible 256 omissions/duplicates possible 512 omissions/duplicates possible 1024 omissions/duplicates possible 2048 omissions/duplicates possible 4096 omissions/duplicates possible 8192 omissions/duplicates possible 16384 omissions/duplicates possible Description: You will write C, C++ code that implements the textbook algorithms for the sorting routines mentioned above. As part of your code, you will include counters that iterate whenever a specific line of the algorithm is executed. Some lines in an algorithm may have a higher cost than other lines. For example, the function call in line 5 in the Merge Sort algorithm is executed only 7 times for an array with 8 elements, but the body of the Merge function which is being called has many lines, some of which are executed more than once. So the cost of line 5 in the Merge sort algorithm is higher than the other 4 lines. We can use the cost of the highest-cost line as an indicator of the cost of the algorithm as a whole. Insertion Sort: Here is the pseudocode for Insertion Sort, modified to include a counter: count - 0 Insertion_Sort (A) for j - 2 to length (A) do key - A[j] // Insert Alj] into the sorted sequence A[1.. j - 1] i- j - 1 while i >0 and Ali) > key do 5.5 Ali + 1] - Afi) i-i-1 Ai + 1] - key 1 2 3 4 5 count count + 1 6 7 8 Your code for Insertion Sort should have a line in it that is equivalent to line 5.5 in the Insertion_Sort pseudocode above. The global variable count will keep a running total of the number of times this line is executed. When you exit from the call to the Insertion Sort function, you should print out the values of n (the length of the array) and count as an indicator of the cost of the function. Merge Sort: Here is the pseudocode for Merge Sort, modified to include a counter: count - 0 Merge_Sort (A, P, I) 1 if p A[i] 4 then largest 5 else largest 6 if r s heap-size [A] and A[r] > A[largest] 7 then largest 8 if largest * i 9 then exchange A[i] Alargest] 9.5 count count + 1 Max Heapify (A, largest) 10 And here is the algorithm for the Build_Max_Heap function used by Heap Sort: Build_Max_Heap (A) 1 heap-size [A] - length [A] 2 for i- floor(length[A]/2) downto 1 do 3 Max_Heapify (A, i) Your program for Heap Sort should have a line of code in it that is equivalent to line 10 in the Max_Heapify pseudocode above. In your program, a global counter should keep track of the number of times this line is executed. Quick Sort: Here is the pseudocode for Quick Sort, modified to include a counter QuickSort (A) 1 Count - 0 2 QUICKSORT (A,1, length [A]) Here is the pseudocode for the QUICKSORT function used by Quick Sort: QUICKSORT (A, P,r) 1 if p 0 and Ali) > key do 5.5 Ali + 1] - Afi) i-i-1 Ai + 1] - key 1 2 3 4 5 count count + 1 6 7 8 Your code for Insertion Sort should have a line in it that is equivalent to line 5.5 in the Insertion_Sort pseudocode above. The global variable count will keep a running total of the number of times this line is executed. When you exit from the call to the Insertion Sort function, you should print out the values of n (the length of the array) and count as an indicator of the cost of the function. Merge Sort: Here is the pseudocode for Merge Sort, modified to include a counter: count - 0 Merge_Sort (A, P, I) 1 if p A[i] 4 then largest 5 else largest 6 if r s heap-size [A] and A[r] > A[largest] 7 then largest 8 if largest * i 9 then exchange A[i] Alargest] 9.5 count count + 1 Max Heapify (A, largest) 10 And here is the algorithm for the Build_Max_Heap function used by Heap Sort: Build_Max_Heap (A) 1 heap-size [A] - length [A] 2 for i- floor(length[A]/2) downto 1 do 3 Max_Heapify (A, i) Your program for Heap Sort should have a line of code in it that is equivalent to line 10 in the Max_Heapify pseudocode above. In your program, a global counter should keep track of the number of times this line is executed. Quick Sort: Here is the pseudocode for Quick Sort, modified to include a counter QuickSort (A) 1 Count - 0 2 QUICKSORT (A,1, length [A]) Here is the pseudocode for the QUICKSORT function used by Quick Sort: QUICKSORT (A, P,r) 1 if p

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions