next up previous contents index CD CD Algorithms
Next: Implementation Challenges Up: Introduction to Algorithms Previous: War Story: Psychic Modeling

Exercises

 

  1. Let P be a problem. The worst-case time complexity of P is tex2html_wrap_inline23815 . The worst-case time complexity of P is also tex2html_wrap_inline23817 . Let A be an algorithm that solves P. Which subset of the following statements are consistent with this information about the complexity of P?

  2. Suppose that an algorithm A runs in worst-case time f(n) and that algorithm B runs in worst-case time g(n). For each of the following questions, answer either yes, no, or can't tell and explain why.

    (a) Is A faster than B for all n greater than some tex2html_wrap_inline23833 if tex2html_wrap_inline23835 ?

    (b) Is A faster than B for all n greater than some tex2html_wrap_inline23837 if tex2html_wrap_inline23839 ?

    (c) Is A faster than B for all n greater than some tex2html_wrap_inline23841 if tex2html_wrap_inline23843 ?

    (d) Is B faster than A for all n greater than some tex2html_wrap_inline23845 if tex2html_wrap_inline23847 ?

    (e) Is B faster than A for all n greater than some tex2html_wrap_inline23849 if tex2html_wrap_inline23851 ?

    (f) Is B faster than A for all n greater than some tex2html_wrap_inline23853 if tex2html_wrap_inline23855 ?

  3. For each of these questions, briefly explain your answer.

    (a) If I prove that an algorithm takes tex2html_wrap_inline23857 worst-case time, is it possible that it takes O(n) on some inputs?

    (b) If I prove that an algorithm takes tex2html_wrap_inline23861 worst-case time, is it possible that it takes O(n) on all inputs?

    (c) If I prove that an algorithm takes tex2html_wrap_inline23865 worst-case time, is it possible that it takes O(n) on some inputs?

    (d) If I prove that an algorithm takes tex2html_wrap_inline23869 worst-case time, is it possible that it takes O(n) on all inputs?

    (e) Is the function tex2html_wrap_inline23873 , where tex2html_wrap_inline23875 for even n and tex2html_wrap_inline23877 for odd n?

  4. For each of the following, answer yes, no, or can't tell. Explain your reasoning!

    (a) Is tex2html_wrap_inline23879 ?

    (b) Is tex2html_wrap_inline23881 ?

    (c) Is tex2html_wrap_inline23883 ?

    (d) Is tex2html_wrap_inline23885 ?

  5. (*) Give a proof or counterexample to the following claim: if f(n) = O(F(n)) and g(n) = O(G(n)), then f(n)/g(n) = O(F(n)/G(n)).
  6. (*) Does f(n) = O(g(n)) imply that tex2html_wrap_inline23895 ? Explain your reasoning!
  7. (*) Give a proof or counterexample to the following claim: for all functions f(n) and g(n), either f(n) = O(g(n)) or g(n) = O(f(n)).
  8. (*) When you first learned to multiply numbers, you were told that tex2html_wrap_inline23905 means add x a total of y times, so tex2html_wrap_inline23907 . What is the time complexity of multiplying two n-digit numbers in base b (people work in base 10, of course, while computers work in base 2) using the repeated addition method, as a function of n and b. Assume that single-digit by single-digit addition or multiplication takes O(1) time. (hint: how big can y be as a function of n and b?)  
  9. (*) In grade school, you learned to multiply long numbers on a digit by digit basis, so that tex2html_wrap_inline23911 . Analyze the time complexity of multiplying two n-digit numbers with this method as a function of n (assume constant base size). Assume that single-digit by single-digit addition or multiplication takes O(1) time.


next up previous contents index CD CD Algorithms
Next: Implementation Challenges Up: Introduction to Algorithms Previous: War Story: Psychic Modeling

Algorithms
Mon Jun 2 23:33:50 EDT 1997