Question: Problem Four (10 points, 5 points each)Write the following algorithms. The algorithms are all named isSorted. We assume an array object know its size, The

Problem Four (10 points, 5 points each)Write the following algorithms. The algorithms are all named isSorted. We assume an array object know its size,

  1. The first algorithm returns true if the array is sorted either in ascend order or in descend order; returns false otherwise. The algorithm takes an int array as argument.
  2. The second algorithm takes an int array and a Boolean value as arguments. If the Boolean value is true, then the algorithm returns true if the array is sorted in ascend order; If the Boolean value is false, then the algorithm returns true if the array is sorted in descend order; The algorithm returns false otherwise

Problem Five (16 points, 8 points each) Do NOT write code, just algorithm.

  1. Modify the insertion sort algorithm with an extra argument, named isAscend, of Boolean type. If isAscend is true, then the array will be sorted in ascend order; otherwise, the array will be sorted in descend order.
  2. Do the same problem to select sort algorithm.

Problem Six (Total 18 points, 3 points each for first 4 sub-problems, 6 points for number five) Answer the questions based on books Quick Sort algorithm.

  1. What is the running time of partition?
  2. What is the running time of quick sort?
  3. How many times the partition algorithm will be executed in a quick sort? Assume the array size is n. Justify your answer.
  4. How many comparisons are needed to sort a list of 2048 elements?
  5. Given array 8, 5, 3, 7, 1, 6, 4, 2. List array to show the array changes in memory. You may list out array after each partition call is terminated.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!