Time Cost
http://imgs.xkcd.com/comics/efficiency.png

Summation Review

i=0ni=i=1ni=1+2+...+n=n(n+1)2\sum_{i=0}^{n}i = \sum_{i=1}^{n}i = 1 + 2 + ... + n = \frac{n(n+1)}{2}

Proof:
S=1+2+...+(n1)+nS = 1 + 2 + ... + (n-1) + n
S=n+(n1)+...+2+1S = n + (n-1) + ... + 2 + 1
2S=(n+1)+(n+1)+...+(n+1)+(n+1)2S = (n+1) + (n+1) + ... + (n+1) + (n+1)
2S=n(n+1)2S = n(n+1)
S=n(n+1)2S = \frac{n(n+1)}{2}


i=lucai=ci=luai\sum_{i=l}^{u}ca_i = c \sum_{i=l}^{u}a_i

Proof:
i=lucai=cal+cal+1+...+can\sum_{i=l}^{u}ca_i = ca_l + ca_{l+1} + ... + ca_n
=c(al+al+1+...+an)= c(a_l + a_{l+1} + ... + a_n)
=ci=luai= c\sum_{i=l}^{u}a_i


i+lu(ai±bi)=i=luai±i=lubi\sum_{i+l}^{u}(a_i \pm b_i) = \sum_{i=l}^{u}a_i \pm \sum_{i=l}^{u}b_i


i=lu1=ul+1\sum_{i=l}^{u}1 = u - l + 1


i=1n(aiai1)=ana0\sum_{i=1}^{n}(a_i-a_{i-1}) = a_n - a_0

a_n - {a_{n-1}}
{a_{n-1}} - {a_{n-2}}
...
a_1 - a_0


i=0n2i=2n+11\sum_{i=0}^{n}2^i = 2^{n+1}-1

General: i=0nai=an+11a1\sum_{i=0}^{n}a^i = \frac{a^{n+1}-1}{a-1} where a1a \neq 1


Important Problem Types

Important Design/Problem Solving Techniques

Fundamental Data Structures

The Analysis Framework

Issues:

Approaches

Sequential Search Example

Search for a given value in an array

SequentialSearch
Input: An array, AA, of length nn and a search key KK
Output: The index of the first element of AA that matches KK or 1-1 if there are no matching elements

  i <- 0
  while i < n and A[i] != K do
    i <- i + 1
  if i < n
    return i
  else
    return - 1

Asymptotic Analysis

'Big Oh'
O(g(n))\mathcal{O}(g(n))

The set of all functions with a lower or the same order of growth as g(n)g(n)

Examples:
nO(n2)n \in \mathcal{O}(n^2)
1000n+45O(n2)1000n + 45 \in \mathcal{O}(n^2)
n(n1)2O(n2)\frac{n(n-1)}{2} \in \mathcal{O}(n^2)

n3O(n2)n^3 \notin \mathcal{O}(n^2)
n310000O(n2)\frac{n^3}{10000} \notin \mathcal{O}(n^2)
2nO(n2)2^n \notin \mathcal{O}(n^2)


Ω(g(n))\Omega(g(n))

The set of all functions with a higher or same order of growth as g(n)g(n)

n3Ω(n2)n^3 \in \Omega(n^2)
n(n1)2Ω(n2)\frac{n(n-1)}{2} \in \Omega(n^2)
2nΩ(n2)2^n \in \Omega(n^2)

1000nΩ(n2)1000n \notin \Omega(n^2)
12n2nΩ(n2)\frac{12n^2}{n} \notin \Omega(n^2)
n+5Ω(n2)n + 5 \notin \Omega(n^2)

Θ(g(n))\Theta(g(n))

The set of all functions with the same order of growth as g(n)g(n)

t(n)O(g(n))t(n) \in \mathcal{O}(g(n)) if t(n)t(n) is bounded above by some constant multiple of g(n)g(n) for all large nn.
Bounded Above

12n+44O(n)12n + 44 \in \mathcal{O}(n)
12n+4412n+44n12n + 44 \leq 12n + 44n, n1\forall n \geq 1
56n\leq 56n where c=56nc = 56n and n0=1n_0 = 1

t(n)Ω(g(n))t(n) \in \Omega(g(n)) if t(n)t(n) is bounded below by some constant multiple of g(n)g(n) for all large nn.

Bounded Below

t(n)Θ(g(n))t(n) \in \Theta(g(n)) if t(n)t(n) is bounded both above and below by some constant multiple of g(n)foralllargeg(n) for all largen$

Bounded Above and Below

Example:
log(n!)Θ(nlogn)\log (n!) \in \Theta(n \log n)
log(n1)=log(1)+log(2)+...+log(n)\log (n1) = \log (1) + \log(2) + ... + \log(n)
log(n)+log(n)+...+log(n)\leq \log(n) + \log(n) + ... + \log(n)

log(n!)log(n2)+log(n2+1)+...+log(n)\log(n!) \geq \log(\frac{n}{2}) + \log(\frac{n}{2}+ 1) + ... + \log(n)
log(n2)+log(n2)+...+log(n2)\geq \log(\frac{n}{2}) + \log(\frac{n}{2}) + ... + \log(\frac{n}{2})
n2log(n2)\geq \frac{n}{2} \log(\frac{n}{2})

General Plan for Analysis (Nonrecursive algorithms)


Limits?

Basic Efficiency Classes and Descriptions (p59)

Algorithm Example (if time permits)

Interval Scheduling

* [Summation Review](#summation-review)