Question

Question 4 1 pts Here is an array which has just been partitioned by the first step of quicksort: 3, 0, 2, 1, 7,. 15. 11, 20, 13 Which of these elements was the pivot? 0 7 0 1 o 20 O 15 Question 5 1 pts Running merge sort on an array of size n which is already sorted is O(n2) O O(n log n O Ollog n

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution 4:

7

Explanation:

There are generally four ways of picking the pivot element in the quicksort sorting algorithm

  1. Always pick first element as pivot.
  2. Always pick last element as pivot
  3. Pick median as pivot
  4. Pick a random element as pivot.

if we choose first element then pivot would be 3 but 3 is not in options

if we choose last element then pivot would be 13 but 13 is not in options

if we choose median as pivot then 7 would be our choice and it satisfy our options

So 7 would be right answer.

Solution 5:

O(nlogn)

Because merge sort always divides the array in two parts and take linear time to merge them, so accordingly in all 3 cases (Best, Worst and Average) the time complexity will be O(nlogn).

Add a comment
Know the answer?
Add Answer to:
Question 4 1 pts Here is an array which has just been partitioned by the first...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Quicksort) Here is an array which has just been partitioned by the first step of quicksort:...

    (Quicksort) Here is an array which has just been partitioned by the first step of quicksort: 3, 0, 2, 4, 5, 8, 7, 6, 9. Which of these elements could have been the pivot? (List all possibilities and explain your answers.)

  • Selection Sort is a common algorithm to sort the elements of an array. First, it scans...

    Selection Sort is a common algorithm to sort the elements of an array. First, it scans the elements of the array to find the smallest value and places it at index 0, thus creating a sorted “subarray” of size 1 that contains the smallest value. Then it scans the remaining unsorted values for the new smallest value and places it at index 1, creating a sorted subarray of size 2 that contains the 2 smallest values. It continues in this...

  • Question 13 pts (TCO 4) Which of the following functions grows at a slower rate than...

    Question 13 pts (TCO 4) Which of the following functions grows at a slower rate than the rest? n2 n log n n3 Flag this Question Question 23 pts (TCO 4) Algorithms can be described using pseudo-code. assignment and arithmetic operations. loops and decision statements. All of the above Flag this Question Question 33 pts (TCO 4) The running time of an algorithm is the time, in milliseconds, it takes to complete its execution. the running time of its implementation....

  • 1.3 ​Which of the following is true about sorting functions?A.The most optimal partitioning policy for quicksort...

    1.3 ​Which of the following is true about sorting functions?A.The most optimal partitioning policy for quicksort on an array we know nothing about wouldbe selecting a random element in the array.B.The fastest possible comparison sort has a worst case no better than O(​n​ log ​n​).C.Heapsort is usually best when you need a stable sort.D.Sorting an already sorted array of size ​n​ with quicksort takes O(​n​ log ​n​) time.E.When sorting elements that are expensive to copy, it is generally best to...

  • Assume that you are sorting an array of 8 elements with quick sort. You just finished...

    Assume that you are sorting an array of 8 elements with quick sort. You just finished the first pass and the array looks like below. Which statement is true for the pivot value? 4 8 12 16 18 20 22 24 QUICKSORT ALGORITHM Quicksort selects a specific value called a pivot and rearranges the array into two parts (called partioning). If the array is randomly ordered, it does not matter which element is the pivot. For simplicity, the first element...

  • c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each...

    c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each size Im trying to do time analysis for Quick sort but i keep getting time = 0 also i want edit the program to test different random sizes of the array and give me the time in a...

  • 1. Which is the best sorting algorithm for larger arrays if all the items can not...

    1. Which is the best sorting algorithm for larger arrays if all the items can not fit in main memory? selection sort insertion sort quicksort Merge sort 2. Which sorting algorithm sorts items without comparing them? quick sort radix sort merge sort Insertion sort 3 What is the average running time for quicksort? O(n2) O(logn) O(nlogn) O(n) O(n2logn) 4. Examine the steps of the following algorithm and write the name of the algorithm described in the blank provided: Recursively divide...

  • Java 1. (5) Assume selection sort is applied to the following array. Show the state of...

    Java 1. (5) Assume selection sort is applied to the following array. Show the state of the array after the first pass of the outer loop. 50 35 15 100 90 20 10 25 2. (5) Assume bubble sort is applied to the following array. Show the state of the array after the first pass of the outer loop 50 35 15 100 90 20 10 25 3. (5) Assume quicksort is applied to the following array. Show the state...

  • And the related algorithms: (20 points) Consider the following strategy for choosing a pivot element for...

    And the related algorithms: (20 points) Consider the following strategy for choosing a pivot element for the Partition subroutine of QuickSort, applied to an array A. .Let n be the number of elements of the array A. If n 24, perform an Insertion Sort of A and return. Otherwise: Choose 2n/2)| elements at random from n; let S be the new list with the chosen elements. Sort the list S using Insertion Sort and use the median m of S...

  • Java Question: Code the Merge Sort in such a way that it outputs the number of...

    Java Question: Code the Merge Sort in such a way that it outputs the number of comparisons and the number of swaps performed when sorting a random set of items. Then use it to sort 1000, 5000, 10,000, and 100,000 integers. Tabulate the results and compare it to the number of comparisons and swaps calculated using the formulas given in Table 8.6. Table 8.6 Performance of the Quicksort Algorithm Speed Memory Overhead Range Bytes lgorithm Range Effort Comments Binary Tree...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT