C455 – Test 1 Sample and Study Guide

 

 

  1. Know the following terminology:
  1. Loop invariants
  2. Given code containing a loop, perform a loop trace cost analysis.
     

  3.  
  4. Given T(n) = T(n * 9/10) + n, use substitution proof to show that T(n) = W(n)

    IH: T(n*9/10)  ³ c n * 9/10

    Show:    T(n) = T(n * 9/10) + n  ³ c n

    Proof:

    T(n) = T(n * 9/10) + n
      ³ c n * 9/10 + n
      = (c*9/10+1) n
      ³ c n
    (c*9/10+1) n ³ c n
    (c*9/10+1)

    ³ c

    Holds for c = 1 > 0
       

    Base:

    Try n0 = 1, c = 1
    T(n) = T(n * 9/10) + n ³ c n
    T(1) = T(1 * 9/10) + 1  ³ 1 * 1
    Holds for n0 = 1, c = 1  

     


  5.  Given an algorithm, define the recurrence.