1
00:00:15,990 --> 00:00:32,520
We discuss the form of a other types of parodies
I will you complete that say w discussed the
2
00:00:32,520 --> 00:00:41,989
parodies algorithms I have u have the basic
knowledge of parodies and here we would like
3
00:00:41,989 --> 00:00:58,511
to like to mention about different types of
parodies so the second parodies what we like
4
00:00:58,511 --> 00:00:59,511
to discuss today.
5
00:00:59,511 --> 00:01:06,970
Is greedy method okay now here let issue they
there are n impossible they are n impossible
6
00:01:06,970 --> 00:01:19,670
entity and you want to find out the best solution
using this greedy methods no say you want
7
00:01:19,670 --> 00:01:30,579
it to be select one by one so that you get
the best possible solution for your problem
8
00:01:30,579 --> 00:01:44,380
so initially you have say if I write the algorithm
greedy genetic algorithm or greedy and A and
9
00:01:44,380 --> 00:01:48,399
n parameters then we will be writing that
your solution.
10
00:01:48,399 --> 00:01:55,340
Initially is PI which is null solution and
then you have to select one after another
11
00:01:55,340 --> 00:02:19,680
so for I = 1 to N or n and then x = select
one parameter out of N and we check you check
12
00:02:19,680 --> 00:02:29,170
whether by selecting X you that solution this
will lead to a feasible solution or not if
13
00:02:29,170 --> 00:02:41,310
X leads to feasible solution to a feasible
solution of your problem
14
00:02:41,310 --> 00:02:55,640
solution of the problem then you update your
solution by solution Union X otherwise you
15
00:02:55,640 --> 00:03:07,180
discard else X otherwise.
Which is discarded that means that the X will
16
00:03:07,180 --> 00:03:17,560
not lead to feasible solution okay this is
simple study we follow we follow under the
17
00:03:17,560 --> 00:03:40,900
greedy strategy no one example is large size
and used to store the detail or fight into
18
00:03:40,900 --> 00:03:43,300
this magnetic tapes.
19
00:03:43,300 --> 00:04:02,830
And suppose you have the files f1 f2 and the
site of this file is s1 now we like to store
20
00:04:02,830 --> 00:04:13,320
this 5 into the magnetic tape in such a way
that it takes the minimum amount of time okay
21
00:04:13,320 --> 00:04:28,669
so suppose I have the three files upon f1,f2,f3
and the size of the file is say 20 and or
22
00:04:28,669 --> 00:04:42,300
20,10 and so if I start saving that first
file with the F 2 then F 3 then the total
23
00:04:42,300 --> 00:04:47,699
number of record movements in that magnetic
tape is that.
24
00:04:47,699 --> 00:04:55,590
First time it will be saving to a file f1
of size 20 records and then it will rewind
25
00:04:55,590 --> 00:05:19,520
back so second time you find store the file
f2 record move up to this 1 movements and
26
00:05:19,520 --> 00:05:37,969
the total number of recommend becomes now
if I think the other way that no I understood
27
00:05:37,969 --> 00:05:45,029
first F 2 then F 1 then if 3 what happens
first time 10 second times.
28
00:05:45,029 --> 00:06:00,180
It is 10 and then 20 so this becomes 30 and
then third time this 40 and then 50 so this
29
00:06:00,180 --> 00:06:11,139
gives you 45 of the movements okay the total
number of movements that means 10 plus 30
30
00:06:11,139 --> 00:06:16,240
plus 45 this gives you 95 okay now if I take
the other way then store first f2 and then
31
00:06:16,240 --> 00:06:25,520
f1 then f3 what happens first time 10 second
time 16 and then 20 this became 30 and then
32
00:06:25,520 --> 00:06:26,669
third time last 15 so this gives you 45 okay
that means 10+30+45 this gives you 85 of the
33
00:06:26,669 --> 00:06:27,669
movement record movements.
34
00:06:27,669 --> 00:06:29,669
Now what happens if I save the files in the
form F 2, F 3 and then F 1 what happens first
35
00:06:29,669 --> 00:06:36,229
F 2 which is the 10 next time it is 10 plus
15 it is purified and then next time it is
36
00:06:36,229 --> 00:06:50,060
45 so it becomes 10 plus 25 plus 45 it becomes
80 okay and this is the minimum number of
37
00:06:50,060 --> 00:06:57,319
record the records to remove to store all
these three files into the magnetic tape so
38
00:06:57,319 --> 00:07:03,689
what is the strategy follow here then you
have files upon it to happen.
39
00:07:03,689 --> 00:07:13,749
And with the side this one is 2s and respectively
the X initially solution is 5 and for I equals
40
00:07:13,749 --> 00:07:25,210
to 1 to N and now you will be selecting X
for from the set of n you will be selecting
41
00:07:25,210 --> 00:07:31,949
the pie which is inside okay so s1 is the
solution and is it fully super yes it will
42
00:07:31,949 --> 00:07:40,389
lead to the solution so you are sold storing
and your solution so s1 becomes all Union
43
00:07:40,389 --> 00:07:57,080
X 1 X 1 you get the next smallest one and
add it and so on okay.
44
00:07:57,080 --> 00:08:05,319
So this is the word strategy this is the greedy
method to solve the problem of storing the
45
00:08:05,319 --> 00:08:13,139
files into the magnetic now the next problem
is well known to you which is knapsack problem
46
00:08:13,139 --> 00:08:19,539
okay do you know what is knapsack problem
right.
47
00:08:19,539 --> 00:08:29,039
Let me tell you what is the knapsack problem
let us issue that you have that n in pts X
48
00:08:29,039 --> 00:08:46,190
1 X 2 X 3 x n and to select X I you are the
Profit PR okay so you have the Prophet P 1
49
00:08:46,190 --> 00:08:56,579
P 2 P 3 P 2 select P I you earn the profit
P I to select excite you want the profit P
50
00:08:56,579 --> 00:09:05,980
I and each entity has certain weight say W
1 is the way that has 2 X 1 weight XT and
51
00:09:05,980 --> 00:09:20,880
now there is exist a bit of capacity have
been capacity of the problem is to select
52
00:09:20,880 --> 00:09:31,670
to select sum of excess and put them into
this big whose capacities in such that you
53
00:09:31,670 --> 00:09:39,000
are not the maximum profit okay.
So what is the problem is to select some of
54
00:09:39,000 --> 00:09:46,351
the excess and put them into the capacity
bin of capacity M in such a way that you are
55
00:09:46,351 --> 00:09:57,130
earn the maximum profit right so basic problem
is that if I sell the w3 weight or the W I
56
00:09:57,130 --> 00:10:05,310
weights of item of X I then I are the profit
P I and I want to maximize my profit but with
57
00:10:05,310 --> 00:10:11,630
the condition is that that my being can take
up to the load of unit.
58
00:10:11,630 --> 00:10:20,829
Now one thing should be clear to you that
mean been if it is not full then I should
59
00:10:20,829 --> 00:10:31,570
take some more items from here to get into
the beam so that I am more profits so I can
60
00:10:31,570 --> 00:10:50,440
write that maximize this problem I can write
maximize P I , X I is equal to 1 to n such
61
00:10:50,440 --> 00:11:02,340
that or subject to the condition subject to
the condition summation over the WI X I is
62
00:11:02,340 --> 00:11:19,259
1 to N is less than equal to M and X I is
lying between 0 & 1and weights are positive
63
00:11:19,259 --> 00:11:26,389
right so what happens the problem is that
I have X 1 , X 2 X n are the entities the
64
00:11:26,389 --> 00:11:34,060
WI is the weight let us to exile and PI is
the profit attached to the item X I.
65
00:11:34,060 --> 00:11:42,180
And you have a beam of capacity M you want
to select some of the excise such that your
66
00:11:42,180 --> 00:11:48,709
bean is full and also you want the maximum
profit so the problem can be redefined maximize
67
00:11:48,709 --> 00:11:55,959
summation P I, X I, X I equal to 0 I equal
to 1 to N subject to the condition that summation
68
00:11:55,959 --> 00:12:02,489
over to W IX I less than equals to M and X
is 0 and 1 what does it mean XI like by 0
69
00:12:02,489 --> 00:12:08,681
& 1 that it is 0 if you do not select if it
is 1 you select the whole item.
70
00:12:08,681 --> 00:12:17,950
Whole item means that you select the W I weight
total right or you can select you can select
71
00:12:17,950 --> 00:12:29,220
small amount of WI of the X I called X I is
component what I can and now how to solve
72
00:12:29,220 --> 00:12:30,569
this problem.
73
00:12:30,569 --> 00:12:40,940
So let us consider one small example so I
have three items item 1 item 2 and item 3
74
00:12:40,940 --> 00:12:51,410
and the item weight is 1 is having the weight
5 this weight is having 10 and this half wait
75
00:12:51,410 --> 00:13:08,829
is having say four and I are not the profit
is say 10 here it can be 15 and it can be
76
00:13:08,829 --> 00:13:29,709
eight seven six it can be 7 okay so this is
your weight and this is your profit so that
77
00:13:29,709 --> 00:13:36,480
means that.
If I sell 5k unit of item one I am the profit
78
00:13:36,480 --> 00:13:51,730
10 can and if I sell ten unit of I have to
15 the profit of 7 I know I want to and I
79
00:13:51,730 --> 00:14:09,019
have a capacity of say now how to select this
a unit of yes like one possible thing that
80
00:14:09,019 --> 00:14:26,670
I select item one completely and three unit
from item two that means 5 ,3 & 0 another
81
00:14:26,670 --> 00:14:37,000
one can be 2,6 and 6, 8, 2, 4, 2 may be one
possibility.
82
00:14:37,000 --> 00:14:50,149
There are another possibility could be 3,
3, 2 and so on if it is the case then how
83
00:14:50,149 --> 00:14:58,819
much I earn the profit or what is the profit
amount so I earn 5 so I earn 10 and then I3
84
00:14:58,819 --> 00:15:15,069
that is 15 divided by 8 into 3 okay so this
gives you so 14.5 now in this case 10 divided
85
00:15:15,069 --> 00:15:46,439
by 5 into 2 + 15 divided by 10 into 4 + 7
divided by 4 into 2 so this is one 4 + 1 +
86
00:15:46,439 --> 00:16:12,139
3.5 and 14.5 + 14 and so on.
So
87
00:16:12,139 --> 00:16:24,791
you observe then your this gives the better
profit among them but how do how to select
88
00:16:24,791 --> 00:16:32,660
what should be the best possible way to select
or wait so that so that your deal is 4 and
89
00:16:32,660 --> 00:16:39,870
all the maximum profit so one possibility
that because here you observe that we have
90
00:16:39,870 --> 00:16:46,939
considered that weight as a factor weight
is related with my profit so I should obtain
91
00:16:46,939 --> 00:16:49,149
what is the profit.
92
00:16:49,149 --> 00:17:11,870
Let us find out that is P by W so it is 2
it is 1.5 and this is this is 1.75 okay so
93
00:17:11,870 --> 00:17:24,949
if I that means that I must there I must put
as much as I can from the I came one into
94
00:17:24,949 --> 00:17:31,670
my base okay and because I am getting per
unit profit is maximum on item one and if
95
00:17:31,670 --> 00:17:42,049
it is the case if it is the case so I will
take five unit five unit of item1 one then
96
00:17:42,049 --> 00:17:47,560
next item is coming this one this gives the
power read profit is maximum.
97
00:17:47,560 --> 00:17:56,490
So what I should do I should take two unit
directly from here oh yes so that I will doing
98
00:17:56,490 --> 00:18:02,870
unit from here so that you get the maximum
profit so if it is your selection is like
99
00:18:02,870 --> 00:18:20,860
that then are you armed profit 10+0+25 so
you want the profit 15. 25 which is the maximum
100
00:18:20,860 --> 00:18:25,150
profit you can earn so in terms of in terms
of general in terms.
101
00:18:25,150 --> 00:18:31,690
If I consider the generalized problem that
you have P 1, P 2 , P n is perfect with the
102
00:18:31,690 --> 00:18:41,390
first look item yeah I you have the weight
WI then the section percentage you first obtained
103
00:18:41,390 --> 00:18:48,440
the per unit profit for each Item and after
planning the power you prefer then you select
104
00:18:48,440 --> 00:19:02,409
first done unit having the maximum profit
as you can into the B now after putting that
105
00:19:02,409 --> 00:19:09,120
maximum profit here you get the next highest
profit one and try to put as much as you can
106
00:19:09,120 --> 00:19:22,820
into the B and so on finally you get some
fraction some section to put here.
107
00:19:22,820 --> 00:19:30,630
And if I add this will be getting the maximum
profit so that is the greedy strategy for
108
00:19:30,630 --> 00:19:38,010
finding the knapsack problem finding of for
solving the knapsack problem now let us consider
109
00:19:38,010 --> 00:19:47,190
the another interesting problem that is optimization
patterns.
110
00:19:47,190 --> 00:20:08,020
Now what is the problem here probably is that
suppose I have files f 1 ,F 2, F 3, F n and
111
00:20:08,020 --> 00:20:25,799
the size is s 1 is s2 is s3 SN so you have
N files and file as the size or as the records
112
00:20:25,799 --> 00:20:37,210
number are know the problem move on to marge
all these files and you do to make people
113
00:20:37,210 --> 00:20:45,530
1 5 now you observe if the last class we discussed
about the merging of two files then there
114
00:20:45,530 --> 00:20:54,090
is a need of data to that from one point to
another file.
115
00:20:54,090 --> 00:21:02,390
So if I have a file A and you have another
file B and you want to mark you want to marge
116
00:21:02,390 --> 00:21:11,620
this to file support this is of sizes N this
is size m and first what you do first you
117
00:21:11,620 --> 00:21:25,760
do what you do that this you need n + m record
to this bands from for marking these two parts
118
00:21:25,760 --> 00:21:26,760
okay.
119
00:21:26,760 --> 00:21:36,650
So for this case also that how I if I budget
file with F 2 then I need s 1 + s 2 or the
120
00:21:36,650 --> 00:21:43,670
record movements and then if I take this one
then you need again a s1 +s2 + SN and a record
121
00:21:43,670 --> 00:21:50,990
book and so on and you know well that you
know our target should be such or our problem
122
00:21:50,990 --> 00:21:55,429
should be like that that you watch these files
into one file.
123
00:21:55,429 --> 00:22:03,669
In such a way that number of records who paid
is minimum this minimum there one way could
124
00:22:03,669 --> 00:22:12,390
be that you first merge these two then you
merge item with this one with this one and
125
00:22:12,390 --> 00:22:17,490
then marge item to this one them with this
one and so on right then another way could
126
00:22:17,490 --> 00:22:22,289
be that you might these two this to and this
to and this to then marge with this one with
127
00:22:22,289 --> 00:22:29,730
this one and so on there are several ways
you can Marge you can merge this n files right
128
00:22:29,730 --> 00:22:31,380
you know to understand the problem say.
129
00:22:31,380 --> 00:22:44,990
Let us assume that I have five files F1, f2,
f3, f4, and f5 and sign of the files could
130
00:22:44,990 --> 00:23:04,510
be 5, 10, 20, 15, 30 so if I marge for this
one there is this one and then marge this
131
00:23:04,510 --> 00:23:11,840
files and then large this whole file and the
length and how many record movements here
132
00:23:11,840 --> 00:23:22,610
to merge this two files you need 25 record
movement to more this again 25 now to marge
133
00:23:22,610 --> 00:23:30,140
this two you need to marge and to merge will
be 80 so the total number of 25+50+80+25 it
134
00:23:30,140 --> 00:23:32,460
is 180.
135
00:23:32,460 --> 00:23:57,630
Now let us think about the other way you have
10, 15, 5, 20, 30 and suppose I Marge this
136
00:23:57,630 --> 00:24:05,510
one first then this one then this one and
then finally this one in that case here 2
137
00:24:05,510 --> 00:24:13,789
to 5 record movements and here 30 record movements
here 50 record movements and here 80 more
138
00:24:13,789 --> 00:24:26,590
movements in that case total becomes 25 +
30 + 50 + 80 so you get 185 record movements
139
00:24:26,590 --> 00:24:30,299
under 185 is it okay.
140
00:24:30,299 --> 00:24:40,690
Now what happens file first Marge this two
then the marge item is merged with this one
141
00:24:40,690 --> 00:24:55,580
then whole thing is marge this one and finally
marge this in that case we are it is 15+ 15
142
00:24:55,580 --> 00:25:14,840
+ 15 +30 and here in this so now what record
movement becomes 15+ 30 50+80 it becomes 175
143
00:25:14,840 --> 00:25:40,429
now can you tell me what is the best way to
do it yes what you have to do is they you
144
00:25:40,429 --> 00:25:46,539
first try to get.
The file with the smallest size and you try
145
00:25:46,539 --> 00:25:51,250
to monitor then you select against values
the smallest ones and if I do what except
146
00:25:51,250 --> 00:26:03,710
for example suppose this is instead of 15
it is 25 okay.
147
00:26:03,710 --> 00:26:16,570
In that case you still marge this one this
one you should have merge then it becoming
148
00:26:16,570 --> 00:26:25,019
size becoming 35 now that this file this file
and this final move this three two are the
149
00:26:25,019 --> 00:26:35,039
smallest one this one is honest one so which
side becomes 55 and then u marge okay so basically
150
00:26:35,039 --> 00:26:39,610
I finally present inform of the top of tree.
151
00:26:39,610 --> 00:26:52,019
So what I will do I will be putting first
five and I Marge with the 10 I get 15 and
152
00:26:52,019 --> 00:27:23,159
then I get 20 you get 35 and then this side
you get 25 and 30 you get 55 you get 90 okay
153
00:27:23,159 --> 00:27:34,240
so the number of record movements will be
three times of five three times okay because
154
00:27:34,240 --> 00:27:46,700
five has to move up to this so three times
of five + three times of 10 + 20 into 2 times
155
00:27:46,700 --> 00:28:01,850
+25 into 2 + 30 into 2 okay.
So the effect is 15 +30 + 40 + 50 + 60 this
156
00:28:01,850 --> 00:28:15,789
gives you 150 that give 195 okay so that is
the way you can solve this so what you have
157
00:28:15,789 --> 00:28:24,780
done here what you first thing is that you
have big two files with the smallest smaller
158
00:28:24,780 --> 00:28:33,470
in size at the bottom most level and then
you merge them and you fix up the two smallest
159
00:28:33,470 --> 00:28:40,480
five merge them and so on okay.
160
00:28:40,480 --> 00:28:51,010
So formula becomes DI into WI where WI is
the WI is the number of Records in the Phi
161
00:28:51,010 --> 00:29:01,690
I f5 and di is the distance of the record
from the root so the next type of problem
162
00:29:01,690 --> 00:29:17,190
which we can consult agree matters is finding
the minimum spanning tree okay.
163
00:29:17,190 --> 00:29:47,169
Suppose GB that graph wait graph
it just say okay this is the weighted graph
164
00:29:47,169 --> 00:30:11,970
you have and you want to obtain the key from
this weighted graph okay and first thing is
165
00:30:11,970 --> 00:30:18,769
that if I forget about this I am looking for
the spanning tree then from this tree from
166
00:30:18,769 --> 00:30:26,809
the graph you have to find out the tree with
n minus 1 edges and n minus 1 edges that will
167
00:30:26,809 --> 00:30:37,130
give you the spanning tree so for this graph
one spanning tree could be this one okay.
168
00:30:37,130 --> 00:30:55,059
So this is 10, 5, 8 another span tree could
be this one which is weight is 10, 7, 5 another
169
00:30:55,059 --> 00:31:16,490
spinning tree would be five seven and eight
oh sorry it is not seven it is 12 the cost
170
00:31:16,490 --> 00:31:38,169
of the sum of this trees the spanning tree
having the minimal cost it is the minimal
171
00:31:38,169 --> 00:31:54,799
spanning tree so two algorithm is exist one
of the arrow and another one is spanning tree.
172
00:31:54,799 --> 00:32:05,850
So let us discuss the kuslals algorithm and
let g of v and e of edges and let the show
173
00:32:05,850 --> 00:32:17,380
is number of vertices is n and WI or weight
is assigned the WI is weight assign to age
174
00:32:17,380 --> 00:32:31,779
between VI and V W IJ is the way assign VIN
and VIJ now since I have to obtain tree and
175
00:32:31,779 --> 00:32:47,820
we have to find it obtained a possible tree
walk having the number of pages never resist
176
00:32:47,820 --> 00:33:02,940
as n minus 1 as n minus 1 now initially this
we will edges will release it is already in
177
00:33:02,940 --> 00:33:12,390
increasing order with respect to the weights
right edges are arranged in the order of in
178
00:33:12,390 --> 00:33:21,639
the increasing order of weights okay now the
algorithm this will be like that while the
179
00:33:21,639 --> 00:33:44,140
number of edges.
There are in the tree is < n-1and e is not
180
00:33:44,140 --> 00:34:02,380
empty okay t is number of element number of
edges that A is < not n - 1 and E is got empty
181
00:34:02,380 --> 00:34:36,270
select second edge using E having the minimum
cast and from E having okay now you see after
182
00:34:36,270 --> 00:34:44,220
selecting this UV you have to see and I put
it in my treaty you what it means that if
183
00:34:44,220 --> 00:34:51,929
I put it in my treaty you should not eat a
cycle okay that is the thing you have to say
184
00:34:51,929 --> 00:35:20,770
so
the check when you yes then you cannot consider
185
00:35:20,770 --> 00:35:40,530
UV for your panic for your minimum spanning
tree you just discard U is form E else at
186
00:35:40,530 --> 00:36:05,770
T V x U, B delete x U,V form E. So that is
your algorithm.
187
00:36:05,770 --> 00:36:16,980
So what it does initially tea is fine while
number of pages with -1 and he is not empty
188
00:36:16,980 --> 00:36:28,060
he is not a pre-selected age UV from he and
then you see if I add this one here in P you
189
00:36:28,060 --> 00:36:37,349
should not create a cycle if it creates cycle
then you discard you be from e and otherwise
190
00:36:37,349 --> 00:36:43,609
you E into the tree and then delete you be
from E know after coming from this while loop
191
00:36:43,609 --> 00:36:53,280
you check with a number of edges even is N
- 1 you have get the minimum spanning tree
192
00:36:53,280 --> 00:37:05,440
so that is the couscous algorithm is dynamic
Programme.
193
00:37:05,440 --> 00:37:13,550
This is also one of the most well known paradigms
being used in different places one simple
194
00:37:13,550 --> 00:37:26,060
one is that finding the all pair shortest
path problem and facility is like that suppose
195
00:37:26,060 --> 00:37:35,230
you have a graph with it runs G and you want
to find the old pair of shortest paths what
196
00:37:35,230 --> 00:37:46,830
do you do that given the cost matrix or weighted
with metric there you see the confusion it
197
00:37:46,830 --> 00:37:54,450
move with the kids whether your cost or part
becomes shorter or not if it is shorter you
198
00:37:54,450 --> 00:38:02,520
consider that the strategy is very simple
that suppose you have I at any state of J
199
00:38:02,520 --> 00:38:18,970
you have the shortest paths you have the paths
or two spots by a via some nodes by some 1
200
00:38:18,970 --> 00:38:24,420
to K - 1 now by.
If you have that the case stage what we do
201
00:38:24,420 --> 00:38:39,069
that we like to introduce the node K and you
check the path with weight of the path from
202
00:38:39,069 --> 00:38:47,890
I to K and K 2 J if you find the sum of this
weight is less than the original weight whatever
203
00:38:47,890 --> 00:38:57,490
you obtain from i to j then instead of using
this path this path you now use this pot ok
204
00:38:57,490 --> 00:39:06,339
that is the idea so dynamically you are updating
your shortest paths suppose you have you know
205
00:39:06,339 --> 00:39:08,839
to write this algorithm suppose.
206
00:39:08,839 --> 00:39:24,441
CIJ is the weight of weight of post of A I
J Now I do not want to type this one so I
207
00:39:24,441 --> 00:39:43,980
write for I = 1 to N J 1 to N. A x I, j = C
x I , j and we the idea my tricks for or what
208
00:39:43,980 --> 00:40:08,339
I am pursuing whatever the shortest path I
have using the party says one two three of
209
00:40:08,339 --> 00:40:27,890
the T -1 right and I have the shortest path
from I to K using the what is a 1 to K - 1
210
00:40:27,890 --> 00:40:42,569
+ the shortest path using the what it says
ok but it between KN E using what is a 1 to
211
00:40:42,569 --> 00:40:54,650
K -1 and that will be dictated by the place
ok this is the one thing and similar type
212
00:40:54,650 --> 00:41:03,460
of program is the Traveling Salesman problem
which you can solve using the binary this
213
00:41:03,460 --> 00:41:12,849
is a dynamic programming. Another problem
is programs generally we saw using optimal
214
00:41:12,849 --> 00:41:22,859
binary search here.
215
00:41:22,859 --> 00:41:38,010
What happened the problem is that suppose
you have the several identifiers several and
216
00:41:38,010 --> 00:41:48,290
if I did say id1, id2 , and id3 is an identifier
and you know this is a point we like to search
217
00:41:48,290 --> 00:42:00,500
several time for example in the case of compiler
you have Saturday the equal one and you have
218
00:42:00,500 --> 00:42:11,050
became suppose if one know I want to check
for the deep body the night not so you we
219
00:42:11,050 --> 00:42:19,220
will be searching it right say for example
I have if, another one is then, another one
220
00:42:19,220 --> 00:42:31,020
is end, another one is while right.
Say and another one is white like say I have
221
00:42:31,020 --> 00:42:39,650
this four identifiers so I can arrange this
or put them in a poem of energy say for example
222
00:42:39,650 --> 00:42:55,609
if I write it is the easy part first and this
side and this side it may be why
223
00:42:55,609 --> 00:43:03,579
another one could be another one could be
you know I want to put here then this side
224
00:43:03,579 --> 00:43:17,339
it is end , again this side is if, and this
site is in Y. Other way I can put it is that
225
00:43:17,339 --> 00:43:42,339
it can be said then on this side it is if,
there are several other ways you can have
226
00:43:42,339 --> 00:43:50,040
your know suppose I want to check their weather
effects if one exists.
227
00:43:50,040 --> 00:43:55,530
So what I will do is search here now I will
come here if now I will be looking with a
228
00:43:55,530 --> 00:44:03,886
exist anything or not if it is not then
you tell that is not there now similarly is
229
00:44:03,886 --> 00:44:08,820
the case to it suppose while exist or not
well no you come here and he has to exist
230
00:44:08,820 --> 00:44:23,940
and it is become the successful search so
there is a question of coming the number of
231
00:44:23,940 --> 00:44:35,170
companions you will be performing to find
out with it now for this case for this case
232
00:44:35,170 --> 00:44:45,290
if it is a successful search then every number
of comparison is required for then is one
233
00:44:45,290 --> 00:44:53,350
for if it is two comparisons.
For n three comparisons and Y is two comparisons
234
00:44:53,350 --> 00:45:02,220
so this is 6 plus 6 plus 5 is 11, 11 number
divided by 4 so that is your average number
235
00:45:02,220 --> 00:45:21,740
of them okay but for this case it is also
1 2 + 2 Plus 3 and it becomes 5 + 3 8, 8 divided
236
00:45:21,740 --> 00:45:31,690
by 4 okay so this is that you I assume that
they are equally likely then for successful
237
00:45:31,690 --> 00:45:40,700
size it becomes 2.75 average number of comparisons
in this case it is 2 and in that case also
238
00:45:40,700 --> 00:45:49,240
it will become the 2.75 and so on so our target
should be should draw a the tree in such a
239
00:45:49,240 --> 00:45:52,059
way that there ever is number component is
minimum.
240
00:45:52,059 --> 00:46:02,390
Now they here we assume that also we assume
that that it is only this full size but what
241
00:46:02,390 --> 00:46:10,130
happens in here suppose I go for F 1 then
it becomes a failure 1 right so a little not
242
00:46:10,130 --> 00:46:20,200
only that we are issuing that equally likely
which is not correct because so one part is
243
00:46:20,200 --> 00:46:28,210
that the question is coming the fourth identifier
id-1 the probability of successful sod is
244
00:46:28,210 --> 00:46:36,349
P I and there will be you observed that if
I have the poor and identified then there
245
00:46:36,349 --> 00:46:44,984
will be L +1 failure such that that if I have
one item say do you go and in that case you
246
00:46:44,984 --> 00:46:48,319
come here.
Because it does not exist so it becomes a
247
00:46:48,319 --> 00:47:03,730
failure size so there will be Q 0, Q 1, Q
n. W ant and Q is and that many that these
248
00:47:03,730 --> 00:47:10,910
are the probabilities for probabilities for
unsuccessful sighs huh the piece this will
249
00:47:10,910 --> 00:47:16,300
lead to this class of identified this will
lead to decide this unsuccessful search leads
250
00:47:16,300 --> 00:47:41,770
to this class of attempts and so on right
so such that summation of Y and Q 0 Q 1 Q
251
00:47:41,770 --> 00:47:57,579
2 Q and the probability for unsuccessful searches
then you have u 0 + summation over P I know
252
00:47:57,579 --> 00:48:05,700
what is your problem no problem is they you
have to put the identifiers in such a way
253
00:48:05,700 --> 00:48:15,079
that in such a way that
the cause.
254
00:48:15,079 --> 00:48:23,950
Is being washed miss that if I put I hate
identified in the level T then T I then so
255
00:48:23,950 --> 00:48:42,349
this can be solved in using dynamic programming
now the next
256
00:48:42,349 --> 00:48:55,240
type of problem parents much on this suspect
but what I want to tell that the one problem
257
00:48:55,240 --> 00:49:12,550
is that by one color and then they go to the
next products and to put the color another
258
00:49:12,550 --> 00:49:19,630
type of ballet and you check that if by putting
the color it fails to satisfy the criteria
259
00:49:19,630 --> 00:49:36,700
recovery color II just put different type
of color so there is one example of back n
260
00:49:36,700 --> 00:49:48,060
queen problems that the problem is to put
them in such a way that nuke we attack the
261
00:49:48,060 --> 00:49:54,700
other preach for example I have a chessboard.
262
00:49:54,700 --> 00:50:12,760
Of 4 + 4 and I have the four Queens Q1, Q2,
Q3, Q4 okay so I have two queens are diagonally
263
00:50:12,760 --> 00:50:23,490
or if I place them binocularly or for this
I want to put this foot prints in such a way
264
00:50:23,490 --> 00:50:28,200
they are not on the same diagonal not on the
same calm. So I put Q1 here Q2 cannot be put
265
00:50:28,200 --> 00:50:29,200
here I can put to here. Once I put Q2 here
were shall I could think I cannot put here
266
00:50:29,200 --> 00:50:36,049
okay. And not on the same color so if I put
you one here you two cannot be put here if
267
00:50:36,049 --> 00:50:41,069
you can it will put the eternal to put here
can be put here so I can put I cannot put
268
00:50:41,069 --> 00:50:48,010
you two here I can put you two here okay.
Once I put the cue tube here where should
269
00:50:48,010 --> 00:50:56,020
I put Q 3 I cannot put here okay I cannot
put here I cannot put here I cannot and out
270
00:50:56,020 --> 00:51:02,270
I cannot put here I cannot put here I cannot
put here I cannot put here I cannot put here
271
00:51:02,270 --> 00:51:11,510
once I cannot put here Q 2 Q 3 and so what
shall I do so with the age of 4 to simplify
272
00:51:11,510 --> 00:51:21,140
the redemption a little issue that you I is
beta the idea Rho Q is played in the eye a
273
00:51:21,140 --> 00:51:27,750
TRO okay so you three should be placed here
now once I know that Q 3 position it cannot
274
00:51:27,750 --> 00:51:31,630
be this one cannot be this one cannot be this
one Ellen with this hand.
275
00:51:31,630 --> 00:51:41,230
What shall I do i back can now I try to put
the position of Q 2 so can it be here let
276
00:51:41,230 --> 00:51:47,859
us assume hat Q 2 is here now what happens
Q 3 cannot be here you see yes you see can
277
00:51:47,859 --> 00:51:55,780
be here so I put Q 3 right because it is not
attacking by Q 1 retargeting by Q 2 now what
278
00:51:55,780 --> 00:52:03,490
happens where should I put where can I put
my q4 can I put q4 here no you for low you
279
00:52:03,490 --> 00:52:12,640
for no you put here you know what should I
do now you back tech can I put Q 3 here no
280
00:52:12,640 --> 00:52:22,950
can I put q3 here no now can I put Q to do
is gone so I have to put Q 1 in different
281
00:52:22,950 --> 00:52:29,990
places so I should put everyone here now if
I put Q in here.
282
00:52:29,990 --> 00:52:36,960
Whatever where shall I put q2 I cannot put
here I tell now if it is the case where can
283
00:52:36,960 --> 00:52:48,780
I put q3 you say I can put it here if I put
q3 here you for I can put here so you observe
284
00:52:48,780 --> 00:52:56,460
that you get a solution where that loop we
is attacking each other now there may be several
285
00:52:56,460 --> 00:53:02,710
it is not the unique solution you may have
the different were also different ways to
286
00:53:02,710 --> 00:53:11,190
put these values per Q is in the teleport
to get the solution okay so this is all about
287
00:53:11,190 --> 00:53:21,819
the backtracking similarly you can solve you
can find out the branch and bound or discussed
288
00:53:21,819 --> 00:53:29,609
in the traversal.
289
00:53:29,609 --> 00:53:46,040
We need to know for our to test I know the
first problem is that suppose I have a binary
290
00:53:46,040 --> 00:53:55,020
tree and I want to traverse this binary tree
how we can traverse now we tell this is the
291
00:53:55,020 --> 00:54:03,660
root and you have the left sub tree and you
have the right now you know to traverse this
292
00:54:03,660 --> 00:54:12,720
by nature we can knows there are several ways
you can traverse one way it could be that
293
00:54:12,720 --> 00:54:20,549
I Traverse first root then left sub tree then
write something and recursively I go further
294
00:54:20,549 --> 00:54:24,520
for the left sub tree root left right and
so on another.
295
00:54:24,520 --> 00:54:30,720
One could be root right sub tree left sub
tree another one could be left sub tree root
296
00:54:30,720 --> 00:54:38,380
right sub tree another one could be like sub
tree root left sub tree another one could
297
00:54:38,380 --> 00:54:45,060
be left sub tree right sub tree root or right
sub kids left side screech these are the six
298
00:54:45,060 --> 00:54:52,480
possible ways you can traverse a binary tree
now see this is basically the mirror of this
299
00:54:52,480 --> 00:55:02,819
so generally we do not consider this so basically
we have the three ways to traverse a binary
300
00:55:02,819 --> 00:55:09,440
tree one is the root first then writes a left
subfield the right sub tree another one is
301
00:55:09,440 --> 00:55:19,170
the left of the left sub tree root right.
So for example if I have, A, B, C, D, E, F,
302
00:55:19,170 --> 00:55:22,440
G, H, R, L now this known has pre order this
is known has In order and this is known has
303
00:55:22,440 --> 00:55:26,430
post order so we Traverse.
304
00:55:26,430 --> 00:55:55,700
In preorder is first then left of this one
B is then less subtract then G then H that
305
00:55:55,700 --> 00:55:58,900
scale then K then C and then F Then the Suppose
you have this binary no these papers is known
306
00:55:58,900 --> 00:56:19,960
as reorder traversing this is known as in
alright and this is known as so if I Traverse
307
00:56:19,960 --> 00:56:32,099
pre-order using the pre-order traversal then
Prior a tells the route fast then left sub-tree
308
00:56:32,099 --> 00:56:45,221
they are like okay this one so if I have Travers
that is B is then left sub-tree d then G then
309
00:56:45,221 --> 00:57:05,120
e then each there is else then k then C and
then now if I Traverse him over the first
310
00:57:05,120 --> 00:57:09,059
is left sub tree.
Then route except tree now you have come here
311
00:57:09,059 --> 00:57:14,410
first is left sub tree then route their eyes
happy now you have first left sub tree then
312
00:57:14,410 --> 00:57:49,819
route so it becomes that g-d be then each
L, E, K, E C and if I Traverse post for that
313
00:57:49,819 --> 00:57:59,599
then left sub tree right sub tree and then
roof now left sub tree right sub tree then
314
00:57:59,599 --> 00:58:13,079
left sub tree right sub tree so G the right
sub tree
315
00:58:13,079 --> 00:58:35,369
right sub tree is l8 k e b yep see so I think
this you remember we discuss all these things
316
00:58:35,369 --> 00:58:51,089
in your undergraduate curricula and you know
I can generate the pilot T but this is not
317
00:58:51,089 --> 00:58:59,250
the case okay.
You know to see that suppose I know that pre-order
318
00:58:59,250 --> 00:59:14,250
and in order let us see how we can't generate
the binary tree see from the pre-order I can
319
00:59:14,250 --> 00:59:22,470
get the who is the root of this node which
is a now from the in order I can find out
320
00:59:22,470 --> 00:59:31,190
I can find out that what are the elements
in the left sub tree and what are the elements
321
00:59:31,190 --> 00:59:37,730
in the right sub tree so this gives you that
this match is on the left sub tree this match
322
00:59:37,730 --> 00:59:45,650
is on the right sub tree know from pre-order
again i can find out who is the rope which
323
00:59:45,650 --> 00:59:47,690
is being again from here.
324
00:59:47,690 --> 00:59:56,339
I can find out this is the left sub tree and
this is the right sub tree of B so GD is here
325
00:59:56,339 --> 01:00:11,880
and this is here now from the DG Genie I get
B so I know the D and G is B is the root and
326
01:00:11,880 --> 01:00:28,839
from here you get the G the left of B so it
is yeah now once you know be so I have done
327
01:00:28,839 --> 01:00:38,849
this one I have done this one, this one, this
one, now I have this part is the row so I
328
01:00:38,849 --> 01:00:48,980
write here once I know the E is here a channel
is the left sub tree of he a channel so H
329
01:00:48,980 --> 01:01:07,960
is the roof and L is the right sub tree
and E k E k E is the right of e softly let
330
01:01:07,960 --> 01:01:18,120
me you have C N FC is the root and F is the
right point is e so similarly if I have the
331
01:01:18,120 --> 01:01:23,819
pre-order and you have if I have the post
order in your I can generate the binary uniquely.
332
01:01:23,819 --> 01:01:37,329
But in the case if I have the preorder and
post order I am in problem I know
333
01:01:37,329 --> 01:01:45,530
that from the so as the result you can draw
the conclusion okay now the next one is let
334
01:01:45,530 --> 01:01:48,960
us ever say that gum if I complete this one
then you are the preliminary of algorithms
335
01:01:48,960 --> 01:02:02,980
parties over so that we can go for so there
are two ways we can traverse the graph one
336
01:02:02,980 --> 01:02:23,520
is known as red phosphorus. So ways you can
travel the draw known has breadth first search
337
01:02:23,520 --> 01:02:33,200
(BFS). Another one is Depth first search (SFS).
338
01:02:33,200 --> 01:02:47,970
That suppose you have a graph
339
01:02:47,970 --> 01:02:56,440
suppose you have a graph and what I it does
that one is that you first good select this
340
01:02:56,440 --> 01:03:04,660
for visit this thought and then you visit
always adjacent always change and such then
341
01:03:04,660 --> 01:03:11,070
for each adjust and then you go to the next
one and so on so it is that level wise this
342
01:03:11,070 --> 01:03:17,310
again you are subject the other they go you
first search it come to this let me come to
343
01:03:17,310 --> 01:03:23,150
this come to this then you finish this.
One then if you need this one this is known
344
01:03:23,150 --> 01:03:31,640
as the first time oh alright then good enough
for friend first are say you can write BFS
345
01:03:31,640 --> 01:03:34,650
and V is,
346
01:03:34,650 --> 01:03:59,569
The starting node then visited V is one and
I write u equals to V now for all body cells
347
01:03:59,569 --> 01:04:48,589
and also in this light for all vertices you
and Justin if visited W zero that is not yet
348
01:04:48,589 --> 01:06:02,290
visited okay so this comes under follow and
if Q is not empty not empty really and repeat
349
01:06:02,290 --> 01:06:17,640
and repeat this so what it does basically
for all what is W adjusted from you do the
350
01:06:17,640 --> 01:06:29,049
following. If visited W is not in digital
than you and you repeat this thing for all
351
01:06:29,049 --> 01:06:35,140
adjuster notices that is the same level things
and if find that Q is not empty.
352
01:06:35,140 --> 01:06:45,779
You take one delete one element from Q from
the top and repeat this process because you
353
01:06:45,779 --> 01:06:54,130
have to find out W and so on but in the case
of death pause in the case of a pass the idea
354
01:06:54,130 --> 01:07:01,569
is little you have to go into the depth of
the graph and the algorithm becomes different
355
01:07:01,569 --> 01:07:34,309
little different DFS you and visited algorithm
becomes like that and for all what he says
356
01:07:34,309 --> 01:08:05,680
the following if visited V visited W is = to
0 then DFS check. What we are doing that you
357
01:08:05,680 --> 01:08:11,060
check with the visited DFS V there visited
V is 1.
358
01:08:11,060 --> 01:08:17,279
I am setting it first now for all vertices
of W I just said to V you see when the W is
359
01:08:17,279 --> 01:08:24,970
visited or not if not then you call DFS (W)
otherwise go to the next adjacent vertex or
360
01:08:24,970 --> 01:08:32,190
it is just a vertex of V and you check again
and so on so that is the DFS or depth-first
361
01:08:32,190 --> 01:08:41,560
search and this algorithm is where that so
with these we like to stop or we are here
362
01:08:41,560 --> 01:08:50,090
today and we assume that we have this the
different standard days or sequential algorithms
363
01:08:50,090 --> 01:08:55,870
so this class will be discussing about that
need of parallel algorithms different types
364
01:08:55,870 --> 01:09:09,390
of parallel models and will start design thank
you.