1
00:00:16,039 --> 00:00:20,150
Good morning, this is the course we will be
discussing here, that is on parallel algorithms.
2
00:00:20,150 --> 00:00:27,150
All the parallel algorithms is an algorithm,
which will be designing on parallel machines,
3
00:00:37,140 --> 00:00:41,339
before we discuss about the parallel machines,
I I think then it is first time to tell about
4
00:00:41,339 --> 00:00:45,489
that, what is sequential machines, sequential
algorithms and the sequential that is structures,
5
00:00:45,489 --> 00:00:52,489
what is the other issues involving that, that
we will discuss about a parallel algorithms.
6
00:00:53,250 --> 00:01:00,250
Now, we look at into this course, what do
I expect from you is that you have the preliminary
7
00:01:00,290 --> 00:01:07,290
knowledge on the data structures and algorithms.
Well this data structure and algorithm, these
8
00:01:19,460 --> 00:01:26,460
two words completely link to each other and
they are very small component on that software
9
00:01:31,990 --> 00:01:38,990
engineering life cycle. Now what is algorithm?
Algorithm is a step by step procedure to solve
10
00:01:45,390 --> 00:01:52,390
a problem by an automation. What is automation?
Automated is nothing but I can give you one
11
00:01:54,040 --> 00:02:01,040
example suppose, your mother is told you to
bring some items from the market say, brinjal
12
00:02:01,040 --> 00:02:06,100
and you have gone to the market and you have
found that brinjal is not available in the
13
00:02:06,100 --> 00:02:10,340
market.
What are you going to do, one way could be
14
00:02:10,340 --> 00:02:17,340
possibly will not be purchasing anything and
you will be coming back without thinking much
15
00:02:20,209 --> 00:02:27,209
and this is, that you have to acted as an
automated, because you did not use your brain
16
00:02:29,510 --> 00:02:35,329
and to think that, what would happen if brinjal
is not available at home. And then, the possibly
17
00:02:35,329 --> 00:02:42,329
you will not able to get your food so, idea
is that you are not using your brain to solve
18
00:02:42,409 --> 00:02:49,409
this problem. So, you have that is, that an
automation is an machine, which does not have
19
00:02:50,459 --> 00:02:56,409
any brain to think.
So, that is the definition of algorithm now,
20
00:02:56,409 --> 00:03:02,279
what happens, in the algorithm we have few
things in your mind that, it must terminate
21
00:03:02,279 --> 00:03:07,889
after sometime. Otherwise, what that will
be an infinite loop and will not be able to
22
00:03:07,889 --> 00:03:14,889
decide, whether algorithm gives you the correct
thing after certain amount of time. The next
23
00:03:15,959 --> 00:03:22,959
program is that, algorithm must be that should
not be any long time error or something undefined
24
00:03:29,139 --> 00:03:34,760
material existing in the steps and third factor
one should keep it in the mind in the case
25
00:03:34,760 --> 00:03:41,760
of algorithm that, it is a must be an effective.
What does it mean, the define I am not able
26
00:03:43,099 --> 00:03:50,040
to solve every step of the algorithm but,
if it so happen, it may take huge amount of
27
00:03:50,040 --> 00:03:55,620
time to solve the problem that is, that may
be that may be a possible scenario. Now, now
28
00:03:55,620 --> 00:03:59,579
another factor you should keep it in mind
in the case of algorithm, it must increase
29
00:03:59,579 --> 00:04:04,129
some output. Otherwise, whatever you are designing
the algorithm, if you are not getting any
30
00:04:04,129 --> 00:04:11,129
error output, you will not using any output
then, this algorithm has no meaning.
31
00:04:11,290 --> 00:04:18,290
Now, there should be some input, maybe input
is internal one are external one now, based
32
00:04:19,269 --> 00:04:26,269
on that, you can design the algorithms. Now,
the thing is, the algorithm depended on data
33
00:04:36,850 --> 00:04:41,510
now, it may so happen that, you have different
sets of data and how you are arranging them
34
00:04:41,510 --> 00:04:48,510
that is known as data structure. Now, an algorithm
can be suitable for one kind of data structure
35
00:04:51,490 --> 00:04:53,930
but, it cannot be appropriate for the another
set of our another type of data structure.
36
00:04:53,930 --> 00:05:00,930
So, this is the highly, so it is highly link
between algorithm and data structures so,
37
00:05:05,420 --> 00:05:12,110
basically, the meaning of data structures
is that, the way you are arranging the data
38
00:05:12,110 --> 00:05:18,850
is data structure. Now, there are certain
operations we will perform on data structures,
39
00:05:18,850 --> 00:05:25,850
one is anyone can read the elements, another
one is that you want to modify certain element,
40
00:05:27,500 --> 00:05:33,150
another one is that you may like to insert
some elements or delete some elements from
41
00:05:33,150 --> 00:05:40,150
the data set or you may reverse or you may
perform certain operations or modifications
42
00:05:42,050 --> 00:05:45,700
on some set of some elements on this set of
data right.
43
00:05:45,700 --> 00:05:52,010
So, these are the few operations, we let perform
on data structures now, and a data structure,
44
00:05:52,010 --> 00:05:59,010
various type of data structures may be suitable
or some type operations may not be suitable
45
00:06:00,150 --> 00:06:07,150
for another type of operations. So, why would
define the data structure is, the programmer
46
00:06:10,420 --> 00:06:12,310
or designer must think about that the type
of operations you like to perform the data,
47
00:06:12,310 --> 00:06:18,750
depending on that, we design one should design
the data structure. So, what is the data structure
48
00:06:18,750 --> 00:06:24,060
is defined then only, you can think about
to design the algorithms, once you design
49
00:06:24,060 --> 00:06:31,060
the algorithm, what are the factors you should
keep it in mind.
50
00:06:31,100 --> 00:06:35,370
One, the algorithm must be correct, until
and unless the algorithm is correct, you cannot
51
00:06:35,370 --> 00:06:41,690
justify that, this will produce the result.
Now, once you know the algorithm is correct,
52
00:06:41,690 --> 00:06:48,690
there the question is coming that, the algorithm
must be efficient. So, what is mean by efficient?
53
00:06:51,220 --> 00:06:58,220
Efficient means that, it must be taking must
be able to take less amount of time to produce
54
00:07:01,680 --> 00:07:08,680
the result. The another possibility is that,
you just taking less amount of space so that,
55
00:07:10,410 --> 00:07:15,240
if it is not loaded on the computer however,
the space problem is not that difficult here.
56
00:07:15,240 --> 00:07:22,240
Because, because that is easy or the cost
wise, the getting memory is not very costly
57
00:07:24,889 --> 00:07:31,889
so, we do not consider the space factor much
for designing the algorithm. But, of course,
58
00:07:35,580 --> 00:07:42,580
the complexity type plays a major role to
define or to design the efficient algorithm.
59
00:07:45,680 --> 00:07:52,680
So, there are two types of complexities, one
is known as time complexity, the other one
60
00:07:53,360 --> 00:08:00,360
is known as space complexity. Now, how to
make that the time for an algorithms, what
61
00:08:13,530 --> 00:08:16,450
are the possible way, the possible way is
that, you design an algorithm and then, implement
62
00:08:16,450 --> 00:08:23,450
on it on some machine and then, you tell how
much time it takes right. So, but, this is
63
00:08:25,060 --> 00:08:28,169
completely machine dependent and in order
to, compare one algorithm with another algorithms,
64
00:08:28,169 --> 00:08:35,169
there you need to get the algorithm and you
have to run on the same machine.
65
00:08:36,860 --> 00:08:43,860
And then, you will be able to tell which one
is better better with respect to time, well
66
00:08:48,269 --> 00:08:52,639
another factor is that, why we use to determine
that x amount of time on the then, you have
67
00:08:52,639 --> 00:08:58,699
to specify the type of machine you have to
use, which is changing day by day. So, that
68
00:08:58,699 --> 00:09:05,699
is not a good way of measuring the time for
an algorithm so, next factor could be that
69
00:09:06,309 --> 00:09:13,309
you can tell the number of operations you
are performing on algorithms. And for each
70
00:09:14,089 --> 00:09:20,319
category of operations, the number of time
that operation operator number of number of
71
00:09:20,319 --> 00:09:26,999
times that operations you have performed right.
So, number of operators you have used and
72
00:09:26,999 --> 00:09:33,279
for each operator, number of times you have
used that you can compute and then, you can
73
00:09:33,279 --> 00:09:38,819
estimate the time because, you can tell that
for multiplication x amount of time, for edition
74
00:09:38,819 --> 00:09:45,819
y amount of time and so on. So, you can compute
the total amount of time needed for algorithms
75
00:09:48,100 --> 00:09:55,100
or for these algorithms. But, again this is
also not an easy task to estimate, how to
76
00:09:55,689 --> 00:10:01,759
find out the number of operations, you are
performing in an algorithms.
77
00:10:01,759 --> 00:10:08,759
So, what is the default way of estimating
the time for an algorithms, one possible thing
78
00:10:11,029 --> 00:10:17,740
is that the number of, you parallel algorithm
we can find out the what which are the operations
79
00:10:17,740 --> 00:10:24,740
are critical. Say for example, in the case
of sum of n numbers, addition is the critical
80
00:10:26,290 --> 00:10:29,009
operations, in the case of matrix multiplication,
multiplication is the critical operations,
81
00:10:29,009 --> 00:10:36,009
in case of sorting is the critical operation.
Now, the number of operations for that problems
82
00:10:37,259 --> 00:10:44,259
can be defined in terms of input output parameters
that is, the number of inputs or number of
83
00:10:47,019 --> 00:10:54,019
outputs in generating that can be used to
estimates the time complexity. For example,
84
00:10:55,269 --> 00:11:00,689
that suppose, I have n elements and you want
to find out the sum of n elements then, the
85
00:11:00,689 --> 00:11:05,749
operations number of operations or the number
of additions will be using is a function of
86
00:11:05,749 --> 00:11:06,860
n.
87
00:11:06,860 --> 00:11:13,860
Can you estimate the number of number of additions
you need, to find the sum of n elements, yes
88
00:11:18,129 --> 00:11:25,129
the number is n minus 1 number is n minus
1, the additions you need to find the sum
89
00:11:27,720 --> 00:11:34,629
of n numbers. So, there is the number of additions
is known as n minus 1. so, this is the dependent
90
00:11:34,629 --> 00:11:41,629
on the input parameter n similarly, in the
case with multiplication so, or matrix multiplication,
91
00:11:45,089 --> 00:11:52,089
here could be for i equal to 1 to n, for j
equal to 1 to n, c i j equals to 0.
92
00:12:15,300 --> 00:12:22,300
For k equals to 1 to n, c i j equal to c i
k star b k j plus c i j j right, this is the
93
00:12:30,649 --> 00:12:31,920
simple classical algorithm format for multiplications
and you observe then, here the two types of
94
00:12:31,920 --> 00:12:38,920
operations here, viewed one is plus and another
one is multiplication. Now, you know the multiplication
95
00:12:40,220 --> 00:12:46,939
is the costlier, multiplication needs more
amount of time than additions. So, the critical
96
00:12:46,939 --> 00:12:53,939
operations c is here, is multiplication you
observe that, if I see whole algorithms then,
97
00:13:03,429 --> 00:13:10,429
two assignments two assignments or assignment
statements, one addition and one multiplication.
98
00:13:14,249 --> 00:13:21,249
Besides this, note the of this assignments
for for this for loops and here, this multiplication
99
00:13:33,649 --> 00:13:40,649
is a representation and the number of number
of multiplications you need number of multiplications
100
00:13:50,050 --> 00:13:57,050
you need to find or to matrix multiplication
to compute the matrix multiplication is this
101
00:13:58,420 --> 00:14:05,420
one, which is n cube which is n cube. So,
again you observe there time complexity so,
102
00:14:05,939 --> 00:14:12,550
when is the time complexity will be addition
using that equal to output parameters.
103
00:14:12,550 --> 00:14:19,550
Now here, there will you find that the worst
case possible and the best case possible so,
104
00:14:27,300 --> 00:14:34,300
for example, to find to sort n elements, you
will find that sometimes the worst case environment
105
00:15:22,459 --> 00:15:29,459
is this and sometimes you may get the best
case environment. So, in the case, you want
106
00:16:14,769 --> 00:16:21,769
to estimate the worst case and the best case,
use these two notations. This known as big
107
00:16:46,239 --> 00:16:53,239
o and this is omega notation, for best possible
that is, the lower bound and this is known
108
00:17:14,880 --> 00:17:16,549
as upper bound.
109
00:17:16,549 --> 00:17:23,549
Then, we have there are known as theta notation
and small o notation. so, what is the theta
110
00:17:26,470 --> 00:17:33,470
notation, which we use for worst case time
complex f n be a function of n. Let g n be
111
00:17:52,890 --> 00:17:59,890
also a function of n then, you get you tell
f n is o g n the request to o of g n, if there
112
00:18:02,300 --> 00:18:09,300
exists constant c and n are such that, f n
is less than equal to c times g n for all,
113
00:18:18,510 --> 00:18:25,510
n greater than or equal to n naught. So, for
example, you have a polynomial of the n set
114
00:18:42,730 --> 00:18:49,730
f n is a n x power n plus a n minus 1 x to
the power n minus 1 a one x plus a 0.
115
00:19:30,830 --> 00:19:37,830
This is polynomial of the degree n now, if
it is polynomial of degree n, what does it
116
00:20:02,930 --> 00:20:09,930
mean that a n for which, this is the leading
coefficient which for all, not equals to zero.
117
00:20:22,520 --> 00:20:29,520
Suppose, i want to find out the worst case
complex, the worst case complexity of the
118
00:20:34,870 --> 00:20:41,870
time and find out by this, this is less than
equals to a n plus a n minus 1 a 1 a 0 x power
119
00:20:47,410 --> 00:20:54,410
n.
Now, a n a n minus 1, a 1 is 0 they are constant
120
00:20:58,310 --> 00:21:05,310
so, I can write c times x to the power x to
the power n, one thing you have to keep it
121
00:21:15,850 --> 00:21:22,850
in mind, if I can I can write only this is
less than equals to this, provided they are
122
00:21:38,820 --> 00:21:44,190
all positive. Now, this is twelve digits number
otherwise, I should write this is n plus 1
123
00:21:44,190 --> 00:21:51,190
and then, I have to write the n plus 1, get
it so, if this is the case so, I can write
124
00:22:00,380 --> 00:22:07,380
this is order x to the power n plus 1.
125
00:22:12,170 --> 00:22:19,170
I have for i equals to 1 to n, for j equals
to 1 to i and so on now, suppose, I want to
126
00:23:05,930 --> 00:23:12,930
compute the complex must the complexity of
this element so, you will be writing that,
127
00:23:42,280 --> 00:23:49,280
summation over i equals to 1 to n, summation
over j equals to 1 to i and will be writing
128
00:24:02,820 --> 00:24:09,820
say order 1. So, this can be written as summation
over i equals to 1 to n and this is becoming
129
00:24:24,020 --> 00:24:27,120
summation over j equals to 1 to i, c, c is
constant.
130
00:24:27,120 --> 00:24:34,120
So, this is the terms summation over i equals
to 1 to n c into i c into i, that will gives
131
00:24:50,940 --> 00:24:57,940
you c into n into n plus 1 divided by 2, agreed.
Now, if it is the case similarly, write this
132
00:25:03,950 --> 00:25:10,950
equal to c into n square, c equal to c into
n square now, for what is the value of for
133
00:25:15,360 --> 00:25:22,360
what value of n this will be true so that,
n equals to 1 and n is equal to 2, it is on
134
00:26:54,330 --> 00:27:01,330
case 3 and so on. So, i can write this is
true for n greater than equal to one so, this
135
00:27:35,710 --> 00:27:42,710
i can write this is order n square order n
square.
136
00:27:50,200 --> 00:27:57,200
So, can you tell me, can I write can I write
instead of, order n square can I write order
137
00:28:14,440 --> 00:28:21,440
n cube? Yes, answer is yes, you can write.
Because, I can always write I can always write
138
00:28:24,590 --> 00:28:31,590
summation summation 1 i is equal to 1 to n,
j is equal to 1 to i, this is less than equal
139
00:28:39,790 --> 00:28:46,790
to c into n square. This I can write d into
n cube plus c into n square where, d is 0.
140
00:28:55,100 --> 00:29:02,100
Now, if I assume that the c plus d c plus
d n cube and this is always true for n greater
141
00:29:04,610 --> 00:29:11,610
than equal to 1 and this is equal to e into
n cube where, e is constant.
142
00:29:29,020 --> 00:29:36,020
So, it is order of n cube now see you observe
that from this I can explain so, I can write
143
00:29:52,420 --> 00:29:59,420
o n cube but, problem is somewhere else. Because,
I have to save my algorithm and my algorithm
144
00:30:11,850 --> 00:30:18,850
is efficient. So, in order to that, I have
to see that this is as close as to the lower
145
00:30:25,100 --> 00:30:25,500
positive values.
146
00:30:25,500 --> 00:30:32,310
So, which is n square now, I have a small
question for you, in this thing where, b and
147
00:30:32,310 --> 00:30:39,310
a are the constant order log b n with this
equals to order log a n where, a and b are
148
00:30:53,790 --> 00:30:54,770
the two constants.
149
00:30:54,770 --> 00:31:01,770
Suppose, I want prove that they are constant
whether you write this one, order log b n
150
00:31:08,110 --> 00:31:15,110
is equal to less than equal to c times log
b n that is equal to c times log b a log a
151
00:31:24,410 --> 00:31:31,410
n. So, this is nothing but, d times log a
n where, d is constant and you can write order
152
00:31:40,730 --> 00:31:47,730
log a n. So, when we can tell about the complexity,
we do mention about this base of logarithm
153
00:31:58,740 --> 00:32:05,740
base of logarithm because, they have much
meaning to define worse case time complexity.
154
00:32:11,960 --> 00:32:18,960
Now, think about the another symbol, which
is known as b omega symbols here, it is talking
155
00:32:38,180 --> 00:32:45,180
about lower bound that
the p is, you have a f n and g n are the two
functions of n. And you have the two positions
156
00:33:14,030 --> 00:33:21,030
d and n 1 and here, it is f n is greater than
equal to d times g n for all n greater than
157
00:33:26,940 --> 00:33:33,940
equal to n 1. That case if it is that case,
f n is omega g n that is the case, if i tell
158
00:33:52,370 --> 00:33:59,370
f n is omega of g n that means, that it may
change the lower bound, which is the constant
159
00:34:12,409 --> 00:34:19,409
factor which is the constant factor. Now,
theta is another notation we use where, you
160
00:34:19,440 --> 00:34:26,440
can have the two functions f n g n and h n
then, f n is equal to theta g n, if d times
161
00:34:56,760 --> 00:35:03,760
g n.
162
00:35:05,119 --> 00:35:12,119
That is, f n is achieved both lower bound
and upper bound of the algorithms right in
163
00:35:26,360 --> 00:35:33,360
the constant factors. So, we introduced the
notation theta for this purpose, this is another
164
00:35:35,700 --> 00:35:42,700
notation we use asymptotic notation o, small
o small o is
used for asymptotic that is, f n is small
165
00:36:20,780 --> 00:36:27,780
o g n that is asymptotic to that is, asymptotic
to g n.
166
00:36:44,800 --> 00:36:51,800
If limit n tends to infinity, f n g n is equal
to 1 right so, we can write f n with assumption
167
00:37:03,130 --> 00:37:10,130
to j, if limit n tends to infinity f n by
g n is equals to 1. So, this on the times
168
00:37:14,340 --> 00:37:21,340
we use for sequential algorithms for evolving
the sequential algorithms now, let us discuss
169
00:37:22,070 --> 00:37:29,070
about the data structures, you have done something
in your book. And again of course, and first
170
00:37:31,190 --> 00:37:38,190
thing is that, you have done the simple data
structure, which is known as array. Now, once
171
00:37:40,380 --> 00:37:47,380
we have an array you tell there, what is the
number of elements in the array right.
172
00:37:48,810 --> 00:37:55,810
So, array of n elements and so, the first
part is that, which is known to you, the number
173
00:38:03,610 --> 00:38:10,610
of clear up by which the number of elements
in the array that is, the major disadvantage
174
00:38:12,180 --> 00:38:19,180
on array. Now, the second thing is that, let
us try to perform certain operation on this
175
00:38:21,150 --> 00:38:25,050
array suppose, I want to read the elements
in the array. So, you need to read all the
176
00:38:25,050 --> 00:38:32,050
elements one by one and
that takes order n amount order n time now,
once this array elements are there then, at
177
00:38:43,920 --> 00:38:50,920
any movement you can fetch the ith element
in order n time.
178
00:39:02,490 --> 00:39:09,490
So, reading array element reading array element
say, for order n time, once it the reading
179
00:39:09,570 --> 00:39:16,570
ith element in the array order of one times,
the next one is suppose, I want to insert
180
00:39:28,200 --> 00:39:35,200
an element in the array. So, this insertion
is not an easy task in the array suppose,
181
00:39:39,820 --> 00:39:46,820
I want to insert an element here, what you
have to do, you have to get a space for this
182
00:40:00,290 --> 00:40:07,290
element. So, you have to get that all the
elements to be shifted by one towards.
183
00:40:17,710 --> 00:40:24,710
So, in the worst case, the insertion is order
of n that is, in the last case but, suppose
184
00:40:27,310 --> 00:40:34,160
I want to insert an element here, nothing
rule the to addition of, which takes constant
185
00:40:34,160 --> 00:40:41,160
of the time, which is the best task. Now,
if you think about the deletion what happen,
186
00:40:42,670 --> 00:40:49,670
suppose, I want to delete this element suppose,
I want to delete this element then, we observe
187
00:40:53,600 --> 00:41:00,600
you want to delete. Basically, you cannot
just delete it, here to bring this element
188
00:41:07,630 --> 00:41:14,630
here, this element here, this element here
and so on. So, again deletion takes, deletion
189
00:41:24,510 --> 00:41:29,690
of take order n times right but, if the best
possible case suppose, i want to delete the
190
00:41:29,690 --> 00:41:36,690
last element then, it takes constant amount
of time.
191
00:41:41,840 --> 00:41:48,840
Now, suppose I want to modify the ith element
of the array, how much time will it takes,
192
00:42:04,270 --> 00:42:11,270
it takes order one time. Because, I will just
go to
the ith element and the excess thing so, I
193
00:42:27,869 --> 00:42:34,869
can easily replace the content of
the ith element and to takes order one time.
So, these are the major steps or major operations.
194
00:42:57,080 --> 00:43:04,080
Now, a simple question for you, you know what
is the transpose of the matrix, the transpose
195
00:43:09,030 --> 00:43:14,790
of the matrix is very simple operation to
do.
196
00:43:14,790 --> 00:43:21,790
But, it is not while I kept write an aptitude
of the transpose of matrix is nothing but,
197
00:43:25,450 --> 00:43:32,450
that is you have a i j has to interchange
a j i. So, set is the operation similar going
198
00:43:49,830 --> 00:43:56,830
to perform it looks n is the simple just you
in touch in between these two elements in
199
00:44:03,060 --> 00:44:05,440
getting the other.
200
00:44:05,440 --> 00:44:12,440
If we write an algorithm point of transpose
of a matrix, we will observe that it has it
201
00:44:33,890 --> 00:44:40,890
is not that much easy. Let us try, can you
tell me what I could write, yes for i equals
202
00:44:55,000 --> 00:45:02,000
to 1 to n, for j equal to, temp equal to a
i j, a i j equal to a j i and then, you
will write to a j i equal to temp. So, if
203
00:45:59,480 --> 00:46:06,480
it is the case, then can you tell me, what
i could write here, 1.
204
00:46:09,770 --> 00:46:16,770
Let us see what happen if I write 1, would
you get the transpose matrix, answer is no,
205
00:46:19,770 --> 00:46:26,770
it will give you the same matrix again. This
is because of the fact that, just for a while
206
00:46:36,180 --> 00:46:43,180
will be first signs, you will interchange
a i j into a j i. Again, when i equal to j
207
00:46:51,330 --> 00:46:58,330
and j equal to i, you find that a i j is interchanged
into a j i. Try at home and see these two
208
00:47:41,599 --> 00:47:48,599
times interchange and another. So, what i
could write here, one will be I can write
209
00:48:34,800 --> 00:48:41,800
i to n in that case, yes you will be getting
one time interchange and you get the transpose
210
00:48:48,640 --> 00:48:50,030
of the matrix.
211
00:48:50,030 --> 00:48:54,710
Here, this is there is one problem here, in
observe that if I had i to n the initial is
212
00:48:54,710 --> 00:48:55,730
the diagonal element would be interchange
again and again. But, this is not question
213
00:48:55,730 --> 00:49:02,730
of what is no need of interchanging diagonal
element of the matrix so, 1 plus I, i plus
214
00:49:06,080 --> 00:49:13,080
1 to n right. Now, suppose I want to obtain
the complexity of this algorithm then, you
215
00:49:29,140 --> 00:49:36,140
can find out delta i equals to 1 to n, j equals
to i plus 1 to n and this is constant time.
216
00:49:52,590 --> 00:49:59,590
Because, constant time, so it is c and which,
I can write summation over i equal to one
217
00:50:13,510 --> 00:50:20,510
to n c times n minus i.
218
00:50:21,240 --> 00:50:28,240
n minus i which I can write c n square minus
c times n into n plus 1 divided by 2 and which
219
00:50:46,609 --> 00:50:53,609
is c n square which is order n square. So,
one thing you remember, the transpose of a
220
00:51:04,290 --> 00:51:11,290
matrix their solve n square times that is
the minimum requirement and minimum time this
221
00:51:26,200 --> 00:51:33,200
is also called. No, there need data structure
here occupied linked list, the in linked list,
222
00:51:41,369 --> 00:51:48,369
you know one is single linked list, next one
is double linked list next then, generalized
223
00:52:05,070 --> 00:52:10,290
linked list.
224
00:52:10,290 --> 00:52:17,290
Now, going to discuss about the single linked
list so, we have the top node, this node is
225
00:52:45,680 --> 00:52:52,680
having the at least two field one is known
as data field, another one is called as link.
226
00:53:39,290 --> 00:53:46,290
Data field linked list and so, on link points
to the next node, there is the starting node
227
00:54:02,150 --> 00:54:09,150
is to the linked list.
228
00:54:10,730 --> 00:54:17,730
Here, if I am to I have to this linked list
let us see what happen, first of all, read
229
00:54:33,140 --> 00:54:40,140
all the data. So, if read one by one, please
takes order n, order n n among of time now,
230
00:54:52,300 --> 00:54:58,750
suppose, i want to get the ith element of
this linked list then, if travels from the
231
00:54:58,750 --> 00:55:01,720
beginning to the higher position, we takes
order i times. So, basically you need order
232
00:55:01,720 --> 00:55:08,300
n times in the worst case, to move the nth
element of the link. Suppose, I want to modify
233
00:55:08,300 --> 00:55:15,300
I want to modify the nth element or ith element
then, I have to go up to highest position
234
00:55:19,480 --> 00:55:26,480
and then, modify the mistakes or the i taps.
Now, what happens that insertion and deletion,
235
00:55:34,790 --> 00:55:41,790
if. I do not know way to, which one to be
deleted or I know that, it is the highest
236
00:55:45,030 --> 00:55:52,030
one to be deleted, I am going to the highest
position and then, perform the deletion operation.
237
00:55:57,589 --> 00:56:04,589
So, it takes what are the i time to reach
them, n th of the your perform the operation
238
00:56:09,880 --> 00:56:16,880
similarly, if I have to insert some node here
so, the area to reach up to this one and then
239
00:56:21,310 --> 00:56:28,310
only, we can able to insert right.
So, let us assure that, this order right can
240
00:56:33,900 --> 00:56:40,900
still here plus the insertion or deletion
time to be consider right. Now, let us see
241
00:56:46,250 --> 00:56:53,250
suppose, I want to insert in node after x,
the node x after x but, I go I align, after
242
00:56:56,320 --> 00:57:03,040
that by some means is or sometime and then,
I will get a node get a node, fill the data.
243
00:57:03,040 --> 00:57:10,040
And then, if I will link this part, if I link
this part then, I give the information about
244
00:57:24,109 --> 00:57:31,109
this one so, what I have to do, I have to
link for this one and then, you will be linking
245
00:57:41,480 --> 00:57:48,480
this one. So, link will go, this will be out
so, if this will be interchange so, which
246
00:57:53,410 --> 00:57:54,950
takes constant amount of time. Now, next one
is so, this takes constant time now, suppose,
247
00:57:54,950 --> 00:58:01,950
I want to delete the node occurrence, how
can I delete the node after x. You have to
248
00:58:10,760 --> 00:58:17,760
delete the node after x, what I can do, I
will put just the link operate to the link
249
00:58:35,720 --> 00:58:42,720
of the next node of the link right. Link of
x, we will finding to the link of x of link
250
00:58:46,140 --> 00:58:53,140
right, that you know, which takes constant
amount of time now, what i want to ask you
251
00:59:02,140 --> 00:59:09,140
the question is differ because, upto this
you had done in your under graduate course.
252
00:59:14,990 --> 00:59:21,990
Suppose, I want to delete this node, how can
I delete this node, can I delete it because,
253
00:59:22,300 --> 00:59:29,300
if I can do that . So, can i delete this node
in constant amount of time, yes, is it difficult.
254
00:59:29,740 --> 00:59:35,609
You will understand how we can do it say,
is not believing this node because, I can
255
00:59:35,609 --> 00:59:41,950
I can go back. So, one could be one we could
be then, I copy this data here, I copy this
256
00:59:41,950 --> 00:59:48,950
data here and then, delete this node here.
In that case, this takes copy takes constant
257
00:59:49,460 --> 00:59:56,460
time and deleting these two takes constant
time. So, we can delete this node, the constant
258
01:00:00,130 --> 01:00:04,910
amount of time, now, think about the the problem
you face in the serial link is of going back,
259
01:00:04,910 --> 01:00:05,160
what is very difficult.
260
01:00:05,089 --> 01:00:06,420
Going backward is very difficult because,
you have to start from the beginning so, you
261
01:00:06,420 --> 01:00:12,210
know instead of that instead of that, then
we did point the toply linked list. Now, doubly
262
01:00:12,210 --> 01:00:19,210
linked list is that, get the one is left link,
another one is the right link and this is
263
01:00:25,410 --> 01:00:30,650
the data field. What is that going backward
or forward, is not the problem in the case
264
01:00:30,650 --> 01:00:35,170
of the doubly linked list. Now, it is a structure
you have to done, which is known as stack
265
01:00:35,170 --> 01:00:39,859
and queue right.
See one example could be the, in the library
266
01:00:39,859 --> 01:00:46,859
we have seen the books are bind upon the number
then, the bookkeeper brings some books again
267
01:00:59,650 --> 01:01:06,650
in the cupboard. whenever you have to read
a book, what you are going to do so, from
268
01:01:09,710 --> 01:01:16,710
that stack of books you will be removing one
by one but, that from the top right. See for
269
01:01:44,849 --> 01:01:51,849
example, in the dining area coffee or so,
when you entered the dining hall, you will
270
01:02:04,070 --> 01:02:11,070
find that the plates are stand on the one
on the top of another one and so on.
271
01:02:13,500 --> 01:02:20,500
And that, you have, you want to take your
food so, you will be taking the plate from
272
01:02:24,109 --> 01:02:27,670
the top, again of the dining area. If all
sets of plates and you put it on the top of
273
01:02:27,670 --> 01:02:34,490
so, that is known as, that is an example of
stack.
274
01:02:34,490 --> 01:02:40,470
But, the example of queue is very simple,
you stand in the movie to get the tickets,
275
01:02:40,470 --> 01:02:41,490
the first person gets the ticket in this and
the person join to get the ticket, he stands
276
01:02:41,490 --> 01:02:44,060
at the end of the queue. Now, we have understand,
what happened the stand, the arrangements
277
01:02:44,060 --> 01:02:51,060
are like this now, suppose, I want to insert
certain element, in the case of stack, we
278
01:02:59,040 --> 01:03:05,430
substitute on the top. Suppose, we want to
delete this element, the deletion also from
279
01:03:05,430 --> 01:03:05,680
the top.
280
01:03:05,430 --> 01:03:09,109
And if you can take the constant amount of
time so in the case of stack, insertion and
281
01:03:09,109 --> 01:03:16,109
deletion from one end. In the case of queue,
this is if you standing so, another person
282
01:03:17,510 --> 01:03:18,760
comes he will be standing at the end and the
person coming out is from the front top. So,
283
01:03:18,760 --> 01:03:19,839
insertion will be at one end and deletion
will be from another end, this is the definition
284
01:03:19,839 --> 01:03:20,550
of queue.
See, an example for this stack would be that
285
01:03:20,550 --> 01:03:21,770
sub-routine volume so, we have a for main
program and we have a routine, here you have
286
01:03:21,770 --> 01:03:23,810
calling sub-routine A then, you have sub-routine
A, you have calling a routine B, here we have
287
01:03:23,810 --> 01:03:24,060
calling C and C is calling here.
288
01:03:23,920 --> 01:03:24,170
So, here you have the return statement so,
return statement here, return statement and
289
01:03:24,130 --> 01:03:24,390
here, return end. So, what happens, why here
is called A so, the system deserves the next
290
01:03:24,390 --> 01:03:24,640
statement, adjust the next statement. So,
say, next statement say s, then this is s
291
01:03:24,619 --> 01:03:31,619
now, it goes to this one, end of completing
and get the address of the next statement
292
01:03:34,170 --> 01:03:38,630
of B, it is to be t so, it stores t. So, it
is called b and we get c and can be u in the
293
01:03:38,630 --> 01:03:42,839
next statement of c. so, here it is stores
u.
294
01:03:42,839 --> 01:03:47,470
So, it perform the c now, it assure it has
return statement, just comes back to the next
295
01:03:47,470 --> 01:03:47,720
statement of C. That is, the adjacent available
in the stack, it is u so, it swaps off that
296
01:03:47,670 --> 01:03:47,920
u and he comes here, it gets to return statement.
Now, they should return to the procedure A
297
01:03:47,849 --> 01:03:48,099
and it gets t from the stack, it comes here
then, it gets the return statement, they should
298
01:03:48,040 --> 01:03:48,290
come back to the main routine to the next
statement to execute with this so, that is
299
01:03:48,220 --> 01:03:48,470
the one example where stack is used.
300
01:03:48,300 --> 01:03:48,550
Now, we have or we know the term tree, what
is tree, the next terminology we will be discussing
301
01:03:48,490 --> 01:03:49,070
the binary tree. Tree tree for takes n nodes,
n is atleast 1 node and 1 node is the node
302
01:03:49,070 --> 01:03:49,480
is the root of the tree root of the tree and
this is specially, dedicated node which is
303
01:03:49,480 --> 01:03:49,890
called as root of the tree. And we have the
remaining n minus 1 then, connected they are
304
01:03:49,890 --> 01:03:53,349
connected to root r, they are connected to
the root node r and most of this n nodes form
305
01:03:53,349 --> 01:03:54,030
a tree, form a sub-trees, this n nodes form
a p sub-trees.
306
01:03:54,030 --> 01:03:55,109
P is basically, we have a root node r root
node r under that, there this some other root
307
01:03:55,109 --> 01:03:56,200
node. So, if we this then, we get x disjoined
sub-trees. If I this again we get some number
308
01:03:56,200 --> 01:03:57,220
of sub-trees and so on. Only condition is
that there is atleast 1 node in the tree So,
309
01:03:57,220 --> 01:03:58,190
in the case of binary tree, empty empty empty
binary empty binary tree is also a binary
310
01:03:58,190 --> 01:03:58,440
tree.
311
01:03:58,240 --> 01:03:59,869
So that, you can define what is binary tree
otherwise then, is specially node will be
312
01:03:59,869 --> 01:04:00,329
getting is root node. root node and it is
utmost two sub-trees, one is known as left
313
01:04:00,329 --> 01:04:00,710
sub-tree, another one is right subtree, left
sub-tree and right sub-tree. And left sub-tree
314
01:04:00,710 --> 01:04:04,570
and right sub-tree both are binary tree. We
have the root node, left sub-tree, root node
315
01:04:04,570 --> 01:04:06,089
it has utmost two children. So, the left child
if exist, is the root of the left sub-tree
316
01:04:06,089 --> 01:04:07,859
and if the right child if exist then, it is
the root of the right sub-tree such that,
317
01:04:07,859 --> 01:04:08,349
it is a binary tree.
318
01:04:08,349 --> 01:04:12,170
Do you recollect what is heap, heap is a complete
binary tree now, what is complete binary tree,
319
01:04:12,170 --> 01:04:14,640
complete binary tree means that, it is full
that last for one level and in the last level
320
01:04:14,640 --> 01:04:14,890
in the last level it is full from from left
to right.
321
01:04:14,690 --> 01:04:14,940
So, heap is a complete binary tree of level
and it satisfies certain properties, one property
322
01:04:14,760 --> 01:04:15,109
is in case if min heap, this is the minimum
element minimum element or this able to scroll
323
01:04:15,109 --> 01:04:16,050
of the both element of left and right child
and also, this is left sub-tree in a tree
324
01:04:16,050 --> 01:04:16,760
and right sub-tree also . So, this is a complete
binary tree and this slope contain, in case
325
01:04:16,760 --> 01:04:17,420
of min heap it contains of minimum element
compare to this tree, compare to right child
326
01:04:17,420 --> 01:04:17,960
and left child and left sub-tree is obedient,
right sub-tree is also obedient.
327
01:04:17,960 --> 01:04:21,540
Graph, we define g by v from V and E where,
V is the set of vertices and E is the set
328
01:04:21,540 --> 01:04:26,869
of edges. V is set of vertices suppose, you
have n vertices, they are defined as the v
329
01:04:26,869 --> 01:04:27,119
1, v 2, and v n and you have edges e 1, e
2, e 3 and so on from the edges. And e r is
330
01:04:26,910 --> 01:04:27,160
the edge between v k and v i right.
331
01:04:26,920 --> 01:04:27,170
This is a structure and this a possible here,
you can have v 1, v 2, v 3, v 4, v 5, v 6
332
01:04:26,960 --> 01:04:27,210
and so on and we can take e, e is also a graph
between. Now, can you tell me, what type of
333
01:04:26,990 --> 01:04:27,240
graph between, e is a sin theta, if e is a
cyclic graph, can you find out can you tell
334
01:04:27,020 --> 01:04:27,270
me the number of edges you have there.
335
01:04:27,030 --> 01:04:27,280
Then, if you have n nodes then, number of
edges will be n minus 1 in the field. Because,
336
01:04:27,060 --> 01:04:27,310
if these are connected acyclic graph, which
takes, which needs n minus 1, to maintain
337
01:04:27,230 --> 01:04:27,480
the connectivity. And if i add 1 is then,
it will become the cyclic graph so, that is
338
01:04:27,230 --> 01:04:27,760
the this always graph v and e just we defining.
So, that why this curving of another now,
339
01:04:27,760 --> 01:04:29,450
let us understand, a simple program and see,
how you can solve it.
340
01:04:29,450 --> 01:04:31,980
Then can you, do you remember the how to find
out the minimum of n elements or suppose,
341
01:04:31,980 --> 01:04:33,839
you have n element and you have to find out
the minimum of this n element, one possible
342
01:04:33,839 --> 01:04:36,109
way is that, you have a 1, a 2 and a n. Initially,
you defined minimum is a 1 then, minimum is
343
01:04:36,109 --> 01:04:38,170
compared with a 2, if you find a 2 is smaller
than min then, min is different by a 2.
344
01:04:38,170 --> 01:04:40,630
And then, you compare again with a 3 and if
you find a 3 is greater than min, do not do
345
01:04:40,630 --> 01:04:40,880
anything, just go for the next one and so
on. So, in that process, you need n minus
346
01:04:40,630 --> 01:04:40,880
1 comparator right, to find out the minimum
of n elements. Now, the programs is here suppose,
347
01:04:40,630 --> 01:04:40,880
we should find out the minimum of n elements,
I am interested to find out the 2nd minimum
348
01:04:40,630 --> 01:04:40,880
second minimum.
Now, can you tell me, how can I find out the
349
01:04:40,630 --> 01:04:40,880
second minimum of this n so, one possible
way is that, you first complete find the minimum.
350
01:04:40,630 --> 01:04:40,880
Now, you have the remaining n minus 1 elements
and again you find the minimum, that will
351
01:04:40,630 --> 01:04:40,880
be your 2nd minimum. So, in the for the first
case you give n minus 1 competitor.
352
01:04:40,630 --> 01:04:40,880
Second time you give n minus 2 competitors
so, you get 2 n minus 3 competitors to find
353
01:04:40,630 --> 01:04:40,880
the 2nd minimum. But, is this the best way
to do it so, let us conjugate this problem
354
01:04:40,630 --> 01:04:40,880
that finding the 2nd minimum.
355
01:04:40,630 --> 01:04:40,880
And this moment we discuss that you have seen
that this many comparisons you need and our
356
01:04:40,630 --> 01:04:40,880
time it is to find out, whether this is the
best possible way for finding the second minimum.
357
01:04:40,630 --> 01:04:40,880
Now, let us consider the another form suppose,
I am interested to find out minimum and maximum
358
01:04:40,630 --> 01:04:40,880
of n elements. Now, one way possible that,
you find the minimum of this, you check n
359
01:04:40,630 --> 01:04:40,880
minus 1 and again, you find the maximum, you
get again n minus 1.
360
01:04:40,630 --> 01:04:40,880
So, to find the minimum and maximum minimum
and maximum of n elements, you need 2 n minus
361
01:04:40,630 --> 01:04:40,880
2 comparisons right but, is this the best
way of doing? Answer is no.
362
01:04:40,630 --> 01:04:40,880
In order to do that, another that you have
a 1, a 2, a 3, a 4, a 5, a 6, a 7 and a 8,
363
01:04:40,630 --> 01:04:40,880
let us assume that you have this 8 elements,
for for simplicity for simplicity let us assume
364
01:04:40,630 --> 01:04:40,880
that they were 8 teams are participating in
one game. And you want to introduce a knock
365
01:04:40,630 --> 01:04:40,880
out tournament among this to find out the
who is the winner right. So, in order do that,
366
01:04:40,630 --> 01:04:40,880
what we do, we divided into 4 groups, each
groups consists of two teams.
367
01:04:40,630 --> 01:04:40,880
And these two teams of each group play each
other and one of them will be declared as
368
01:04:40,630 --> 01:04:40,880
winner and one of them will be declared as
looser, get it. Now, in order to see the winner
369
01:04:40,630 --> 01:04:40,880
of this so, this four will be divided into
two teams, two groups and the winner is, a
370
01:04:40,630 --> 01:04:40,880
winner of these two be here and these two
teams will play each other and to be here,
371
01:04:40,630 --> 01:04:40,880
to be the winner, that is the procedure.
372
01:04:40,630 --> 01:04:40,880
To find out the winner of the same teams by
knock out method now, it plays winner by replace
373
01:04:40,630 --> 01:04:40,880
w by min, what happened. So, this itself is
the minimum of these 2 elements, minimum of
374
01:04:40,630 --> 01:04:40,880
these 2 elements, minimum of these 2 elements
and minimum of these 2 elements. So, minimum
375
01:04:40,630 --> 01:04:40,880
of these 2 elements is here and minimum of
these 2 elements will be here and the minimum
376
01:04:40,630 --> 01:04:40,880
of these 2 elements is the minimum of all
these 8 elements agreed.
377
01:04:40,630 --> 01:04:40,880
So, you observed the number of comparisons
you have used, here 1 2 3 4 5 6 7. So, 7 comparisons
378
01:04:40,630 --> 01:04:40,880
you have used that is, n minus 1 comparison
to find the minimum, agreed. Now, in order
379
01:04:40,630 --> 01:04:40,880
to find out the maximum of these, you observe
the maximum cannot be any one of them because,
380
01:04:40,630 --> 01:04:40,880
they are the minimum. So, maximum will be
one of these 4 elements now, one of these
381
01:04:40,630 --> 01:04:40,880
4 elements means that, you have to find out
the maximum of these 4 elements.
382
01:04:40,630 --> 01:04:40,880
That 4 elements are nothing but, n by 2 elements
and finding the maximum of these 4 elements
383
01:04:40,630 --> 01:04:40,880
is n by 2 minus 1. So, the number of comparisons
help me to find the maximum and minimum of
384
01:04:40,630 --> 01:04:40,880
n elements is 3 n by 2 minus 2 so, it is much
better than much better than 2 n minus 2.
385
01:04:40,630 --> 01:04:40,880
Now, what about what about the another one
that finding the, so I loop into this problem
386
01:04:40,630 --> 01:04:40,880
on one over the another, you get a 1, a 2,
a 3, a 4, a 5, a 6, a 7 and a 8. And you have
387
01:04:40,630 --> 01:04:40,880
for winner 1, winner 2, winner 3, winner 4
then, winner winner of these two, winner of
388
01:04:40,630 --> 01:04:40,880
these two and then, W is referred by minimum.
Then, suppose, this is your minimum movement
389
01:04:40,630 --> 01:04:40,880
minimum movement so, to find the 2nd minimum
the the problem will get, this is the problem
390
01:04:40,630 --> 01:04:40,880
you can detect and this is the another problem
you can detect and this is another problem
391
01:04:40,630 --> 01:04:40,880
you can detect right. Because, this is minimum
of minimum of these 4 elements, this is one
392
01:04:40,630 --> 01:04:40,880
case and this is the minimum of these 2 elements
so, you have that many possible candidates,
393
01:04:40,630 --> 01:04:40,880
among that you have to find out the minimum.
394
01:04:40,630 --> 01:04:40,880
So, this you observe that every height gives
1 element, every level you get 1 element for
395
01:04:40,630 --> 01:04:40,880
this level this one, for this level this one
and this level this one. The height of the
396
01:04:40,630 --> 01:04:40,880
state is log n minus 1 height of the state
is log n minus 1 so, to find the minimum you
397
01:04:40,630 --> 01:04:40,880
get n minus 1 then, height of the tree is
log n minus 1 and to find the minimum, you
398
01:04:40,630 --> 01:04:40,880
get another minus 1. Height of the tree is
log n plus 1 plus 1 so, you get log n minus
399
01:04:40,630 --> 01:04:40,880
1 comparison.
So, 2nd minimum takes n plus log n minus 2
400
01:04:40,630 --> 01:04:40,880
as many comparisons so, this is the but, again
to find the 3 rd minimum you have to go for
401
01:04:40,630 --> 01:04:40,880
you have to do one by one again. So, it will
become log n minus 2 then, log n minus 3 and
402
01:04:40,630 --> 01:04:40,880
so on so, n plus log n minus 2 plus log n
minus 2 plus log n minus 3 and so on. So,
403
01:04:40,630 --> 01:04:40,880
you will find that suppose, I have to find
out the 1st minimum, 2nd minimum, 3rd minimum
404
01:04:40,630 --> 01:04:40,880
upto n minimums so, this becomes order of
n log n, which is basically nothing but, 1st
405
01:04:40,630 --> 01:04:40,880
minimum, 2nd minimum, 3rd minimum and so on.
It is, we are basically, making the sorting
406
01:04:40,630 --> 01:04:40,880
of n elements and which is lower bound of
this order n log n, which is matching with
407
01:04:40,630 --> 01:04:40,880
that. Let us stop here, and in next class
we will be discussing about different paradigms,
408
01:04:40,630 --> 01:04:40,880
we used for sequential algorithms. And then,
in the 3rd class onwards, we will be discussing
409
01:04:40,630 --> 01:04:40,880
starting about the parallel algorithms and
what are all the things we drop are in the
410
01:04:40,630 --> 01:04:40,880
notes.Thanks.