Practise! Practise! Practise!

And here are additional challenges. Remember - don’t just jump into coding. Think and solve the problem by developing your algorithms on paper first. If you take home only one thing from this module, it’s that!

  1. Assume you have a two-dimensional table. A user gives you the number of columns \(C\), number of rows \(R\), and a two-dimensional index (\(r\), \(c\)) that refers to a cell position, where \(r\) is a row index and \(c\) a column index. Convert (\(r\), \(c\)) to a single-dimensional index \(s\), assuming row-major ordering (i.e. \(s\) is ordered from left to right, and then top to bottom). See the figure below for an illustration. Convert subscripts to linear indices
  2. Try the above in the inverse direction, i.e. convert \(s\) to (\(r\), \(c\)) given \(R\) and \(C\).
  3. Implement a three-dimensional version of the above problem, in both directions; i.e. \((x_1, x_2, x_3) \rightarrow s\) and \(s \rightarrow (x_1, x_2, x_3)\)
  4. Using Newton’s Method, estimate the square root of a number \(n\) (as entered by the user).

    In Newton’s Method, you start with any estimate of the square root, \(x\), and compute a new estimate for \(x\) using \(x^{new} = \frac{x + \frac{n}{x}}{2}\). You then update \(x\) with the new estimate \(x^{new}\) and repeat until \(x\) and \(x^{new}\) do not change.

You are always welcome to use the widget below if you cannot get Python working on your computer!

This is an archived version of the course and is no longer updated. Please find the latest version of the course on the main webpage.