Problem 4 Consider Following Pseudocode Sorting Algorithm 0 1 Swap A0 1 Else N 2 M Lan Bad Q43895666
![Problem 4. Consider the following pseudocode for a sorting algorithm, for 0 <a<1 and n > 1 badSort(A[0. . n - 1]) if (n = 2)](https://media.cheggcdn.com/media/1c8/1c8eba22-9cb6-4119-82df-99d094dac797/image.png)


Problem 4. Consider the following pseudocode for a sorting algorithm, for 0 <a<1 and n > 1 badSort(A[0. . n – 1]) if (n = 2) and (A[0] > A[1]) swap A0 and A[1] else if (n > 2) m = lan badSort(A0… m – 1) badSort( Anm…n-1 badSort(Ao… m – 1 Problem 4.a. (3 points) • Show that the divide and conquer approach of badSort fails to sort the input array if a < 1/2. Problem 4.b. (2 points) • Does badSort work correctly if a = 3/4? If not, why? Explain how you fix it. Problem 4.c. (2 points) . State a recurrence (in terms of n and a) for the number of comparisons performed by badSort. Problem 4.d. (2 points) • Let a = 2/3. and solve the recurrence to determine the asymptotie time complexity of badSort. Problem 5. Problem 5.a. (3 points) Problem 5. Problem 5.a. (3 points) Implementation: Implement badSort from Problem 4 to sort an array of integers. The value of a should be an input parameter to your program. Implement the algorithm in C/C++. Your program should be able to read inputs from a file called “data.txt”, where the first value of each line is the number of integers that need to be sorted, followed by the integers. The output will be written to a file called “bad.out”. Problem 5.b. (3 points) Modify code: Modify the code to collect running time data. Call the new timing program badSort Time. Instead of reading arrays from the file data.txt and sorting, you will now generate arrays of size n containing random integer values from 0 to 10,000 to sort. Use the system clock to record the running times of each algorithm for n = 5000, 10000 15000. 20,000….. for two values of a 273 and 3/4. You may need to modify the values of in if an algorithm runs too fast or too slow to collect the running time data. Provide a table with the timing data Problem 5.c. (2 points) Plot data and fit a curve Plot the running time data vou collected for eacli value of Show transcribed image text Problem 4. Consider the following pseudocode for a sorting algorithm, for 0 A[1]) swap A0 and A[1] else if (n > 2) m = lan badSort(A0… m – 1) badSort( Anm…n-1 badSort(Ao… m – 1
Problem 4.a. (3 points) • Show that the divide and conquer approach of badSort fails to sort the input array if a
Expert Answer
Answer to Problem 4. Consider the following pseudocode for a sorting algorithm, for 0 A[1]) swap A0 and A[1] else if (n > 2) m = l…
Related