algorithm = takes one-or-more values, produces an outputs

Ex: contains

Given a list of and value , return

Input: is an array, is a value Output: true if , false otherwise

i, r := 0, false
while i neq |L| do
  if L[i] = v then
    r := true
    i := i + 1
  else
    i := i + 1
return r

invariants

Induction hypothesis that holds at beginning of iteration.

Deterministic

  1. Base case: inv holds before the loop
  2. Hypothesis: holds after j-th, j<m repetition of loop
  3. Step: assume inv holds when start m-th loop, proves it holds again at the end of m-th loop

Are we done?

  • Assuming invariant does it reach conclusion
  • Does it end?

Formal argument: prove a bound function

bound function on the state of the algorithm such that the output of

  • natural number (0, 1, 2, …)
  • strictly decreases after each iteration

starts at

correctness.

  1. pre-condition: restriction require on input
  2. post-condition: should the output be
  3. prove the running the program turns pre-condition and post-condition

complexity.

assume V is not in the list Contains(N) = 5 + 7N

given V is in the list

contains is correct, runtime complexity is and memory complexity is

runtime.

graph comparison

models are simplification.

shows different growth rates.

Interested in scalability of algorithm For large enough inputs, contains will always be faster than altc because order of growth of Growth

upper bounded (at-most)

lower bounded (at-least)

equivalent (strictly bounded)