Lecture 04 Ticket

Complete before the beginning of class on Friday, 09/09/2022

Download this ticket in pdf format or .tex source.

\[\def\compare{ {\mathrm{compare}} } \def\swap{ {\mathrm{swap}} } \def\sort{ {\mathrm{sort}} } \def\true{ {\mathrm{true}} } \def\false{ {\mathrm{false}} }\]

Consider the following method that on input a positive integer \(n\) sums the odd numbers from \(1\) to \(2 n - 1\):

1
2
3
4
5
6
  Sum(n):
    total <- 0
    for k = 1 up to n do
      total <- total + 2 * k - 1
    endfor
    return total

Observe that for \(n = 1, 2, 3, 4\), \(\mathrm{Sum}(n)\) returns the values \(1, 4, 9, 16\). In each case, the value returned by \(\mathrm{Sum}(n)\) is \(n^2\). Use induction to argue that this formula always holds: for every positive integer \(n\), the value returned by \(\mathrm{Sum}(n)\) is \(n^2\).

Solution

We will argue the following claim