Computer Science 15-112, Fall 2011
Class Notes:  Efficiency


  1. Required Reading
  2. Big-Oh
  3. Common Function Families
  4. Efficiency
  5. The Big Idea
  6. Examples

Efficiency

  1. Required Reading
    1. Wikipedia page on Big-Oh Notation (you may gloss over the formal details!)
       
  2. Big-Oh
    1. Describes asymptotic behavior of a function
    2. Informally (for 15112):  ignore all lower-order terms and constants
    3. Formally (after 15112):  see here
    4. A few examples:
  3. Common Function Families
    1. Common Function Families (in increasing size)
      1. Constant  (k)
      2. Logarithmic  (logkn)
      3. Square-Root (n0.5)
      4. Linear  (kn)
      5. Linearithmic, Loglinear, or quasilinear  (nlogn)
      6. Quadratic  (kn2)
      7. Exponential  (kn)
    2. Graphically
      (Images borrowed from here)





       
  4. Efficiency
  5. The Big Idea
  6. Examples
    1. isPrime versus fasterIsPrime
    2. linear search versus binary search
      • Definitions
        • Linear search:  check each element in turn
        • Binary search:  check middle element, eliminate half on each pass
      • Number-guessing game
      • Find a value in a sorted list (if we knew about lists...)
      • Find a root (zero) of a function with bisection (really just binary search)
    3. selectionsort versus mergesort
      • See David Eck's most-excellent xSortLab
      • Also see these fun dancing-based visualizations of selectionsort and mergesort
      • Definitions
        • selectionsort: repeatedly select largest remaining element and swap it into sorted position
        • mergesort:  sort blocks of 1's into 2's, 2's into 4's, etc, on each pass merging sorted blocks into sorted larger blocks
      • Analysis (in class)
    4. From lab2:  isPrime(nthHappyNumber(n))

carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem