Master theorem
Let a 1 and b > 1 be constants, let f(n) be a
function, and let T(n) be defined on the nonnegative integers by the recurrence
T(n) = aT(n/b) + f(n)
where we interpret n/b to mean either the floor or
ceiling of n/b. Then T(n) can be bounded
(g(n) = cfw_ f(n): there exists positive constants
c1, c2, n0 such that 0 c1g(n) f(n) c2g(n)
for all n n0
O(g(n) = cfw_ f(n): there exists positive constants
c, n0 such that 0 f(n) cg(n) for all n n0
(g(n) = cfw_ f(n): there exists positive constants
c,
The Sorting Problem
Formal definition:
Input: A sequence of numbers
a1 , a2 , , an
Output: A permutation (reordering) a1, a2 , an
permutation (reordering)
of the input sequence such that a1 a2 an
INSERTION-SORT(A)
Another INSERTION-SORT pseudocode:
for j
Algorithms
What is an algorithm?
An algorithm is any well-defined computational
procedure that takes some value, or set of values, as
input and produces some value, or set of values, as
output. An algorithm is thus a sequence of
computational steps that