MA-305 Homework 7

Due Tuesday, April 15, at the beginning of class



You may do the calculations necessary for these problems either by hand or with Maple. Please submit a handwritten solution, or email an ASCII/Postscript/html document to the TA.

  1. Textbook, Exercise 4.2, p. 259, Problems 9 and 10.
  2. Textbook, Exercise 4.2, p. 259, Problem 16.
  3. Textbook, Exercise 4.3, p. 275, Problem 14.
  4. Textbook, Exercise 4.3, p. 275, Problem 20.
  5. Consider the following test runs on insertion sort:
    math% testisort 10 100
    Input array
    63 94 85 2 11 59 38 47 89 92 
    Sorted array after 29 comparisons
    2 11 38 47 59 63 85 89 92 94 
    math% testisort 15 100
    Input array
    63 94 85 2 11 59 38 47 89 92 17 81 27 0 37 
    Sorted array after 77 comparisons
    0 2 11 17 27 37 38 47 59 63 81 85 89 92 94 
    math% testisort 20 100
    Input array
    63 94 85 2 11 59 38 47 89 92 17 81 27 0 37 11 1 56 46 28 
    Sorted array after 137 comparisons
    0 1 2 11 11 17 27 28 37 38 46 47 56 59 63 81 85 89 92 94 
    math% testisort 25 100
    Input array
    63 94 85 2 11 59 38 47 89 92 17 81 27 0 37 11 1 56 46 28
    10 21 70 92 43 
    Sorted array after 191 comparisons
    0 1 2 10 11 11 17 21 27 28 37 38 43 46 47 56 59 63 70 81
    85 89 92 92 94 
    math% testisort 30 100
    Input array
    63 94 85 2 11 59 38 47 89 92 17 81 27 0 37 11 1 56 46 28
    10 21 70 92 43 29 91 93 94 67 
    Sorted array after 225 comparisons
    0 1 2 10 11 11 17 21 27 28 29 37 38 43 46 47 56 59 63 67
    70 81 85 89 91 92 92 93 94 94 
    math% testisort 50 100
    Input array
    63 94 85 2 11 59 38 47 89 92 17 81 27 0 37 11 1 56 46 28
    10 21 70 92 43 29 91 93 94 67 10 57 13 96 60 25 55 98 72
    44 42 41 77 21 41 66 33 43 22 31 
    Sorted array after 657 comparisons
    0 1 2 10 10 11 11 13 17 21 21 22 25 27 28 29 31 33 37 38
    41 41 42 43 43 44 46 47 55 56 57 59 60 63 66 67 70 72 77
    81 85 89 91 92 92 93 94 94 96 98 
    
    We know that insertion sort uses a quadratic number of comparisions, i.e., C(n) = c0 + c1 n + c2 n2. Using least square fits, determine the constants c0, c1, and c2 and then estimate the number of comparisions taken for n = 10,000.