00:00:08
hey everyone welcome to simply learn's
00:00:10
youtube channel in this session we will
00:00:12
discuss what is an algorithm but before
00:00:15
we begin let me tell you guys that we
00:00:17
have daily updates on multiple
00:00:18
technologies if you're a tech geek in a
00:00:20
continuous hunt for latest technological
00:00:22
trends then consider getting subscribed
00:00:24
to our youtube channel and don't forget
00:00:26
to hit that bell icon to never miss an
00:00:28
update from simply done
00:00:30
now without further ado let's get
00:00:32
started with the agenda for today's
00:00:34
session
00:00:37
first we will get started with what is
00:00:39
an algorithm
00:00:40
followed by that we will look into the
00:00:42
characteristics of algorithm
00:00:44
next we will learn how to write an
00:00:46
algorithm
00:00:47
moving ahead we will look at algorithm
00:00:50
analysis and algorithm complexities
00:00:53
after that we will discuss the
00:00:55
advantages and disadvantages of
00:00:57
algorithms and finally we will see some
00:01:00
differences between algorithms and
00:01:01
programming
00:01:03
i hope i made myself clear with the
00:01:04
agenda now let's get started with the
00:01:06
first point that is what exactly is an
00:01:09
algorithm
00:01:12
how does algorithm work in real life
00:01:15
so we'll have a use case here
00:01:17
on my screen we have a lady and she is
00:01:19
shreya shreya wants to make some tea and
00:01:22
for that she is following some steps
00:01:25
so the first step is she'll take a pan
00:01:27
and fill it with water and place it on a
00:01:30
gas stove
00:01:31
followed by that the second step is
00:01:33
she'll make sure that the water comes to
00:01:35
a nice boil and then she adds some tea
00:01:38
leaves and sugar followed by step 2 we
00:01:41
have step 3 where she'll allow the leaf
00:01:43
to be fully expanded and she'll add some
00:01:46
milk after that
00:01:49
next we have the stefo where she will
00:01:51
wait for the tea to come for a good
00:01:53
decent boil
00:01:55
next we have step 5 where she'll turn
00:01:57
off the gas and she'll take the pan off
00:01:59
from the stove and the tea is ready to
00:02:01
get filtered and lastly we have the step
00:02:04
6 where she is all set with the tea
00:02:08
in computer science an algorithm is a
00:02:09
method or set of rules that we must be
00:02:12
following to perform some specific
00:02:14
calculations or other problem solving
00:02:16
operations
00:02:17
as a result an algorithm is a collection
00:02:19
of rules or instructions that govern how
00:02:22
a work needs to be conducted step by
00:02:24
step to achieve the desired results to
00:02:27
accomplish a task
00:02:28
we first provide some input and then
00:02:31
follow a sequence of steps to acquire
00:02:33
the required outcome of the input so
00:02:35
that is the fundamental definition of an
00:02:37
algorithm and we also had a use case and
00:02:40
now we will move ahead and understand
00:02:42
the characteristics of algorithms
00:02:45
so basically we have six characteristics
00:02:47
of algorithm so the first one is it
00:02:50
should be clear and unambiguous the
00:02:52
second one is that it has to be well
00:02:55
defined inputs and the third one is that
00:02:57
it has to be having well-defined outputs
00:03:01
as well the fourth property of an
00:03:02
algorithm is its feasibility followed by
00:03:05
that
00:03:05
finiteness and finally we have language
00:03:08
independence
00:03:11
now we will look into each one of the
00:03:13
characteristics in detail so first we
00:03:16
have clear and unambiguous so this
00:03:19
statement is the one which states that
00:03:21
the algorithm should be straightforward
00:03:24
simple and easily readable
00:03:26
each one of its steps should be distinct
00:03:28
in every way and lead it to a single
00:03:30
conclusion
00:03:32
so the next one is it should be having
00:03:34
well-defined inputs so this means that
00:03:37
an algorithm should indicate what output
00:03:40
can be expected as well as the input
00:03:42
should be properly well-defined now we
00:03:45
have the third one similarly we should
00:03:47
also have well-defined outputs so the
00:03:50
well-defined output characteristics of
00:03:51
an algorithm means that the algorithm
00:03:54
must clearly indicate what output can be
00:03:56
expected as well as the output should
00:03:59
also be well defined followed by the
00:04:02
third characteristic we have the fourth
00:04:04
characteristic that is the finiteness of
00:04:07
algorithm so the finiteness of algorithm
00:04:09
says that the algorithm must be finite
00:04:12
and it must not result in infinite loops
00:04:15
or similar situations
00:04:17
so followed by the fourth one we have
00:04:19
the fifth characteristic that defines
00:04:21
about the feasibility of an algorithm
00:04:24
so feasibility of an algorithm states
00:04:27
that the algorithm must be really simple
00:04:29
generic and practical
00:04:31
it must be able to be executed with
00:04:33
resources available
00:04:35
now the last characteristic of the
00:04:37
algorithm is being independent of the
00:04:40
language
00:04:42
so it means that the algorithm should be
00:04:44
defined in such a way that it is
00:04:46
completely independent of the language
00:04:48
it must be simple instructions that can
00:04:50
be implemented using any programming
00:04:52
language
00:04:54
so these were the six major
00:04:55
characteristics of algorithm now let's
00:04:57
move ahead and understand how to write
00:05:00
an algorithm
00:05:01
writing an algorithm does not have any
00:05:03
hard and fast rules
00:05:05
next algorithms are never created to
00:05:08
support a specific programming language
00:05:11
as we all know algorithm should be
00:05:13
capable enough to support the
00:05:14
conditional statements such as if if
00:05:17
else switch etc
00:05:18
an algorithm should be capable enough to
00:05:20
execute some of the conditional
00:05:22
statements such as if if else switch etc
00:05:25
and also it must be capable to execute
00:05:28
the iterative statements such as for
00:05:30
loop while loop do while loop etc
00:05:34
we usually create algorithms in a
00:05:36
step-by-step manner however this isn't
00:05:38
always the case
00:05:40
after the problem domain has been well
00:05:42
defined algorithm writing is a procedure
00:05:45
that is carried out
00:05:47
we build an algorithm to find a solution
00:05:49
to a problem a problem can be resolved
00:05:51
in a variety of ways let's look at an
00:05:53
example of how to write an algorithm
00:05:56
consider the following scenario we need
00:05:58
to create an algorithm to determine the
00:06:00
largest number among the three given
00:06:02
numbers x y and z as a result the
00:06:06
initial solution to the problem can be
00:06:08
written in this manner so we begin with
00:06:11
reading all the three numbers and in the
00:06:13
second step we will have a condition
00:06:15
that says if x is greater than y we will
00:06:18
proceed to step four else we will
00:06:20
proceed to step 5.
00:06:22
next in step 4 we establish a condition
00:06:24
that if x is greater than z then x is
00:06:27
the largest of the three numbers
00:06:29
otherwise z is the largest
00:06:32
if y is greater than z z will be the
00:06:34
greatest number otherwise y will be the
00:06:37
largest number amongst all the three in
00:06:40
step five
00:06:41
and the procedure will be terminated
00:06:43
let's have a look at what the next
00:06:45
solution has to offer in this algorithm
00:06:48
we begin by reading all the three
00:06:50
variables then compare all the three
00:06:52
numbers in the third step to determine
00:06:54
the largest number which is if x is
00:06:57
greater than y then there is another if
00:07:00
else statement that states that if x is
00:07:02
greater than y then x is largest
00:07:05
otherwise z is the largest
00:07:08
then this if else statement which says
00:07:11
that if y is greater than z then y is
00:07:14
greater otherwise z is the greatest of
00:07:17
the three numbers so this is how we have
00:07:20
multiple solutions to the same problem
00:07:22
so after discussing these solutions we
00:07:24
will move ahead and understand algorithm
00:07:26
analysis
00:07:28
the algorithm may be studied in two
00:07:30
levels first before it is made and then
00:07:33
after it is created the two analysis of
00:07:36
an algorithm are as follows the first
00:07:38
one is priori analysis and the second
00:07:41
one is the post analysis so first we
00:07:43
will talk about the priori analysis
00:07:46
priori analysis refers to the
00:07:48
theoretical analysis of an algorithm
00:07:50
performed before its implementation
00:07:52
before implementing the algorithm other
00:07:54
parameters such as processor speed might
00:07:57
be considered
00:07:58
which does not affect the implementation
00:08:00
component next we will talk about post
00:08:04
analysis
00:08:05
a practical analysis of an algorithm is
00:08:07
called as posterior analysis and it
00:08:10
utilizes any computer language to build
00:08:12
the algorithm the purpose of this
00:08:15
analysis is to determine how much time
00:08:17
and space the algorithm takes to operate
00:08:20
now after being understood the algorithm
00:08:23
analysis we will be able to comprehend
00:08:25
the algorithm complexity two methods can
00:08:27
be used to assess the algorithm
00:08:30
complexity the first one is time
00:08:32
complexity which states that the amount
00:08:35
of time required to finish an
00:08:36
algorithm's execution is known as its
00:08:39
time complexity
00:08:41
followed by time complexity the other
00:08:43
one is the space complexity which is
00:08:46
calculated by the quantity of space
00:08:47
required to solve a problem and produce
00:08:50
an output of space complexity of an
00:08:52
algorithm
00:08:54
let's take a closer look at these
00:08:55
complexities
00:08:57
now we will begin with time complexity
00:08:59
of an algorithm the big o notation is
00:09:02
used to express an algorithm's time
00:09:04
complexity the asymptomatic notation is
00:09:07
used to depict temporary complexity of
00:09:10
big o notation
00:09:12
the time complexity is mainly determined
00:09:14
by counting the number of steps required
00:09:17
to complete the task
00:09:19
let's take a look at an example to
00:09:21
understand this time complexity in a
00:09:23
much better way
00:09:24
if we want to find out a multiplication
00:09:26
of n numbers we can do it by executing a
00:09:29
loop from 1 to n then calculating
00:09:33
multiplication when the loop ends then
00:09:35
multiplication holds the n numbers
00:09:38
multiplication and last we return the
00:09:40
calculated multiplication
00:09:42
the loop statements time complexity will
00:09:45
be at least n and when the number of n
00:09:47
increases the time complexity will also
00:09:51
increase
00:09:52
while the code's complexity that is
00:09:54
returns multiplication will remain
00:09:56
constant because its value is unaffected
00:09:59
by the value of n and it will obtain the
00:10:02
result in every single step
00:10:05
next we will discuss about space
00:10:07
complexity which is expressed with big o
00:10:10
notation just as time complexity
00:10:15
these four items are stored in space
00:10:18
complexity it initially saves program
00:10:21
instructions then stores constant values
00:10:24
then stores variable values and finally
00:10:27
it keeps track of function cells jumping
00:10:29
statements and so on the sum of
00:10:32
auxiliary space and input size is used
00:10:35
to calculate space complexity the extra
00:10:38
space or temporary space used by an
00:10:40
algorithm is referred to an auxiliary
00:10:42
space after learning about algorithm
00:10:44
complexity we will look at some of the
00:10:46
algorithms pros and cons so let's start
00:10:50
with the advantages of algorithms
00:10:52
firstly algorithms are easy to
00:10:54
understand
00:10:55
next algorithms are step-by-step
00:10:58
representation of a solution and lastly
00:11:01
the problem is broken down into smaller
00:11:03
bits or steps in an algorithm making it
00:11:06
easier for the programmer now an
00:11:09
algorithm also have various drawbacks
00:11:12
one of which being it takes long time to
00:11:15
write hence it is time consuming
00:11:17
second con of the algorithm is
00:11:20
algorithms make it harder to demonstrate
00:11:22
branching and looping statements
00:11:25
so followed by the advantages and
00:11:27
disadvantages of algorithms we now enter
00:11:30
into the final segment where we discuss
00:11:32
the differences between algorithms and
00:11:34
programming so the first difference is
00:11:36
that
00:11:37
an algorithm is a type of programming on
00:11:40
the other hand a program is more
00:11:42
directly associated with the computer
00:11:44
performing one or more tasks but an
00:11:47
algorithm is more of a notation a
00:11:49
technique for solving a problem
00:11:52
now let us discuss the second difference
00:11:55
an algorithm can be decoded or run by a
00:11:58
human whereas the program is only run or
00:12:02
decoded by a set of compilers of the
00:12:04
computer
00:12:06
now the third difference
00:12:08
basically an algorithm is a design of
00:12:10
the solution to the problem
00:12:13
here we can only analyze the solution
00:12:16
but we can never run it
00:12:18
but whereas on the other hand
00:12:19
programming is completely a different
00:12:22
ballgame here you can directly implement
00:12:24
a certain phase or an entire program and
00:12:28
test the programs and get an output
00:12:30
so the fourth and the last difference
00:12:32
between an algorithm and programming is
00:12:35
an algorithm is written using natural
00:12:37
human vocabulary
00:12:38
whereas programs are written using any
00:12:41
programming language such as c c plus
00:12:43
plus java python etc
00:12:46
now with that we have come to an end of
00:12:47
this tutorial on what is an algorithm if
00:12:50
you have any queries regarding the
00:12:52
topics covered in this session then
00:12:53
please feel free to let us know in the
00:12:55
comment section below and our team of
00:12:56
experts will be happy to resolve all
00:12:58
your queries until next time thank you
00:13:00
stay safe and keep learning
00:13:06
hi there if you like this video
00:13:08
subscribe to the simply learn youtube
00:13:09
channel and click here to watch similar
00:13:12
videos turn it up and get certified
00:13:14
click here