Monday, October 29, 2007

Recursion

In many cases, your recursive functions may need additional data structures or an argument that tracks the recursion level. Often the best solution in such cases is to move the data structure or argument initialization code into a separate function. This is wrapper function.

Binary Search: running time O(log(n))

range = upper - lower;
error conditions:
1. range <0
2. range == 0 && array[lower] != target
target not exist
3. array[lower] > array[upper]
unsorted array

center = (upper-lower)/2 + lower;

No comments: