We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9e71b6c commit a5ea02fCopy full SHA for a5ea02f
QuickSelect 2 partitions
@@ -0,0 +1,32 @@
1
+Two Types of Partition Exists in QuickSelect
2
+Source: http://cs.stackexchange.com/questions/11458/quicksort-partitioning-hoare-vs-lomuto
3
+1. Lomuto -> To understand this watch this video: https://www.youtube.com/watch?v=MZaf_9IZCrc
4
+2. Hoare -> Normal i and j counter partition
5
+The code for Hoare parition is:
6
+private static int partition(int[] a, int low, int high) {
7
+
8
+ int i = low;
9
+ int j = high;
10
+ int temp = 0;
11
12
+ int pivot = a[low+(high-low)/2];
13
14
+ while(i<=j){
15
+ while(a[i]<pivot)
16
+ i++;
17
+ while(a[j]>pivot)
18
+ j--;
19
+ if(i>j)
20
+ break;
21
+ else{ // if(i<=j)
22
+ temp=a[i];
23
+ a[i]=a[j];
24
+ a[j]=temp;
25
26
27
+ }
28
29
+ return i; // return the pivot index
30
31
32
+*/
0 commit comments