1
00:00:00,760 --> 00:00:01,760
Welcome back.
2
00:00:01,760 --> 00:00:09,430
So we have been looking at how to count using
Recurrences.
3
00:00:09,430 --> 00:00:11,850
So stepping back a little.
4
00:00:11,850 --> 00:00:19,430
So we have been looking at Combinatorics which
is a branch of mathematics involving counting.
5
00:00:19,430 --> 00:00:28,920
And the typical question is how to count the
cardinality of the set.
6
00:00:28,920 --> 00:00:37,079
And here we mostly talk about the case when
the set is given implicitly and not explicitly.
7
00:00:37,079 --> 00:00:39,530
That means the set is described in words and
I want to know how many elements are there
8
00:00:39,530 --> 00:00:40,530
in the set?
9
00:00:40,530 --> 00:00:48,559
A typical example is how many elements of
a universe satisfy a certain set of conditions?
10
00:00:48,559 --> 00:00:56,940
Or how many ways can I draw an element from
the universe such that satisfies certain set
11
00:00:56,940 --> 00:01:03,879
of conditions?
12
00:01:03,879 --> 00:01:11,159
So here the some of the example that we already
seen and how to tackle them.
13
00:01:11,159 --> 00:01:21,000
In fact, the big problem of counting is that
the-- all the problems are unique and one
14
00:01:21,000 --> 00:01:23,130
need to apply a technique that fits it.
15
00:01:23,130 --> 00:01:31,660
Counting is in fact one of the most challenging
subjects in mathematics and big names in mathematics
16
00:01:31,660 --> 00:01:36,700
has also works on this particular area.
17
00:01:36,700 --> 00:01:41,630
And we will be showing you some tricks and
tools of how to count.
18
00:01:41,630 --> 00:01:53,190
So one of the things that we looked at is
how to select k objects from n objects and
19
00:01:53,190 --> 00:02:00,570
in that case we looked at whether the order
in which we select the elements matter and
20
00:02:00,570 --> 00:02:07,990
whether we can select a same object multiple
times.
21
00:02:07,990 --> 00:02:14,530
And for all the four cases we came up with
a solution which was a Compact nice beautiful
22
00:02:14,530 --> 00:02:28,689
solution something like the n! by k! times
(n-k)!, in this case.
23
00:02:28,689 --> 00:02:37,110
Now similar problem was how to distribute
n balls into k bins.
24
00:02:37,110 --> 00:02:42,519
And here also there are multiple cases to
be looked at namely whether the bins are distinguishable
25
00:02:42,519 --> 00:02:49,349
or the balls are distinguishable or whether
the ordering in the bins matter or some of
26
00:02:49,349 --> 00:02:52,909
the bins can remain empty and so on.
27
00:02:52,909 --> 00:02:59,769
Now have been look these cases also we came
up with the certain set of answers to all
28
00:02:59,769 --> 00:03:01,620
the various cases.
29
00:03:01,620 --> 00:03:06,010
And they are mostly compact.
30
00:03:06,010 --> 00:03:17,049
We says that we have some idea about how to
– what are these values are.
31
00:03:17,049 --> 00:03:23,390
And we use all these tricks to solve this
set of problems.
32
00:03:23,390 --> 00:03:31,090
The final problem was this problem of how
many 0,1 strings of length n are there that
33
00:03:31,090 --> 00:03:32,620
does not contain any consecutive zero.
34
00:03:32,620 --> 00:03:44,000
And if you take the way in which we did this
problem back we started with notation of T(n)
35
00:03:44,000 --> 00:03:50,379
be the number of 0,1 strings of length n which
does not contain any consecutive zero.
36
00:03:50,379 --> 00:03:58,819
We proved that T(1) equals to 2; T(2) equals
to 3 this we did by pure counting and then
37
00:03:58,819 --> 00:04:07,540
you prove that T(n) is equals to T(n-1) +
T(n-2) and this in fact gave us a procedure
38
00:04:07,540 --> 00:04:11,690
of computing T(n).
39
00:04:11,690 --> 00:04:16,870
Of course we left it in the case that can
we find a nice expression for T(n).
40
00:04:16,870 --> 00:04:25,820
And we will come back to this particular question
later on in the next videos.
41
00:04:25,820 --> 00:04:32,220
But the main idea was that we basically converted
the problem of counting into a recurrence
42
00:04:32,220 --> 00:04:33,220
relation.
43
00:04:33,220 --> 00:04:39,570
Or in other words we converted it into some
sequence of numbers so that we have a set
44
00:04:39,570 --> 00:04:47,100
of initial conditions and we can any further
term is defined as a function of the preceding
45
00:04:47,100 --> 00:04:48,220
terms, right.
46
00:04:48,220 --> 00:04:57,030
So here where the set of initial equations
and here is the thing where it is recurrence
47
00:04:57,030 --> 00:05:15,390
relations where the T(n) is decide it is--
written as a function
48
00:05:15,390 --> 00:05:16,950
of T(n-1) and T(n-2).
49
00:05:16,950 --> 00:05:21,630
Now, Recurrence relations are extensively
used in various subjects.
50
00:05:21,630 --> 00:05:28,790
And in fact they have one of the very strong
ways of modeling problems particularly counting
51
00:05:28,790 --> 00:05:37,220
problems and solving recurrence relations
is also big part of this subject.
52
00:05:37,220 --> 00:05:42,500
Now in this video we will be looking at one
more problem and see how we can model it using
53
00:05:42,500 --> 00:05:43,500
recurrence relations.
54
00:05:43,500 --> 00:05:54,380
The topic, the problem is called the “Tower
of Hanoi” problem.
55
00:05:54,380 --> 00:06:03,710
And the main idea is that you have three polls
and n disks of different sizes.
56
00:06:03,710 --> 00:06:08,380
So let me show you the picture so something
like this you have three polls and you have
57
00:06:08,380 --> 00:06:15,991
this n disks here, these are n disks 1,2,3,4
and they are arranged in such a way that the
58
00:06:15,991 --> 00:06:23,610
smallest one is on top, largest one is on
the bottom and so the next-- this one is--
59
00:06:23,610 --> 00:06:36,970
this one is bigger than this, so the one which
is basically arranged in a decreasing form.
60
00:06:36,970 --> 00:06:45,840
And the goal is to somehow place all these
things – all these n disks into the second
61
00:06:45,840 --> 00:06:48,690
one into this one.
62
00:06:48,690 --> 00:06:51,180
And what we can do?
63
00:06:51,180 --> 00:06:59,930
You can remove one at any point of time; you
can remove one disk from here and put it anywhere.
64
00:06:59,930 --> 00:07:05,600
But you cannot put a bigger disk on a smaller
disk, okay.
65
00:07:05,600 --> 00:07:09,970
So let me go on it.
66
00:07:09,970 --> 00:07:16,080
There are three posts and n disks of different
sizes.
67
00:07:16,080 --> 00:07:21,470
Each disk has a hole through the center so
that it fits on a post.
68
00:07:21,470 --> 00:07:26,360
At the start all n disks are on the post #1.
69
00:07:26,360 --> 00:07:32,870
The disks are arranged by size so the smallest
is on the top and the largest is on the bottom.
70
00:07:32,870 --> 00:07:41,100
The goal is to end up with all the n disks
in the same order on a different post.
71
00:07:41,100 --> 00:07:48,920
In a single move one can move one disk from
one post and place it to the another post.
72
00:07:48,920 --> 00:07:57,550
And at no point can one place a bigger disk
over a smaller disk.
73
00:07:57,550 --> 00:08:09,800
Question is how many steps will be taken to
move n disk from post #2 to any other post.
74
00:08:09,800 --> 00:08:16,310
So here is the typical picture of Tower of
Hanoi and it is like the game that kids play
75
00:08:16,310 --> 00:08:27,180
but you cannot place a bigger disk on top
of a smaller disk on any of the post.
76
00:08:27,180 --> 00:08:35,550
So question is that how many ways can you
make the move?
77
00:08:35,550 --> 00:08:45,580
So for doing the counting the typical way
of doing it is again let H(n) be the number
78
00:08:45,580 --> 00:08:47,490
of steps required to move n disks.
79
00:08:47,490 --> 00:08:57,080
Now if H(n) is
the number of steps required to move n disks,
80
00:08:57,080 --> 00:09:03,190
how many-- so can we say something above this
H(n)?
81
00:09:03,190 --> 00:09:04,380
What about H(1)?
82
00:09:04,380 --> 00:09:14,820
So H(1), since I do not have I cannot draw
this so I just draw as numbers okay so I have
83
00:09:14,820 --> 00:09:18,870
a three post and I have this number one.
84
00:09:18,870 --> 00:09:26,700
Now of course if I have to place this one
in this next pole I just lift to pop this
85
00:09:26,700 --> 00:09:30,290
one out and push it in the next one.
86
00:09:30,290 --> 00:09:36,650
So clearly H(1) equals to one right and this
is the trivial thing.
87
00:09:36,650 --> 00:09:38,870
What about H(2)?
88
00:09:38,870 --> 00:09:40,240
H(2) is interesting.
89
00:09:40,240 --> 00:09:51,170
Right, so I have these three poles says in
the first one I have 1 and then 2.
90
00:09:51,170 --> 00:09:56,070
How can I move this 1,2 to the second pole?
91
00:09:56,070 --> 00:10:03,089
So of course the first thing that I have to
do is I have to move this first and I move
92
00:10:03,089 --> 00:10:06,260
it to the first one.
93
00:10:06,260 --> 00:10:23,160
So I have one made one move then I move the
second one to the second place so I make another
94
00:10:23,160 --> 00:10:25,540
move one.
95
00:10:25,540 --> 00:10:36,170
And in the third I move the first one back
to the second one so which is one more move
96
00:10:36,170 --> 00:10:37,850
also.
97
00:10:37,850 --> 00:10:45,080
So good so I make, so number of H(2) is actually
equals to 3.
98
00:10:45,080 --> 00:10:50,420
Let us see one more example.
99
00:10:50,420 --> 00:10:56,010
What about H(3)?
100
00:10:56,010 --> 00:11:01,110
So here I have 1, 2 and 3.
101
00:11:01,110 --> 00:11:08,550
I need to move this 1, 2, 3 to the next pole.
102
00:11:08,550 --> 00:11:20,200
Now I know how to move 1,2 to the second pole
maybe I can also move it to third pole right
103
00:11:20,200 --> 00:11:32,089
so I can move 1 to here, 2 to here then I
move 1 from here to here, so I have till now
104
00:11:32,089 --> 00:11:40,730
made three moves right three then I make move
this number 3 to this second one.
105
00:11:40,730 --> 00:12:01,820
I have made four moves and now I move 1 to
here then I move 2 to here and I move the
106
00:12:01,820 --> 00:12:03,390
1 to here.
107
00:12:03,390 --> 00:12:10,300
So I have made– initially I have made 1,
2, 3 then I made one more move then I made
108
00:12:10,300 --> 00:12:15,180
two more moves so namely I have made seven
moves all total.
109
00:12:15,180 --> 00:12:18,020
So H (3) is 7.
110
00:12:18,020 --> 00:12:27,090
Now like this if I keep on continuing and
say if I know H (1) to H (n-1) can I compute
111
00:12:27,090 --> 00:12:38,000
H(n) and that is the question to be asked.
112
00:12:38,000 --> 00:12:41,860
So let us see first here.
113
00:12:41,860 --> 00:12:47,529
First of all, can I get upper bound on H(n)?
114
00:12:47,529 --> 00:12:56,839
If you remember what we did for the case of
H (3) let us see what was done.
115
00:12:56,839 --> 00:13:09,060
We first used H(n-1) step to move the top
n-1 disks from the first pole to the third
116
00:13:09,060 --> 00:13:10,540
pole right.
117
00:13:10,540 --> 00:13:16,070
That we can do because that is the definition
of H(n-1).
118
00:13:16,070 --> 00:13:23,040
Then I move the nth disk the bottom most disk
from the first pole to the second pole.
119
00:13:23,040 --> 00:13:30,960
And then again I moved the n-1 disks on top
of the second pole.
120
00:13:30,960 --> 00:13:38,090
So sorry this is not third pole this should
be second pole.
121
00:13:38,090 --> 00:13:47,770
This second pole right and this is also not
the first pole this is on the third pole.
122
00:13:47,770 --> 00:13:51,190
So I had it on the third pole, from third
pole I moved it to second pole.
123
00:13:51,190 --> 00:13:58,510
So in other words total number of steps that
I made was of course less than 2 times H(n-1)
124
00:13:58,510 --> 00:13:59,510
-1.
125
00:13:59,510 --> 00:14:07,570
So what we have is that the minimum number
of steps required is less than or equal to
126
00:14:07,570 --> 00:14:11,010
2 times H(n-1) – 1.
127
00:14:11,010 --> 00:14:15,980
Now unfortunately this is just upper bound.
128
00:14:15,980 --> 00:14:20,410
Can we get a lower bound?
129
00:14:20,410 --> 00:14:27,270
Or in other word is it possible that this
number H(n) is strictly less than – sorry
130
00:14:27,270 --> 00:14:31,839
another mistake this is plus 1 of course.
131
00:14:31,839 --> 00:14:39,899
Can it be strictly less than H(n) < 2 times
H(n-1) + 1.
132
00:14:39,899 --> 00:14:43,399
And let us prove that it cannot be.
133
00:14:43,399 --> 00:14:49,260
So, why it cannot be?
134
00:14:49,260 --> 00:14:58,720
So consider an algorithm that moves the n
disks from the first pole to the second pole
135
00:14:58,720 --> 00:14:59,720
right.
136
00:14:59,720 --> 00:15:05,589
Consider the time when the nth disk was moved,
of course at some point of time the last disk
137
00:15:05,589 --> 00:15:10,260
was moved from the first pole to the second
pole.
138
00:15:10,260 --> 00:15:16,830
Now before that move it must have been the
case that this top n-1 must have been moved
139
00:15:16,830 --> 00:15:20,600
from the first pole to the third pole.
140
00:15:20,600 --> 00:15:21,600
Why?
141
00:15:21,600 --> 00:15:30,220
Because when I move the biggest disk from
the first pole to the second pole, the first
142
00:15:30,220 --> 00:15:33,230
pole must have been empty other than that.
143
00:15:33,230 --> 00:15:38,930
And since the biggest disk cannot be placed
on top of the any of the other disks so the
144
00:15:38,930 --> 00:15:42,700
second pole must also have been empty, right.
145
00:15:42,700 --> 00:15:49,570
So the n-1 disks must have been sitting all
of them in the third pole.
146
00:15:49,570 --> 00:15:50,680
Right.
147
00:15:50,680 --> 00:16:00,500
And of course to complete the game after I
move the nth disk to the second pole, the
148
00:16:00,500 --> 00:16:06,180
n-1 disk must have been moved from third pole
to the second pole—third pole to second
149
00:16:06,180 --> 00:16:07,180
pole.
150
00:16:07,180 --> 00:16:16,920
So the number of steps that must have been
made here is H(n-1) and H(n-1) and this one.
151
00:16:16,920 --> 00:16:28,650
So H(n) must have made H(n-1) here, H(n-1)
here and the one move here so it is two times
152
00:16:28,650 --> 00:16:30,910
H(n-1) plus 1.
153
00:16:30,910 --> 00:16:38,570
So in other words for the case is that from
the previous slide and this slide that H(n)
154
00:16:38,570 --> 00:16:44,170
is actually equal to 2 times H(n-1).
155
00:16:44,170 --> 00:16:51,040
So thus for counting the number of steps required
to move n disks I have H(1) equals to 1, I
156
00:16:51,040 --> 00:17:00,700
have H(2) equals to 3 and H(n) equals to 2
times H(n-1) plus 1.
157
00:17:00,700 --> 00:17:08,220
So as you can see here we can clearly write
down here now that okay H(3) equals to 2 times
158
00:17:08,220 --> 00:17:19,670
H(2) + 1 which is 7 number sorry—H(4) is
2 times H(3) plus 1 which is 15; H(5) is 31
159
00:17:19,670 --> 00:17:22,061
and so on and so forth.
160
00:17:22,061 --> 00:17:32,490
So I can keep on doing this same again and
again and get some values.
161
00:17:32,490 --> 00:17:37,560
Question is that is there a nice expression
for H(n).
162
00:17:37,560 --> 00:17:46,350
Or in other words instead of just computing
H(n) in brute force manners like this is there
163
00:17:46,350 --> 00:17:50,860
a way of computing H(n) directly.
164
00:17:50,860 --> 00:18:00,990
So we have seen two examples of how to solve
this counting problem using recurrence relations.
165
00:18:00,990 --> 00:18:07,100
Now there are many other recurrences relations
that appears in real life, of course we have
166
00:18:07,100 --> 00:18:15,750
seen this the one this is the one that we
saw for the case of 0,1 string without any
167
00:18:15,750 --> 00:18:16,830
consecutive zeros.
168
00:18:16,830 --> 00:18:19,530
We also saw this one.
169
00:18:19,530 --> 00:18:27,570
Now if I change the initial conditions, for
example in the first case I have change the
170
00:18:27,570 --> 00:18:33,240
initial condition to something like this F(1)
equals to one, F(2) equals to two, this is
171
00:18:33,240 --> 00:18:37,540
the famous Fibonacci sequence.
172
00:18:37,540 --> 00:18:50,480
Then we have seen slide b(1) equals to 1 and
b(n) equals to b([n over 2]) + 1 which is
173
00:18:50,480 --> 00:19:00,440
something that arises from Binary search is
called it is an algorithm.
174
00:19:00,440 --> 00:19:09,990
We have M(n) equals to 2 times M ([n/2]) +
n this comes from what is called as Merge
175
00:19:09,990 --> 00:19:11,070
sort algorithm.
176
00:19:11,070 --> 00:19:16,530
So, various algorithms produce different types
of such equations.
177
00:19:16,530 --> 00:19:26,860
And the equations that are much more complicated
like this where C (n) is sum of square of
178
00:19:26,860 --> 00:19:34,270
them and these are called Catalan numbers.
179
00:19:34,270 --> 00:19:35,860
Now these are examples of recurrences relations.
180
00:19:35,860 --> 00:19:44,799
Recurrences relations as you can see is where
the nth terms is written as the function of
181
00:19:44,799 --> 00:19:48,770
the previous terms as in this case.
182
00:19:48,770 --> 00:19:54,760
Now there are techniques of solving these
recurrence relations and getting a compact
183
00:19:54,760 --> 00:19:57,450
form for these recurrence relations.
184
00:19:57,450 --> 00:20:05,210
They are essential for not only for counting
but also for algorithms for analysis of algorithms;
185
00:20:05,210 --> 00:20:11,429
for various other subjects of math.
186
00:20:11,429 --> 00:20:19,170
In the next video, we will be looking at techniques
of solving these recurrence relations.
187
00:20:19,170 --> 00:20:20,250
Thank you.