Java Reference
In-Depth Information
Algorithm mergeSort(a, tempArray, first, last)
if (first < last)
{
2.
mid = (first + last) / 2
mergeSort(a, first, mid)
mergeSort(a, mid + 1, last)
if (array[mid] > array[mid + 1]))
Merge the sorted halves a[first..mid] and a[mid+1..last] using the array tempArray
}
3.
quickSort(array, 0, 7)
partition(array, 0, 7)
96248753
36248759
36258749
32658749
32458769
quickSort(array, 0, 1)
insertionSort(array, 0, 1)
23458769
quickSort(array, 3, 7)
partition(array, 3, 7)
23458769
23458679
23456879
23456789
quickSort(array, 3, 4)
insertionSort(array, 3, 4)
23456789
quickSort(array, 6, 7)
insertionSort(array, 6, 7)
23456789
4.
6340 1234 0291 0003 6325 0068 5227 1638
634 0 029 1 000 3 123 4 632 5 522 7 006 8 163 8
00 0 363 2 552 2 712 3 416 3 863 4 000 6 802 9 1
0 0 03 0 0 68 5 2 27 1 2 34 0 2 91 6 3 25 6 3 40 1 6 38
0 003 0 068 0 291 1 234 1 638 5 227 6 325 6 340
0003 0068 0291 1234 1638 5227 6325 6340
Algorithm radixSort(a, first, last, wordLength)
// Sorts the array of lowercase words a[first..last] into ascending order;
// treats each word as if it was padded on the right with blanks to make all words have
// the same length, wordLength .
for (i = 1 to wordlength)
{
5.
Clear bucket['a'] , bucket['b'] , . . . , bucket['z'] , bucket[' ']
for (index = first to last)
{
letter = i th letter from the right of a[index]
Place a[index] at end of bucket[letter]
}
Place contents of bucket['a'] , bucket['b'] , . . . , bucket['z'] , bucket[' ']
into the array a
}
 
Search WWH ::




Custom Search