AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th...
-
Upload
kelton-st-ives -
Category
Documents
-
view
213 -
download
0
Transcript of AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th...
![Page 1: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/1.jpg)
Induction
AE1APS Algorithmic Problem SolvingJohn Drake
![Page 2: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/2.jpg)
Coursework 4 deadline – ◦ Thursday 29th November at 1pm
Same submission guidelines as before, hard-copy during lectures or soft-copy via e-mail
Reminder
![Page 3: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/3.jpg)
Invariants – Chapter 2 River Crossing – Chapter 3 Logic Puzzles – Chapter 5 Matchstick Games - Chapter 4
◦ Sum Games – Chapter 4 Induction – Chapter 6
◦ Tower of Hanoi – Chapter 8
Outline of the course
![Page 4: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/4.jpg)
Induction is the name given to a problem solving technique based on using the solution to small instances of a problem to solve larger instances of a problem.
In fact we can solve problems of arbitrary size
Induction
![Page 5: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/5.jpg)
We need to measure the "size" of an instance of a problem
E.g. with matchstick problems, we might call the size the number of matches
Size
![Page 6: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/6.jpg)
It is not always obvious what the size should be for some types of problems
The size must be non–negative i.e. whole numbers 0, 1, 2, …
We call these numbers "natural numbers", as they are naturally used for counting
Size
![Page 7: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/7.jpg)
Note that some mathematicians do not include 0 in the natural numbers
There are good reasons why we should include 0.Zero has important significance in maths (and the history of maths)
One reason in when counting the size of sets, the null set is defined to have size of 0
We will see examples of including 0 later
Zero
![Page 8: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/8.jpg)
We solve the problem in two steps
First we solve the problem instance of size 0
This is usually very easy (often called trivial)
Then, we show how to solve, a problem of size n+1 (where n is an arbitrary natural number), given we have a solution to a problem instance of size n.
Two step process
![Page 9: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/9.jpg)
The first step is called the base case of the basis of induction.
The second step is the induction step
Two step process
![Page 10: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/10.jpg)
By this process, we can solve problems of size 0
We also know how to solve instances of size 1 (as it is one larger than 0)
We can apply the induction step to solve problems of size 2 and so on.
Sizes 0, 1, 2, …
![Page 11: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/11.jpg)
The induction step allows us to solve problems of size one greater than the current size problem
By repeating this process we can solve problems of any size
Sizes 0, 1, 2, …
![Page 12: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/12.jpg)
Straight lines are drawn across a sheet of paper, dividing the paper up into regions.Show that it is possible to colour each region black or white, so that no two adjacent regions have the same colour
Problem statement – cutting the plane.
![Page 13: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/13.jpg)
P120
Cutting the plane
![Page 14: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/14.jpg)
The number of lines is the size of a problem We have to show how to solve the problem
when there are zero lines We have to show how to solve a problem
when there are n+1 lines, assuming we can solve the problem with n lines
Let us call the situation when no two adjacent regions have the same colouring "a satisfactory colouring"
Outline
![Page 15: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/15.jpg)
This is trivial.
With 0 lines, there is one region
This can be coloured black or white and will be a satisfactory colouring.
Zero case (base case)
![Page 16: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/16.jpg)
Assume a number of lines (n) are drawn on the paper, and the regions have a satisfactory colouring
Induction step
![Page 17: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/17.jpg)
Now we add an additional line (i.e. n + 1)
This will divide some existing regions into two new regions, which will have the same colour, therefore the colouring is not satisfactory.
Induction step
![Page 18: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/18.jpg)
The task is to show how to modify the colouring so that it does become satisfactory.
Induction step
![Page 19: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/19.jpg)
Inverting any satisfactory colouring will also give a satisfactory colouring.◦ i.e. changing black regions for white, and vice
versa will also be satisfactory
Let us call the two sides of the new line left and right. Inverting colours in either region will still give a satisfactory colouring in that half (left or right)
The key (or the trick)
![Page 20: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/20.jpg)
Hence, inverting the colours in one half will guarantee a satisfactory colouring for the whole piece of paper
The key (or the trick)
![Page 21: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/21.jpg)
The algorithm for colouring is non-deterministic in several ways◦ The initial colouring is not specified (could be black or
white)◦ The order in which the lines are added is unspecified◦ The naming of the left and right regions is not specified
(symmetry)
This means the final colouring can be arrived at in different ways, but it is guaranteed to be satisfactory
Non- deterministic
![Page 22: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/22.jpg)
A square piece of paper is divided into a grid of size 2n by 2n, where n is a natural number
Individual squares are called grid squares and a single grid square is covered
E.g. n = 3
Triominoes – problem statement
![Page 23: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/23.jpg)
A triomino is an "L" shape made of 3 grid squares. Show that it is possible to cover the remaining grid squares using triominoes
Triominoes – problem statement
![Page 24: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/24.jpg)
The obvious size to use is n
The base case is when n=0, and the grid has size 1 by 1 (i.e. 20 by 20)
This square will of course be covered
The base case is solved
Size and Base case
![Page 25: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/25.jpg)
We want to solve a grid of 2n+1 by 2n+1
We know how to cover a 2n by 2n grid, how do we use this to help us cover a grid size larger by one
We make the inductive hypothesis that this is possible
Inductive Step
![Page 26: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/26.jpg)
A grid of size 2n+1 by 2n+1 can be divided into 4 grids of size 2n by 2n by drawing horizontal and vertical lines
These 4 regions can be called bottom-left, bottom-right, top-left and top-right
One square is already covered, we will assume this is in the bottom left square, why?
The key
![Page 27: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/27.jpg)
The bottom left grid is of size 2n by 2n , of which one square has already been covered.By the induction hypothesis, the remaining squares in the bottom-left grid can be covered
The key
![Page 28: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/28.jpg)
The bottom left grid is of size 2n by 2n , of which one square has already been covered.By the induction hypothesis, the remaining squares in the bottom-left grid can be covered
The key
![Page 29: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/29.jpg)
This leaves us having to cover the remaining 3 grids
None of these have any squares covered
We can apply the inductive hypothesis if just one of the squares in each of the 3 remaining grids is covered
Induction
![Page 30: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/30.jpg)
This can be done by placing a triomino at the junction of the 3 grids
Induction
![Page 31: AE1APS Algorithmic Problem Solving John Drake. Coursework 4 deadline – ◦ Thursday 29 th November at 1pm Same submission guidelines as before, hard-](https://reader036.fdocuments.in/reader036/viewer/2022062621/551c16bf5503469e4f8b5686/html5/thumbnails/31.jpg)
What if we had chosen n = 1 to be our base case?
Our proof would have left out the 0 case, so we would still need to prove that separately
However including 0 provides a slightly deeper insight
"Humans" start counting at 1, computer scientists and mathematicians start counting at 0
If 1 was the base case.