Skip to content

Commit a5ea02f

Browse files
committed
Create QuickSelect 2 partitions
1 parent 9e71b6c commit a5ea02f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

QuickSelect 2 partitions

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
i++;
26+
j--;
27+
}
28+
}
29+
return i; // return the pivot index
30+
31+
}
32+
*/

0 commit comments

Comments
 (0)