Fundamentals
See also: complexity analysis
LinearSearch(L, v, o)
: potentially-high cost
recursive binary search:
repetition → induction
Induction hypothesis:
∀ L′,v′ ∃ 0≤b≤e≤∣L′∣∧0≤e−b<m
Recursive case: mid := (begin + end) div 2
: b≤mid<e
termination bound function: e−b
Complexity:
T(n)=⎩⎨⎧1 1⋅T(⌊2n⌋)+1 if n=0;if n>1.
Complexity: T(n)=1⋅T(⌊2n⌋)+1. Assume n=2x, work = 1
x+2=log2(n)+2→Θ(log2(n))
Can usually assume n=2x
LowerBoundRec
is correct and runtime and memory complexity of Θ(log2(∣L∣))
non-recursive binary search: