| 1 if n = 0 or n = 1 n! = | | n*(n-1)! if n > 1
BinarySearch(A, first, last, key)
- if first >= last
- return NOT_FOUND
- mid = (first + last)/2
- if A[mid] match the key
- return mid
- else if A[mid] is less than the key
- return BinarySearch(A, mid+1, last, key);
- else
- return BinarySearch(A, first, mid-1, key);
MergeSort(A, low, high)Merge(A, low, mid, high)
- if low >= high
- return
- mid = (low+high)/2
- MergSort(A, low, mid)
- Mergesort(A, mid+1, high)
- Merge(A, low, mid, high)
- while there is data in each sub list
- copy the smallest data value to the merged list
- Copy the data remaining in one of the lists to the merged list
l l l h h h u u u _ 0 1 2 3 4 5 6 7 8 2 0 3 9 7 6 5 1 8 pivot value = 4, pivot location = 3, current = 6
QuickSort(A, low, high)Partition(A, low, high)
- if low < high
- pos = Partition(A, low, high)
- Quicksort(A, low, p-1)
- Quicksort(A, p+1, high)
- pivot = A[hi]
- pivotLoc = low-1
- for j = low to high-1
- if A[j] <= pivot
- i = i + 1
- swap(A[i],A[j]);
- i = i + 1
- swap (A[i], A[hi]
- return i