Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions