4! = 4(4-1)! = 4 * 3! 3! = 3(3-1)! = 3 * 2! 2! = 2 * 1! 1! = 1 * 0! 0! = 1 by definition = 1 * 1 = 1 2! = 2 * 1 =2 3! = 3 * 2 = 6 4! = 4 * 6 = 24
f(1) = 1 f(2) = 1 f(5) = f(4) + f(3) f(4) = f(3) + f(2) f(3) = f(2) + f(1) = 1 + 1 = 2 f(4) = 2 + 1 = 3 f(5) = 3 + 2 = 5
BinarySearch(A, begin, end, key)
- if begin > end
- return NOT_FOUND
- mid ← (begin+end)/2
- if A[mid] == key
- return mid
- else if A[mid] > key
- return BinarySearch(A,begin, mid-1, key)
- else
- return BinarySearch(A,mid+1,end,key)