retagged by
4,202 views
0 votes
0 votes
Suppose we want to sort an array in ascending order and we implement quicksort so that we always choose the last element in the array as the pivot element. Assume that the input is a permutation of {1, 2, …, n}. Which of the following would definitely be a worst case permutation of this input for this implementation of quicksort?

{1, 2,…, n} with all even numbers in random order followed by all odd numbers in random order.

{1, 2, . . . , n} in ascending order.

{1,2,...,n} in some random order.

{1, 2, . . . , n} with all odd numbers in ascending order followed by all even numbers in random order.
retagged by

1 Answer

Best answer
2 votes
2 votes

{1, 2, . . . , n} in ascending order beacuse QS has wrost case for elements already sorted (ascending/descending)!

selected by

Related questions

0 votes
0 votes
0 answers
2
Dulqar asked Jan 24, 2017
4,976 views
if T(n) = n2 √ n thenT(n) = O(n2)T(n) = O(n2 log n)T(n) = O(n3)None of the aboveIm getting option 2 is it correct ?
0 votes
0 votes
2 answers
4
Dulqar asked Feb 3, 2017
755 views
Q3: What kind of ciphers Electronic Codebook (ECB) mode and Cipher Block Chaining (CBC) mode are(A) Block cipher(B) Stream cipher(C) Field cipher(D) both (A) and (B)