January 2018
Intermediate to advanced
332 pages
7h 36m
English
Hoare Partition Scheme, on the other hand, takes a pivot value from the middle of the dataset and then starts parsing the values from the low and high end to determine the actual position of the pivot; this results in fewer number of operations as compared to the Lomuto Scheme:
partitionHoare(data, low, high) { // determine mid point var pivot = Math.floor((low + high) / 2 ); // while both ends do not converge while(low <= high) { // increment low index until condition matches while(data[low].pages > data[pivot].pages) { low++; } // decrement high index until condition matches while(data[high] && (data[high].pages < data[pivot].pages)) { high--; } // if not converged, swap and increment/decrement indices if (low <= ...
Read now
Unlock full access