Quicksort algorithm
Why Stack Overflow recommends it
Stack Overflow users link it as a reference when explaining or debugging quicksort partition code, especially in C and C++ answers and questions.
Recommended by 0 people across 0 different months, 2015 to 2021.
What it is
A 20-minute lesson from mycodeschool that explains the quicksort algorithm and implements it in C++. It covers partitioning around a pivot and the divide and conquer approach, with an average case of O(n log n). It is part of the channel's sorting algorithms series.
What people said
Cites Shivam Mitra · 2015-12 · Stack Overflow · on “can anyone explain this peudo code (partition)”
First, you are selecting a pivot element. After partitioning, all the elements smaller than pivot element will be on left side of pivot and all the elements greater than the pivot will be on right side. You can select any element as pivot element. Once the pivot element is chosen, you first assign an initial position to pivot element which is low in your case. Then we loop through all the elements and see if they are smaller or greater than pivot element. Now two case arises: When a[i] > pivot: As (i > j) always hold true, the array element is already on the right side of pivot element. When a[i] < pivot:In this case, the array element lies on right side of pivot and is smaller than pivot. S
Cites buzzbox · 2016-09 · Stack Overflow · on “Quicksort with first element as pivot example”
[this video] for last element as pivot int partition(int *a,int start,int end) { int pivot=a[end],temp,p1=start,i; for(i=start;i<end;i++) { if(a[i]<pivot) { if(i!=p1) { temp=a[p1]; a[p1]=a[i]; a[i]=temp; } p1++; } } temp=a[p1]; a[p1]=a[end]; a[end]=temp; return p1; } [LINK] for first element as pivot int partition1(int *a,int start,int end) { int pivot=a[start],p1=start+1,i,temp; for(i=start+1;i<=end;i++) { if(a[i]<pivot) { if(i!=p1) { temp=a[p1]; a[p1]=a[i]; a[i]=temp; } p1++; } } a[start]=a[p1-1]; a[p1-1]=pivot; return p1-1; } void quicksort(int *a,int start,int end) { int p1; if(start<end) { p1=partition(a,start,end); quicksort(a,start,p1-1); quicksort(a,p1+1,end); } }
Cites krom · 2021-03 · Stack Overflow · on “QuickSort slower than mergeSort”
I was trying out different sorting algorithms. I was interested to really see the difference. I tried it on an array of 10 integers and everything works nicely, but of course, the run time is negligible on small amounts of data. So I tried it on 100,000 integers, and thats where I started to notice which ones are faster than the others. I believe quicksort is known to be faster than mergesort so I was wondering what the problem in my code was. Referenced from ( [this video] ) sorting algorithm series. void quickSort(int num[], int start, int end) { if (start < end) { printf("\n."); int partitionIndex; partitionIndex = randomizedPartition(num, start, end); quickSort(num, 0, partitionIndex - 1); qu