GATE Overflow - Recent questions tagged quicksort
https://gateoverflow.in/tag/quicksort
Powered by Question2AnswerQUICK SORT- SELF DOUBT
https://gateoverflow.in/319659/quick-sort-self-doubt
<p>In quick sort for sorting of n Numbers, the 75th greatest Element is selected as pivot using $O(n^2)$ time complexity algorithm than what is the worst case time complexity of quick sort.</p>
<ol>
<li>O($n^2$)</li>
<li>O($n^3$)</li>
<li>O(nlogn)</li>
<li>O(n)</li>
</ol>Algorithmshttps://gateoverflow.in/319659/quick-sort-self-doubtMon, 02 Sep 2019 17:04:32 +0000Cormen Edition 3 Exercise 7.4 Question 6 (Page No. 185)
https://gateoverflow.in/315812/cormen-edition-3-exercise-7-4-question-6-page-no-185
<p>Consider modifying the <a href="https://gateoverflow.in/315753/cormen-edition-3-exercise-7-1-question-1-page-no-173" rel="nofollow">PARTITION</a> procedure by randomly picking three elements from the array $A$ and partitioning about their median (the middle value of the three elements). Approximate the probability of getting at worst a $\alpha$-to-$(1-\alpha)$ split, as a function of $\alpha$ in the range $0<\alpha<1$.</p>Algorithmshttps://gateoverflow.in/315812/cormen-edition-3-exercise-7-4-question-6-page-no-185Fri, 28 Jun 2019 02:46:28 +0000Cormen Edition 3 Exercise 7.4 Question 5 (Page No. 185)
https://gateoverflow.in/315811/cormen-edition-3-exercise-7-4-question-5-page-no-185
We can improve the running time of quicksort in practice by taking advantage of the fast running time of insertion sort when its input is “nearly” sorted. Upon calling quicksort on a subarray with fewer than $k$ elements, let it simply return without sorting the subarray. After the top-level call to quicksort returns, run insertion sort on the entire array to finish the sorting process. Argue that this sorting algorithm runs in $O(nk+n\ lg\ (n/k))$ expected time. How should we pick $k$, both in theory and in practice?Algorithmshttps://gateoverflow.in/315811/cormen-edition-3-exercise-7-4-question-5-page-no-185Fri, 28 Jun 2019 02:42:52 +0000Cormen Edition 3 Exercise 7.4 Question 4 (Page No. 184)
https://gateoverflow.in/315810/cormen-edition-3-exercise-7-4-question-4-page-no-184
<p>Show that <a rel="nofollow" href="https://gateoverflow.in/315806/cormen-edition-3-exercise-7-3-question-2-page-no-180">RANDOMIZED-QUICKSORT</a>’s expected running time is $\Omega(n\ lg\ n)$.</p>Algorithmshttps://gateoverflow.in/315810/cormen-edition-3-exercise-7-4-question-4-page-no-184Fri, 28 Jun 2019 02:39:04 +0000Cormen Edition 3 Exercise 7.4 Question 3 (Page No. 184)
https://gateoverflow.in/315809/cormen-edition-3-exercise-7-4-question-3-page-no-184
Show that the expression $q^2 +(n-q-1)^2$ achieves a maximum over $q=0,1,\dots ,n-1$ when $q=0$ or $q=n-1$.Algorithmshttps://gateoverflow.in/315809/cormen-edition-3-exercise-7-4-question-3-page-no-184Fri, 28 Jun 2019 02:37:02 +0000Cormen Edition 3 Exercise 7.4 Question 2 (Page No. 184)
https://gateoverflow.in/315808/cormen-edition-3-exercise-7-4-question-2-page-no-184
Show that quicksort’s best-case running time is $\Omega(n\ lg\ n)$.Algorithmshttps://gateoverflow.in/315808/cormen-edition-3-exercise-7-4-question-2-page-no-184Fri, 28 Jun 2019 02:34:09 +0000Cormen Edition 3 Exercise 7.3 Question 2 (Page No. 180)
https://gateoverflow.in/315806/cormen-edition-3-exercise-7-3-question-2-page-no-180
<pre>
RANDOMIZED-QUICKSORT(A, p, r)
1 if p < r
2 q = RANDOMIZED-PARTITION(A, p, r)
3 RANDOMIZED-QUICKSORT(A, p, q – 1)
4 RANDOMIZED-QUICKSORT(A, q + 1, r)
RANDOMIZED-PARTITION(A, p, r)
1 i = RANDOM(p, r)
2 exchange A[r] with A[i]
3 return <a href="https://gateoverflow.in/315753/cormen-edition-3-exercise-7-1-question-1-page-no-173" rel="nofollow">PARTITION(A, p, r)</a></pre>
<p> </p>
<p>When RANDOMIZED-QUICKSORT runs, how many calls are made to the random number generator RANDOM in the worst case? How about in the best case? Give your answer in terms of $\Theta$ notation.</p>Algorithmshttps://gateoverflow.in/315806/cormen-edition-3-exercise-7-3-question-2-page-no-180Fri, 28 Jun 2019 02:25:27 +0000Cormen Edition 3 Exercise 7.3 Question 1 (Page No. 180)
https://gateoverflow.in/315805/cormen-edition-3-exercise-7-3-question-1-page-no-180
Why do we analyze the expected running time of a randomized algorithm and not its worst-case running time?Algorithmshttps://gateoverflow.in/315805/cormen-edition-3-exercise-7-3-question-1-page-no-180Fri, 28 Jun 2019 02:16:21 +0000Cormen Edition 3 Exercise 7.2 Question 6 (Page No. 179)
https://gateoverflow.in/315774/cormen-edition-3-exercise-7-2-question-6-page-no-179
<p>Argue that for any constant $0<\alpha\leq 1/2$, the probability is approximately $1-2\alpha$ that on a random input array,<a rel="nofollow" href="https://gateoverflow.in/315753/cormen-edition-3-exercise-7-1-question-1-page-no-173"> PARTITION </a>produces a split more balanced than $1-\alpha$ to $\alpha$.</p>Algorithmshttps://gateoverflow.in/315774/cormen-edition-3-exercise-7-2-question-6-page-no-179Thu, 27 Jun 2019 09:22:38 +0000Cormen Edition 3 Exercise 7.2 Question 5 (Page No. 178)
https://gateoverflow.in/315773/cormen-edition-3-exercise-7-2-question-5-page-no-178
Suppose that the splits at every level of quicksort are in the proportion $1-\alpha$ to $\alpha$, where $0<\alpha\leq1/2$ is a constant. Show that the minimum depth of a leaf in the recursion tree is approximately $-lg\ n /lg\ \alpha$ and the maximum depth is approximately $-lg\ n / lg\ (1-\alpha)$.(Don’t worry about integer round-off.)Algorithmshttps://gateoverflow.in/315773/cormen-edition-3-exercise-7-2-question-5-page-no-178Thu, 27 Jun 2019 09:17:35 +0000Cormen Edition 3 Exercise 7.2 Question 4 (Page No. 178)
https://gateoverflow.in/315772/cormen-edition-3-exercise-7-2-question-4-page-no-178
Banks often record transactions on an account in order of the times of the transactions, but many people like to receive their bank statements with checks listed in order by check number. People usually write checks in order by check number, and merchants usually cash them with reasonable dispatch. The problem of converting time-of-transaction ordering to check-number ordering is, therefore, the problem of sorting almost-sorted input. Argue that the procedure INSERTION-SORT would tend to beat the procedure QUICKSORT on this problem.Algorithmshttps://gateoverflow.in/315772/cormen-edition-3-exercise-7-2-question-4-page-no-178Thu, 27 Jun 2019 09:10:47 +0000Cormen Edition 3 Exercise 7.2 Question 3 (Page No. 178)
https://gateoverflow.in/315769/cormen-edition-3-exercise-7-2-question-3-page-no-178
<p>Show that the running time of <a rel="nofollow" href="https://gateoverflow.in/315766/cormen-edition-3-exercise-7-1-question-4-page-no-174">QUICKSORT</a> is $\Theta(n^2)$ when the array $A$ contains distinct elements and is sorted in decreasing order.</p>Algorithmshttps://gateoverflow.in/315769/cormen-edition-3-exercise-7-2-question-3-page-no-178Thu, 27 Jun 2019 09:02:29 +0000Cormen Edition 3 Exercise 7.2 Question 2 (Page No. 178)
https://gateoverflow.in/315768/cormen-edition-3-exercise-7-2-question-2-page-no-178
<p>What is the running time of <a rel="nofollow" href="https://gateoverflow.in/315766/cormen-edition-3-exercise-7-1-question-4-page-no-174">QUICKSORT</a> when all elements of the array $A$ have the same value?</p>Algorithmshttps://gateoverflow.in/315768/cormen-edition-3-exercise-7-2-question-2-page-no-178Thu, 27 Jun 2019 08:59:48 +0000Cormen Edition 3 Exercise 7.1 Question 4 (Page No. 174)
https://gateoverflow.in/315766/cormen-edition-3-exercise-7-1-question-4-page-no-174
<pre>
QUICKSORT(A,p,r)
1 if p < r
2 q = <a rel="nofollow" href="https://gateoverflow.in/315753/cormen-edition-3-exercise-7-1-question-1-page-no-173">PARTITION(A,p,r)</a>
3 QUICKSORT(A, p , q-1)
4 QUICKSORT(A, q + 1, r)</pre>
<p>How would you modify QUICKSORT to sort into nonincreasing order?</p>Algorithmshttps://gateoverflow.in/315766/cormen-edition-3-exercise-7-1-question-4-page-no-174Thu, 27 Jun 2019 08:34:35 +0000Cormen Edition 3 Exercise 7.1 Question 3 (Page No. 174)
https://gateoverflow.in/315765/cormen-edition-3-exercise-7-1-question-3-page-no-174
<p>Give a brief argument that the running time of <a rel="nofollow" href="https://gateoverflow.in/315753/cormen-edition-3-exercise-7-1-question-1-page-no-173">PARTITION</a> on a subarray of size $n$ is $\Theta(n)$.</p>Algorithmshttps://gateoverflow.in/315765/cormen-edition-3-exercise-7-1-question-3-page-no-174Thu, 27 Jun 2019 08:28:33 +0000Cormen Edition 3 Exercise 7.1 Question 2 (Page No. 174)
https://gateoverflow.in/315756/cormen-edition-3-exercise-7-1-question-2-page-no-174
<p>What value of $q$ does <a rel="nofollow" href="https://gateoverflow.in/315753/cormen-edition-3-exercise-7-1-question-1-page-no-173">PARTITION</a> return when all elements in the array $A[p..r]$ have the same value? Modify PARTITION so that $q=\lfloor(p+r)/2 \rfloor$ when all elements in the array $A[p..r]$ have the same value.</p>Algorithmshttps://gateoverflow.in/315756/cormen-edition-3-exercise-7-1-question-2-page-no-174Thu, 27 Jun 2019 04:02:49 +0000Cormen Edition 3 Exercise 7.1 Question 1 (Page No. 173)
https://gateoverflow.in/315753/cormen-edition-3-exercise-7-1-question-1-page-no-173
<pre>
PARTITION(A,p,r)
1 x = A[r]
2 i = p – 1
3 for j = p to r – 1
4 if A[j] <= x
5 i = i + 1
6 exchange A[i] with A[j]
7 exchange A[i+1] with A[r]
8 return i + 1</pre>
<p> </p>
<p>illustrate the operation of PARTITION on the array $A=\langle 13,19,9,5,12,8,7,4,21,2,6,11\rangle$</p>Algorithmshttps://gateoverflow.in/315753/cormen-edition-3-exercise-7-1-question-1-page-no-173Thu, 27 Jun 2019 03:57:06 +0000GATE2019-20
https://gateoverflow.in/302828/gate2019-20
An array of $25$ distinct elements is to be sorted using quicksort. Assume that the pivot element is chosen uniformly at random. The probability that the pivot element gets placed in the worst possible location in the first round of partitioning (rounded off to $2$ decimal places) is ________Algorithmshttps://gateoverflow.in/302828/gate2019-20Thu, 07 Feb 2019 09:40:49 +0000MadeEasy Test Series: Algorithms - Sorting
https://gateoverflow.in/297910/madeeasy-test-series-algorithms-sorting
Consider a scenario of modified quick sort, where we have given an input sorted array A[1 .. . n], all elements of array are distinct and n >=3. Pivot is the median of set of 3 elements [First element, middle element, and last element]. What will be worst case time complexity of modified quick sort?<br />
<br />
a.O($n^{2}$)<br />
b.O(nlogn)<br />
c.O($n^{2}$logn)<br />
d.O(nloglogn)Algorithmshttps://gateoverflow.in/297910/madeeasy-test-series-algorithms-sortingMon, 21 Jan 2019 10:18:59 +0000Ace Test Series: Algorithms - Sorting
https://gateoverflow.in/294073/ace-test-series-algorithms-sorting
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=15137182767523691958"></p>Algorithmshttps://gateoverflow.in/294073/ace-test-series-algorithms-sortingSun, 13 Jan 2019 18:29:56 +0000MadeEasy Test Series: Algorithms - Sorting
https://gateoverflow.in/284970/madeeasy-test-series-algorithms-sorting
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=16373676665481911352"></p>
<p>Is there any standard way to sort in Quicksort or what all matters is PIVOT getting placed at its correct position thats it?
<br>
I mean if only pivot condition then 3!*3! for both left and right elements but if any standard then each of the left and right parts shall also be preserved in that order so 1?</p>
<p>like in Selection sort we have fixed way that after 1st pass the array will remain as it is and only those elements compared with the minimum will be getting swapped.</p>Algorithmshttps://gateoverflow.in/284970/madeeasy-test-series-algorithms-sortingWed, 26 Dec 2018 17:32:09 +0000Self Doubt- Quick Sort
https://gateoverflow.in/273757/self-doubt-quick-sort
<p>Que – Consider the recursive quicksort algorithm with “random pivoting”. That is, in each recursive call, a pivot is chosen uniformly at random from the sub-array being sorted. When this randomized algorithm is applied to an array of size n all whose elements are distinct, what is the probability that the smallest and the $2^{nd}$ largest elements in the array are compared during a run of the algorithm?</p>
<hr>
<p>I am getting – $\frac{2}{n}+(\frac{1}{n}*\frac{2}{n-1}) = \frac{2}{n-1} $</p>
<p>Please verify.</p>Algorithmshttps://gateoverflow.in/273757/self-doubt-quick-sortMon, 03 Dec 2018 06:22:30 +0000Adaptive sorting Algorithm.
https://gateoverflow.in/272998/adaptive-sorting-algorithm
Is Quick sort an adaptive sorting Algorithm? I think no. Because as per the definition given in the Wikipedia is that A adaptive sorting Algorithm is one who takes the advantage of preorderedness of the input. But in case of Quick sort it act as disadvantage.Algorithmshttps://gateoverflow.in/272998/adaptive-sorting-algorithmSat, 01 Dec 2018 10:06:25 +0000Self Doubt - Quick Sort
https://gateoverflow.in/266096/self-doubt-quick-sort
<p>Consider the following inputs:</p>
<p>1) 2 2 2 2 2 2 2</p>
<p>2) 1 2 3 4 5 6 7</p>
<p>3) 7 6 5 4 3 2 1</p>
<p>In all three cases, the worst-case time complexity of quicksort is O(n<sup>2</sup>)</p>
<p> </p>
<p><strong>My doubt is if I am taking the middle element as a pivot, then my recursive equation for the above three cases will become: T(n) = T(n/2) + O(n), right?</strong></p>
<p><strong>Can someone explain how we are saying worst-case time complexity for these three cases is O(n<sup>2</sup>) irrespective of the selection of the pivot element?</strong></p>
<p> </p>Algorithmshttps://gateoverflow.in/266096/self-doubt-quick-sortFri, 16 Nov 2018 14:35:04 +0000chache performance between hoare and loranto quicksort
https://gateoverflow.in/264514/chache-performance-between-hoare-and-loranto-quicksort
between hoare and loranto quicksort which give better cache performance ?<br />
<br />
we know that in hoare quicksort we move the pointer i,j in different direction but in loranto quicksort we move i,j in same direction<br />
<br />
so the cache performance of loranto should be better?Algorithmshttps://gateoverflow.in/264514/chache-performance-between-hoare-and-loranto-quicksortTue, 13 Nov 2018 05:54:13 +0000Randomized Quicksort
https://gateoverflow.in/245546/randomized-quicksort
True or False :<br />
<br />
In randomized quicksort , each key is involved in the same number of comparisons.Algorithmshttps://gateoverflow.in/245546/randomized-quicksortFri, 21 Sep 2018 17:36:05 +0000Code Quick Sort
https://gateoverflow.in/233764/code-quick-sort
<p>Why the code is not showing correct sorting ?(here pivot is smaller index element, i.e. arr[low])</p>
<pre class="prettyprint lang-c_cpp" data-pbcklang="c_cpp" data-pbcktabsize="4">
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void fillArray(int array[], int n)
{
time_t t;
time(&t);//get current time
srand(t);//gives current time as seed for random number generator
for(int i = 0; i < n; i++)
{
array[i] = rand()%(10*n);//Doing mod to avoid very large numbers
}
}
void printArray(int array[], int n)
{
for(int i = 0; i < n; i++)
{
printf("\n%d ", array[i]);
}
}
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
int partition (int arr[], int low, int high)
{
int j;
static int swap1=0;
static int swap2=0;
int pivot = arr[low]; // pivot
int i = (low); // Index of smaller element
for (j = low+1; j <= high; j++)
{
// If current element is smaller than or
// equal to pivot
if (arr[j] <= pivot)
{
i++; // increment index of smaller element
swap(&arr[i], &arr[j]);
swap1++;
}
}
swap(&arr[i], &arr[low]);
swap2++;
printf("Total number of swaps:%d",(swap1+swap2));
return (i + 1);
}
void quickSort(int arr[], int low, int high)
{
if (low < high)
{
/* pi is partitioning index, arr[p] is now
at right place */
int pi = partition(arr, low, high);
// Separately sort elements before
// partition and after partition
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
int main()
{
int * array, n=5;
int low=0;
//printf("Enter the no. of numbers: ");
//scanf("%d", &n);
array = malloc(n * sizeof(int));
fillArray(array, n);
quickSort(array,low,n);
printArray(array, n);
return 0;
}
</pre>
<p> </p>Programminghttps://gateoverflow.in/233764/code-quick-sortThu, 16 Aug 2018 06:54:16 +0000Made Easy algorithms
https://gateoverflow.in/231245/made-easy-algorithms
After applying few passes of quick sort on a given array, the following output was obtained:<br />
<br />
1,10,5,8,25,44,55,30,70<br />
<br />
Then how many pivot elements are there in the above output?Algorithmshttps://gateoverflow.in/231245/made-easy-algorithmsMon, 06 Aug 2018 08:45:12 +0000Quick Sort Time Complexity
https://gateoverflow.in/223231/quick-sort-time-complexity
<p><strong>Quick sort</strong><strong> gives O(</strong><strong>nlogn</strong><strong>) </strong><strong>worst case</strong><strong> performance if the pivot is selected as:</strong></p>
<p>a) First element of the array</p>
<p>b) Median of first, last and middle elements</p>
<p>c) Arithmetic mean of the elements</p>
<p>d) None of these</p>
<p> </p>
<p><strong>Now, the answer is given as Option (b). But, as far as I know complexity of quick sort depends on order of elements and not on pivot element. So, answer should be option (d) i.e None of these</strong></p>
<p><strong>Correct me if I am wrong</strong></p>Algorithmshttps://gateoverflow.in/223231/quick-sort-time-complexitySun, 01 Jul 2018 16:03:01 +0000cormen 3rd edition 7.2-6
https://gateoverflow.in/220864/cormen-3rd-edition-7-2-6
<p>Argue that for any constant 0<α≤1/2, the probability is approximately 1−2α that on a random input array, <code>PARTITION</code> produces a split more balanced than 1−α to α.</p>
<p>Please explain how the probability is calculated?</p>Algorithmshttps://gateoverflow.in/220864/cormen-3rd-edition-7-2-6Thu, 14 Jun 2018 06:59:11 +0000Quick Sort- Algorithm
https://gateoverflow.in/217676/quick-sort-algorithm
Let $0<α<.5$ be some constant (independent of the input array length $n$). What is the probability that, with a randomly chosen pivot element, the Partition subroutine produces a split in which the size of the smaller of the two subarrays is $≥α$ times the size of the original array?<br />
<br />
1. $1 - 2*\alpha$<br />
<br />
2. $\alpha$<br />
<br />
3. $1 - \alpha$<br />
<br />
4. $2 - 2*\alpha$Algorithmshttps://gateoverflow.in/217676/quick-sort-algorithmWed, 23 May 2018 15:18:59 +0000Doubt
https://gateoverflow.in/209914/doubt
<p>In Randomized Quick sort, Can we have partitioning algorithm that never gives worst case as $O(n^2)$<sup> </sup>for every input?</p>Algorithmshttps://gateoverflow.in/209914/doubtThu, 29 Mar 2018 07:56:02 +0000quick sort
https://gateoverflow.in/194760/quick-sort
<p>You have an array of n elements. Suppose you implement quick sort by always choosing the central element of the array as the pivot. Then the tightest lower bound for the <strong>best case </strong>performance is
<br>
<br>
a) O(n2)
<br>
<br>
b) O(nlogn)
<br>
<br>
c) Θ(nlogn)
<br>
<br>
d) O(n3)</p>Algorithmshttps://gateoverflow.in/194760/quick-sortSun, 14 Jan 2018 10:56:17 +0000TIFR2018-B-7
https://gateoverflow.in/179291/tifr2018-b-7
<p>Consider the recursive quicksort algorithm with "random pivoting". That is, in each recursive call, a pivot is chosen uniformly at random from the sub-array being sorted.When this randomized algorithm is applied to an array of size $n$ all whose elements are distinct, what is the probability that the smallest and the largest elements in the array are compared during a run of the algorithm ?</p>
<ol class="shrink-inline-options" style="list-style-type:upper-alpha">
<li>$\left(\dfrac{1}{n}\right)$</li>
<li>$\left(\dfrac{2}{n}\right)$</li>
<li>$\Theta \left(\dfrac{1}{n\log n}\right)$</li>
<li>${O} \left(\dfrac{1}{n^{2}}\right)$</li>
<li>$\Theta\left(\dfrac{1}{n \log^{2} n}\right)$</li>
</ol>Algorithmshttps://gateoverflow.in/179291/tifr2018-b-7Sun, 10 Dec 2017 01:38:43 +00003-way quicksort
https://gateoverflow.in/178416/3-way-quicksort
3-way partitioning is a modification of quicksort that partitioned the elements into groups smaller than,equal to and larger than pivot. Only the group of smaller and larger elements need to be sorted. If there are N items and K unique value the running time of modified quick sort is-<br />
<br />
(A) O(nlogk)<br />
<br />
(B) O(klogn)<br />
<br />
(C) O(nk)<br />
<br />
(D) O(k^2)Algorithmshttps://gateoverflow.in/178416/3-way-quicksortThu, 07 Dec 2017 21:12:42 +0000Quick Sort Number Of Comparison Query
https://gateoverflow.in/176453/quick-sort-number-of-comparison-query
<p>What is the number of <em>Comparison </em> to sort below arrays using quick sort using first element as pivot ?</p>
<p>Please show steps .</p>
<p>A1=4,1,5,3,2</p>
<p>A2=1,2,3,4,5</p>
Algorithmshttps://gateoverflow.in/176453/quick-sort-number-of-comparison-querySat, 02 Dec 2017 23:21:23 +0000Modified form of GATE1996_2.15
https://gateoverflow.in/161097/modified-form-of-gate1996_2-15
<p>Quick-sort is run on two inputs shown below to sort in ascending order taking first element as pivot</p>
<p>i) 1,2,3,…<em>n</em></p>
<p>ii)<em> n</em>,<em>n</em>−1,<em>n</em>−2,…,2,1</p>
<p>Let <em>S</em>1 and <em>S</em>2 be the number of swaps made for the inputs (i) and (ii) respectively. Then,</p>
<p><strong>i) How is S1 and S2 related ?</strong></p>
<p><strong>ii) How will the answer change if the pivot is changed to middle element ?</strong></p>Algorithmshttps://gateoverflow.in/161097/modified-form-of-gate1996_2-15Wed, 18 Oct 2017 08:29:02 +0000QUICKSORT
https://gateoverflow.in/155660/quicksort
Could anyone describe how the partitioning algorithm vary when the pivot is varied ?<br />
<br />
In Cormen , last element is taken as pivot . Suppose I took first element or middle element or 3 rd element as pivot then how the partitioning algorithm will change.Algorithmshttps://gateoverflow.in/155660/quicksortWed, 27 Sep 2017 09:15:13 +0000Quick Sort
https://gateoverflow.in/149631/quick-sort
"Quick sort has good cache performance" , Can anyone explain this statement.How is cache related to quick sort.I searched for this over the internet but could not find a good article.Algorithmshttps://gateoverflow.in/149631/quick-sortSun, 03 Sep 2017 12:54:08 +0000Quick sort
https://gateoverflow.in/143135/quick-sort
When array is already sorted in reverse order then what will be the recurrence relation for number of swaps on array of n elements using quick sort?Algorithmshttps://gateoverflow.in/143135/quick-sortThu, 10 Aug 2017 14:01:22 +0000With quick sort The results after first partioning of the given array
https://gateoverflow.in/125609/with-quick-sort-results-after-first-partioning-given-array
With quick sort The results after first partioning of the given array. <br />
<br />
A = (2,8,7,1,3,5,6,4,9).<br />
<br />
Analysis the time complexity of Quick sort in the best case.Algorithmshttps://gateoverflow.in/125609/with-quick-sort-results-after-first-partioning-given-arraySat, 15 Apr 2017 03:55:23 +0000A list of elements are given A - <3,1,4,1,5,9,2,6,5,3,5,8,9 >
https://gateoverflow.in/125608/a-list-of-elements-are-given-a-3-1-4-1-5-9-2-6-5-3-5-8-9
A list of elements are given A - <3,1,4,1,5,9,2,6,5,3,5,8,9 ><br />
<br />
Show Howw the "Pivot" and quick sort algorithm work.<br />
<br />
finally show the Best Case analysis for quick sort .Algorithmshttps://gateoverflow.in/125608/a-list-of-elements-are-given-a-3-1-4-1-5-9-2-6-5-3-5-8-9Sat, 15 Apr 2017 03:51:22 +0000GATE 2008 Quick Sort
https://gateoverflow.in/122868/gate-2008-quick-sort
Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let T(n) be the number of comparisons required to sort n elements. Then— <br />
A. T(n) <= 2T(n/5) + n <br />
<br />
B. T(n) <= T(n/5) + T(4n/5) + n<br />
<br />
C. T(n) <= 2T(4n/5) + n <br />
<br />
D. T(n) <= 2T(n/2) + n <br />
<br />
<br />
The Answer to this question is B. My doubt is that why can't the answer be C? My logic is that if there are (n/5) elements on one side and (4n/5) on the other, then T(n)= T(n/5) + T(4n/5) + n. Here, 4n/5 > n/5 so definitely, time taken will be less than 2T(4n/5) + n, if elements are more than (n/5)( since it is given 'AT LEAST').<br />
<br />
Where am I going wrong?Algorithmshttps://gateoverflow.in/122868/gate-2008-quick-sortWed, 29 Mar 2017 09:18:07 +0000Algorithm quicksort
https://gateoverflow.in/116776/algorithm-quicksort
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=6401764963669722405"></p>
<p><strong>Reply with solution @ Habibkhan,@Gabbar,@Arjun Sir</strong></p>Algorithmshttps://gateoverflow.in/116776/algorithm-quicksortTue, 07 Feb 2017 05:40:49 +0000quick sort
https://gateoverflow.in/108311/quick-sort
If we use quicksort algorithm to sort the elements: $16, 13, 14, 12, 21, 16, 23$ and $15$ in ascending order, what is the output after the first pass of quicksort? (Assume pivot element is beginning of an array)Algorithmshttps://gateoverflow.in/108311/quick-sortFri, 20 Jan 2017 12:05:06 +0000Quicksort
https://gateoverflow.in/83816/quicksort
Consider an array with following element<br />
<br />
12, 18, 17,11, 13, 15, 16 ,14<br />
<br />
The number of element will change their initial position after completion of partition algorithm by choosing 15 as a pivot are __<br />
<br />
Please solve step by step.Algorithmshttps://gateoverflow.in/83816/quicksortFri, 18 Nov 2016 17:25:58 +0000New Gradience Sorting
https://gateoverflow.in/82458/new-gradience-sorting
There are many variations of Quicksort. We may choose the pivot for each partition step in various ways. There are various strategies for partitioning an array segment into one subpartition of consecutive array positions that has values less than or equal to the pivot and another subpartition of consecutive array positions with those values greater than the pivot. The recursion that partitions the array into smaller and smaller segments may be stopped in various ways. However, even with all that variation, not any set of values can ever be a partition at any level. Your problem is to consider the Quicksorting of an array that initially has the values 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7 and identify below the one set of values that could possibly be one entire partition at some level of the Quicksort recursion<br />
<br />
a) 6, 9, 7, 8, 9<br />
<br />
b) 3, 1, 3, 1<br />
<br />
c) 5, 4, 3, 3, 5<br />
<br />
d) 1, 4, 1, 3Algorithmshttps://gateoverflow.in/82458/new-gradience-sortingMon, 14 Nov 2016 20:09:42 +0000quick sort
https://gateoverflow.in/79724/quick-sort
Is quick sort in-place algorithm?Algorithmshttps://gateoverflow.in/79724/quick-sortMon, 07 Nov 2016 04:39:13 +0000Quick sort
https://gateoverflow.in/78215/quick-sort
<p>@arjun sir
<br>
why is quick sort with median as pivot not in practice even though it can sort the worst case list in O(nlogn) time?
<br>
median can be found in O(n) time and this divides list into two halves.
<br>
recurrance relation becomes
<br>
T(n) = 2T(n/2)+O(n)
<br>
which gives O(nlogn)
<br>
why do we still say worst case TC of quick sort is O(n^2) when median as pivot can do it in O(nlogn) time?
<br>
<a rel="nofollow" href="http://www.geeksforgeeks.org/can-quicksort-implemented-onlogn-worst-case-time-complexity/">http://www.geeksforgeeks.org/can-quicksort-implemented-onlogn-worst-case-time-complexity/</a>
<br>
this link says we dont implement it bcoz "The hidden constants in this approach are high compared to normal Quicksort"
<br>
but why are we caring about constants here? </p>Algorithmshttps://gateoverflow.in/78215/quick-sortWed, 02 Nov 2016 07:09:00 +0000Algorithm
https://gateoverflow.in/72408/algorithm
<p><img alt="Loading Question" src="https://d2190hpfa85jkd.cloudfront.net/q/97fa53e467ee8cedc3e72e5ad0b6079c.jpg"></p>Algorithmshttps://gateoverflow.in/72408/algorithmFri, 07 Oct 2016 16:17:46 +0000