Advanced Data Structures

Fall 2003


[ CIS 410/510 | CIS | UO | News ]


Loop Invariant


Try your hand at some loop invariant problems!
(from "Problem-Solving Strategies" by Arthur Engel, Springer)
  1. On an 8 x 8 checkerboard, we are allowed to switch colors in a single row or column (call the operation switch). Can we obtain a single Black square (and 63 White squares) by repeatedly applying switch?

  2. A clock has six "hours" labeled 1, 0, 1, 0, 0, 0. An operation add changes the labels of two adjacent hours by adding 1 to each. Can we arrive at the clock with all six hours labeled by the same integer by repeatedly applying add?

  3. A 4 x 4 grid has location (1,2) marked -1 and the other 15 locations marked +1. An operation negate changes signs of all locations of a column, a row, a diagonal, a sub-diagonal of the grid. Can we arrive at all locations marked +1 by repeatedly applying negate?

  4. For an odd positive integer n, write the numbers 1, ..., 2n. Repeatedly replace two arbitrary integers, a and b, in the list by the absolute value of their difference, |a-b|. What can you say about the last remaining integer (after 2n-1 replacements)?

  5. Define a sequence of numbers {x_n, y_n} by Does the sequence converge? If so, what is the limit?