1.1Characteristics of Algorithm
In this video we are going to discuss about characteristics of
algorithm. In order to solve the algorithm we have to write various
instructions algorithm means a finite set of instructions. Any algorithm
must contain five properties five characteristics one by one. The first
characteristic of an algorithm is input so input means an algorithm
must accept either zero or more number of inputs. The next
characteristic is output which means algorithm must produce minimum
one output. Every algorithm must satisfy these five properties are
these five characteristics in the next video we will see about we have
to consider various issues in order to study the algorithm we will
discuss the topic. The characteristic can also be called as property also
the last character the last characteristic is effectiveness.
1.2: Introduction to Algorithm & Syllabus
Discussion for GATE/NET & Placements
Preparation | DAA
Kovalchuk - one of the main course objective computer science car a
BA important QA EMF put those aspects is from Jonathan sub simple
expected competitive exams keep on it. hello those so gates which is
Baptists or get there it 's really some start Kennedy array algorithm
that is also called it da designed analysis and algorithm. Time
complexity and space complexity are the most important age of
portion are most important IQ key subsea rajababu. Time complexity is
related well of quicksort have merge sort and selection sort a bubble
sort insertion sort. Time complexities and on or ERP all sorting
algorithms are there. Make greedy methods 3d methods may have
opposite a job sequencing and knapsack optimal merge pattern a
Huffman coding a disaster algorithm a minimum spanning tree talking
about Karuma so sorry topics important of their lakin is Michigan man
analysis keep a spare key gate k exam paper do you see a net keep
whatever you say.
This is all about the introduction of the introduction and the syllabus
discussion of and good thank you. This is a porous syllabus to analyze
guru ki important tag that is all sorting and searching algorithms on
key time complexity and space complexity or is cathode or convenient
karna Kelly.
,1.3 How Write and Analyze Algorithm
Algorithms are the procedures for solving problem whether you do it
manually using pen and paper or you make a program and let your
machine do it. Algorithm should be time efficient means it must be
faster and faster so after reading the algorithms we analyze how much
time it is taking so that time what we get is in the form of a function.
These are the two major criteria on mr. algorithms are analyzed and
furthermore if you have any other criteria criteria. to move how much
memory space it will consume so that is the second criterion which we
will analyze an algorithm. Data transferred or network consumption is
also important criteria how much data is going to be transferred see if
the algorithm or means if a procedure that you are writing if it 's
unnecessary transferring to larger size data. Each statement takes one
unit of time and each variable is taken as one word. The analysis is at
basic level but at a very shallow level this base analysis we will do will
not go into much detail but much detail analysis can to be done next
just space analysis what are the variables used here for a space and
rent.
It may be a teacher type or float type or double type that we do n't
know so that's why we say it is taking words. planning it converted to
a program it may have been a program. planning to be a program
instead of a program, it may be teacher type.
1.4 Frequency Count Method
The time taken by an algorithm can be known by assigning one unit of
time for each statement and if any statement is repeating for some
number of times the frequency of execution of that statement will
calculate and we find that time taken. Alberto did some algorithms and
find out how this method is useful for five to ten complexity of
algorithms this algorithm is for finding sum of all the elements in an.
Whatever is written in the loop like this type of loop the statement
legible for n times and the loop itself if you take it will execute for n
plus 1 times then the last statement it will make you for one time.
Whatever is there inside this loop will is u4 n times this is and two legs
are two statements are they each is taking and then what is this again
the Zulu. The time and the space complexity of this algorithm is N
squared how to find the time complexity I have shown it here. Next
algorithm is multiplication of two matrices you can see that there are
three loops nested one inside one one inside another let us find out
the time on this side.
,1.5.1 Time Complexity #1
I relate few pieces of code and show you how to analyze them how to
find out the time complexity for them this is a simple loop I am not
reading a complete algorithm I have this written a piece of code in
which one statement is there but we are already familiar with this one
we know that this will execute for n plus 1 9 and this way is good for
and we do n't want this time because anyway when we are at the
order of be writing a degree so this will not affect the degree at all so
it will be same only so just you need to move the statement how many
times it is executed so that 's it so this is order of n you can avoid this
one here I have to find out how many times the statement is executed
so number of times so it will not execute at all so 0 times then this
loop ends again I am plus plus plus I becomes 1 I am less than n in
suppose it 's enters inside then again this group 0 0 is less than 9 yes
then J plus plus J is 1 1 1 is not less than I so for 1 it will execute so
many times it has executed one time and then goes up again. this will
be 4 2 times and when I is the 3 J will take 0 1 2 & 3. Tracy says he
hopes K square is not reaching it is not repeating for n times definitely
it is red waiting for some number of times so that we do n't know we
are sure that it still not execute for n. 4 goes on how many times it "s
going to execute it 's going on K times so what this will be 1 plus 2
Plus 3 plus 4 plus goes on to K time. Tracy: In the next video we 'll find
more examples right so different type of course I will show you and I 'll
show you how to analyze them so this is all by tracing you canonized n
so in the other video next video also you can find few more algorithms
that
1.5.2 Time Complexity Example #2
This is the time complexity so the statement will execute for order of
log n base 2 times so from this we can observe that if you have a loop
where the counter variable it 's not implementing but it is getting
multiplied by something let us say 2 or 3 then it will get log base 2
time so you'll execute form operates two times. K that will be equal to
n so K is how much log in these two so the other we have analyzed this
one. If you have any look like this the value of I is getting multiplied
then it is going to take log and time. If a rent of n value at 10 let us
see what happens is initially 1 1 is less than 10 now n value is at 10
once less then 10 continued its multiplied by 2 so 2 is left then four
four is less then eight multiplied with it is 8 8 is also connected then
16. If I find log eight log interval between how long eight is written as
two for three days. The previous one in the first example I have shown
you that it was multiplying time and starting for a month now this is
dividing every time starting from N and and up - what up - 1 it is
, reaching so it 's part of login makes these fullest. The time complexity
for this one is this is independent rule and it is situated for n times.
Order of n is order of n and whatever is they recite will repeat for and
times next the in the follow this is using j j j is less than n and j is
every time x 2 right so this is a friend a login time and anything inside
that also will take login time if remember initially I've shown you that
this is mistakes n plus 1. Our loop is incrementing that is n or
decrementing it is and whether it is in demanding by one hour two or
even ten or even hundred also it 's sort of Emily 's same weight and
my rules also order of N and by 200 is also order.
1.5.3 Time Complexity of While and if #3
In C language there are three loops while and do-while there is
a difference though while will execute minimum one time but
follow fine while loop. Before C language he has languages
used to provide for loop in a different way let us see that follow
for I assign one to M do some statements inside and this is :
here this was the syntax in Pascal language. in old languages
they used to be a loop called repeat some statement inside
and under some condition now these loops were different
repeat until loops are different this will repeat as long as a
condition is false and once the condition is true it will stop so it
is similar to do while how minimum one time the statement is
but it is different compared to Dubai. for n time total how many
3 n plus 2 but when I was using for loop I was saying that let us
ignore these two and just take it as n plus 1 so I was. saying
that it was 2 n. plus 1 whatever the function may be we are not
interested in exact formula or exact function we are. interested
in the degree of a function so we say order of n now that 's it
now you can see whatever I can write using while loop I can.
write it using for loops also now our next piece of code here
see a assign 1 while a is less than B some statement and a is
multiplied by 2 every time there is no n here then how many
times
Using while loop you can also do it using for loop in C
language. In so for loop just you can reframe them as while
loop let us take one more example again a loop is there while
loop and in this while loop I is starting from N and I is dickweed
getting divided by two every time so again the time will be log.