Home Work Number 1, Intro to Algorithms, Spring 2015

Due on Thursday February 12
Please submit your answers (for any 6 questions) in a plain paper (write your name and section number) Type written answers are preferred
Do the following problems from the text book (DG - Dasgupta et al, CLRS - Cormen et al's book) - log(n) means logarithm to the base 2
  1. Exercise 0.2 (page 18 from DG or page 8 of DG in 2008 edition)
  2. Exercise 0.3 a and b (page 18 from DG or page 8 of DG in 2008 edition)
  3. Explain whether the following statements are true or false and why
    1. Is (2 log(n))log(n) = Big-Oh(n log(n)n )?
    2. Is 7 log(n) = Big-Oh(n log(7) )?
    3. Is 2 7log(n) = Big-Oh(n7 )?
  4. Here is an algorithm to sort 4 elements with 5 comparisons and 5 swap instructions (swap swaps the contents of its arguments) . Here is one
    input a,b,c,d
    output: sorted(a,b,c,d) - a < b < c < d
    Algorithm:
    if (a > b) swap(a,b)
    if (c > d) swap(c,d) 
    if (b > d) swap(b,d) // d is the highest
    if (a > c) swap(a,c) // a is the smallest
    if (b > c) swap (b,c)
    
    Answer the following questions.
    1. How many swap instructions will be executed for the input (a,b,c,d order) 100, 20, 30, 40?
    2. How many swap instructions will be executed for the input (a,b,c,d order) 30,100,200,40?
    3. Give an input where all the five swap instructions are executed. (Hint: Think back from the output)
  5. Using 3 swap and compare instructions, how will you merge 2 sets of two sorted elements each.
  6. Order (increasing) the following functions according to their Bih-Oh notation (Approximate each function by a Big-Oh notation and then Order (increasing) them) - Give a brief explanation
    n 1.5,   log(n1.5),  log(log((n)),   n!,  2n2,  n log(n) ,   n/log(n)   22n,   4n
  7. What is the running times for the follwoing two programs - Express your answer in Big-Oh Notation in terms of basic operations.
    1. // output sum
      sum = 0
      for i= 1 to n
       { 
          for j = 1 to i
             {
               for k = 1 to j
                  sum = sum + 1
             }
         }
      
    2. // input a[m][n], x[n]
      // outout b[m]
      for i = 1 to m 
       {  
         for j = 1 to n
            b[i] = a[i][j]*x[j]
       }