Answered step by step
Verified Expert Solution
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,
- 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.
- 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.
- 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.
- 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.
- What is the running time of partition?
- What is the running time of quick sort?
- How many times the partition algorithm will be executed in a quick sort? Assume the array size is n. Justify your answer.
- How many comparisons are needed to sort a list of 2048 elements?
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started