Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

Exercises

  1.   Determine the running times predicted by the detailed model of the computer given in Section gif for each of the following program fragments:
    1. i = 0
      while i < n:
          k += 1
          i += 1
    2. i = 1
      while i < n:
          k += 1
          i = i * 2
    3. i = n - 1
      while i != 0:
          k += 1
          i = i / 2
    4. i = 0
      while i < n:
          if i % 2 == 0:
      	k += 1
          i += 1
    5. i = 0
      while i < n:
          j = 0
          while j < n:
      	k += 1
      	j += 1
          i += 1
    6. i = 0
      while i < n:
          j = i
          while j < n:
      	k += 1
      	j += 1
          i += 1
    7. i = 0
      while i < n:
          j = 0
          while j < i * i:
      	k += 1
      	j += 1
          i += 1
  2. Repeat Exercise gif, this time using the simplified model of the computer given in Section gif.
  3. Prove by induction the following summation formulas:
    1. tex2html_wrap_inline58387
    2. tex2html_wrap_inline58389
    3. tex2html_wrap_inline58391
  4. Evaluate each of the following series summations:
    1. tex2html_wrap_inline58393
    2. tex2html_wrap_inline58395
    3. tex2html_wrap_inline58397
    4. tex2html_wrap_inline58399
  5. Show that tex2html_wrap_inline58401, for tex2html_wrap_inline58403. Hint: Let tex2html_wrap_inline58405 and show that tex2html_wrap_inline58407.
  6. Show that tex2html_wrap_inline58409. Hint: Let tex2html_wrap_inline58411 and show that the difference tex2html_wrap_inline58413 is (approximately) a geometric series summation.
  7. Solve each of the following recurrences by repeated substitution:
    1. tex2html_wrap_inline58415
    2. tex2html_wrap_inline58417
    3. tex2html_wrap_inline58419
    4. tex2html_wrap_inline58421
    5. tex2html_wrap_inline58423
    6. tex2html_wrap_inline58425
    7. tex2html_wrap_inline58427

next up previous index

Bruno Copyright © 2003, 2004 by Bruno R. Preiss, P.Eng. All rights reserved.