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!
- 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.
- Try the above in the inverse direction, i.e. convert \(s\) to (\(r\), \(c\)) given \(R\) and \(C\).
- 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)\)
- 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!