Explain how the quicksort algorithm is practically a O (n log n) algorithm rather than an O (n2) one. What would be the worst-case costly operation in the quicksort algorithm’s steps? What is the probability of this costly operation occurring?
Added by Susan P.
Step 1
The sub-arrays are then sorted recursively. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 55 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
(b) A sorting algorithm is in O(n^(2)) in the worst case. It takes 2 seconds to sort 10,000 records, i.e. n=10,000. (i) What is the predicted time for the algorithm to sort 20,000 records? [2 marks] (ii) Suppose that you are presented with a machine that is 100 times as fast. How many records will you be able to process on the new machine in 4 seconds? [2 marks]
Akash M.
Consider QuickSort on the array A[1:n] and assume that the pivot element x (used to split the array A[lo:hi] into two portions such that all elements in the left portion A[lo:m] are ≤x and all elements in the right portion A[m:hi] are ≥x) is the penultimate element of the array to be split (i. e., A[hi - 1]). Construct an infinite sequence of numbers for n and construct an assignment of the numbers 1...n to the n array elements that causes QuickSort, with the stated choice of pivot, to (a) execute optimally (that is A[lo:m] and A[m:hi] are always of equal size) (b) execute in the slowest possible way.
Question 1: (4+3+3=10 points) Let Sn be the set of all possible permutations of the array {1, 2, ..., n}. We can view Sn as the set of all possible inputs to a sorting algorithm. Note that |Sn| = n!. 1. Given any constant C ≥ 0, show that there is no comparison-based sorting algorithm that can sort using less than Cn comparisons for at least half of the arrays in Sn. (Show this is true for large enough n, and same for parts 2 and 3.) 2. What about a fraction of 1/n of the arrays in Sn? 3. What about a fraction of 1/2n of the arrays in Sn?
Monisha S.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD