To Table of Contents To Bottom of Page To Next Chapter

CS421 - Advanced Data Structures and Algorithm Development - Chapter 1 OverView


  1. Problems
    We want to identify solvable problems, and for each such problem we want bounds on the computational cost. Our aim is to solve problems with as little computational effort per problem instance as possible.
    • Problem Types
      • Search problems: find an X in the input satisfying property Y. [ch. 2-3]
      • Structured problems: Transform the input to satisfy property Y. [ch. 4-5]
      • Construction problems: Build an X satisfying property Y. [ch. 5-6]
      • Optimization problems: Find the best X satisfying property Y. [ch. 6-7]
      • Decision problems: Decide whether the input satisfies property Y. [ch. 6-7]
      • Adaptive problems: Maintain property Y over time.
    • Categories of hard problems
      • A conceptually hard problem (don't understand the problem well enough)
      • An analytically hard problem (don't know how to analyze how long it will take to solve every problem instance)
      • A computationally hard problem (relatively small problem instances will take millions of years to solve)
      • A computationally unsolvable problem (no algorithm can exist)
    • Towers of Hanoi problem
  2. Models
    The set of legal operations is the environment and the subset of operations we want to minimize is the goal. The environment and the goal together make up the model.
  3. Algorithms - finite sequence of operations, each chosen from a finite set of well-defined operations.
    • PAUSE: Think about the algorithm for solving the Towers of Hanoi.
    • An algorithm that uses itself to solve a problem is called a recursive algorithm.
    • The forward-backward strategy: Solve simple special cases and then generalize their solution, then test the generalization on other special cases.
  4. Analysis
    • Upper Bounds
      "Analysis first involves figuring out bounds on the number of operations an algorithm performs given an input of size n. Usually we will first find its worst cost, that is, the maximum number of times it performs the chosen operation. since the algorithm is proof that we can solve the problem using at most that number of operations, even in the worst case, this gives an upper bound on the problem's worst cost as a function of n.

      PAUSE: Can the average cost be worse than the worst cost, or better than the best cost?

      Find the average cost (=worst cost) for the Towers of Hanoi.

      PAUSE: Show the cost to equal 2n - 1.

      Proof by Induction:

      1. Basic Step: HANOI makes one disk move when n = 1, so f(1) = 1. f(1) = 21 - 1. Therefore, f(n) = 2n - 1 when n = 1.
      2. Inductive Step: Suppose that for all k < n, f(k) = 2k - 1. then since n > 1, from the recurrence we must have that f(n) = 2f(n - 1) + 1. But n > n - 1. Therefore f(n) = 2 (2n-1 - 1) + 1 = 2n - 1.
      3. Hence, if the inductive assumption is true for all k < n then it is true for n as well. Thus, f(n) = 2n - 1 for all n.

    • Lower Bounds
      The smallest number of operations necessary to solve the problem over all inputs of size n is the lower bound. on the problem's worst cost. An upper bound is a measure of how bad a particular algorithm can be; a lower bound is a measure of how hard a particular problem is.
      Let g(n) = an upper bound and h(n) = a lower bound; If beyond some point g(n) - h(n) <= c, for some constant c, then there is no point looking for a better algorithm; up to a constant, A is as good a solution as is possible within M. A is worst case optimal for problem P.
      If g(n) - h(n) > c for any c, even for large n, but beyond some point g(n)/h(n) <= c, for some non-zero constant c then within M, A is worst case asymptotically optimal for P. [asymptotic upper bound: f(n) = O(g(n)) if there exists positive constants c, n0 such that f(n) <= c g(n) for all n > n0

      In HANOI, we must move every disk but the biggest at least twice and the the biggest at least once so 2n - 1 is a lower bound. But each time we move the biggest disk, we must also move all n-1 disks, so f(n) >= f(n-1) [f is non-decreasing].
      PAUSE: Use induction to show that f(n) >= 2n - 1.


  5. Now What?
    if the upper and lower bounds match then stop,
    else if they're close enough or the problem isn't that important then stop,
    else if the model focuses on the wrong thing, then restate it,
    else if the algorithm is too fat then generate a slimmer algorithm,
    else if the lower bound is too weak then generate a stronger lower bound.
    repeat to perfection or exhaustion.
  6. Napkin Mathematics
    logxy = z «==» xz = y «==»xlogxy = y
    logx(rs) = logxr + logxs   and   logx(r/s) = logxr - logxs  and  lgab = b lga

    Compare n! with 2n and 22n
    Write their recurrence functions
    PAUSE: Use induction to show that n! >= 22n for n >= 9.
    Binomial Theorem and Binomial coefficients
    Fibonacci
    Find the amount of work done by the code fragment in Figure 1.1 (pg.33)
    Summations
    PAUSE: Estimate the summation of (ai + b) from 1 to n.
    The subtract-and-guess or divide-and-guess strategy: To find the value of the sum f, pick a known function g and find a pattern in the terms f(n) - g(n) or f(n) / g(n)
    e.g. to find the summation of i from 1 to n, compare with g(n) where g(n) is summation of 1 from 1 to n and then divide
    PAUSE: What is the summation of n2
    How fast do the Fibonacci numbers grow?

  7. Growth Rates
    Two functions of n have different growth rates if as n goes to infinity their ratio either goes to infinity or to zero. If their ratio stays near a non-zero constant then they are asymptotically the same function.
    Compare function in terms of the number of digits [pg. 39]
    Do all these functions have different growth rates? IF we take the ratio of any two, does the ratio go to zero or infinity? Or stay near a non-zero constant?
    Is there a constant so large that if we nultiply n by it, the resulting function is always large than n2. PROVE IT!
    Order: lg lg n  lg n  lg2n  n1/10  sqrt n  n  n lg n  n2  2n  n!  22n  2n!
    • Limits [lim f(n) as n approaches infinity is defined as: for all s > 0, there exists a c > 0 such that if n > 0 implies that r+s > f(n) > r-s
    • Order Notation
      f=o(g) f is slower than g
      f=O(g) f is no faster than g
      f=Q(g) f is about as fast as g[f=O(g) and g=O(f)]
      f~g f is as fast as g
      f=W(g) f is no slower than g [g=O(f)]
      A function f is O of g if there are positive constants r and c such that f(n) <= r g(n) for all n bigger than c. [f =O(g)]
      o is like <; O is like <=; Q [theta] is like "roughly equal"; ~ is like= ; W [omega] is like >=
      Q(1) constant
      Q(lg n) logarithmic
      Q(lgc n, c>=1 polylogarithmic
      Q(nr)0<r<1 sublinear
      Q(n) linear
      Q(nr1<r<2) subquadratic
      Q(n2) quadratic
      Q(n3) cubic
      Q(nc, c>=1) polynomial
      Q(rn, r>1) exponential
    • Manipulating Order Notation
      lim f(n) / g(n) = r implies f = O(g)
      lim f(n) / g(n) = r > 0 implies f = Q(g)
      n = O(n2)
      PAUSE: Show that if n = o(n2) then (n2) is not O(n)
    • Differentiation [definition and examples]; l'Hopital's Rule
      Show that lg n = o(sqrt (n))
      Show that lg2n = o(n1/10)

  8. Back to Reality
  9. Should we forget about "infinitely growing" inputs? [if we do, then all algorithms are constant time!]
    If the input is relatively small, then almost any algorithm will do [unless the problem is very common or very hard]. If the input is extremely large, then no algorithm will do.
  10. Hard Problems
    • hiker problem
    • domino and chessboard problem
    • Prime #s.
      • Is 667 prime?
      • 267 - 1 = 147573952589676412927 = 193707721 x 761838257287
      • Is (2353+1)/3 prime?
      • NP complete problems [i.e. satisfiability problem - Can a proposition composed of variables that can only have two logical values ever be true (be satisfied)?]
    • Solving Hard Problems
      • dynamic programming
      • greedy algorithm
      • approximation algorithm
      • probabilistic algorithm - guaranteed to work most of the time
        Problem: Decide whether (6x2 + 3x3 - x)3 + (6x2 - 3x3 + x)3 = (6x2(3x2 + 1))2
        Algorithm: Generate a random number and see if it satisfies the equation.
  11. Coda - The Continent of Analysis
    • Can we learn all of the tools?
    • 3 kinds of hard but solvable problems: conceptual, analytical, and computationally hard

To Table of Contents To top of page To Next Chapter