 Welcome to the lecture on Analysis of Algorithm, Time and Space. At the end of this session, students will be able to list and determine the criteria for analysis of an algorithm, analyze a simple algorithm using step count method. We will also be discussing how to write an algorithm, what means analyzing algorithm, the criteria for algorithm analysis, time analysis, space analysis. Now, when we say how to write an algorithm, means consider the given example for algorithm swap AB, here if you notice this is a simple algorithm with three statements where the intention is to swap the numbers A and B and it is being done in a very simple way, here the use of curly brackets has been done to write the three statement, however the alternative way suggests use of begin and end with the same statements written in this format. Now the third format also for algorithm swap says the same thing, however here begin and end is replaced by curly bracket and here the assignment operator is replaced by arrow operator. If you notice the same algorithm is being written in three different ways, so what we want to convey here is there is no specific syntax for writing the algorithm, the algorithm has to be written in a way that is been understood by the programmer and the person who is going to use it, so as long as you use a conventions which are understood by both of them the algorithm is fine. Now we move to the analysis of algorithm, algorithms are nothing but the procedures for solving problem either manually or using computer, the criteria for algorithm analysis basically includes time, time means time function, how much time is the algorithm going to take, next is space, space means how much memory space is the algorithm going to occupy, third criteria is the network, if the algorithm is a part of network consider like uber, ola app, swiggy where these are the algorithms that are working on the internet and there is a to and flow of the data packet. Now this also needs to be considered, the fourth important point is the power consumption, when you are running specific apps for example google app, for going from one destination to other most of the time it is been observed that as there is lot of multimedia data involved in google map the power consumption is more, so much power is being consumed and finally the CPU registered, this is most of the time being ignored, however for our discussion the major criteria is time and space, so we are going to consider the time function and the space function, moving ahead when we see how much time will it take means it is not the watch time, it is actually the time required for the executing of the algorithm and how do we do this, we do this by considering the same example of algorithm swap. Now when we say we are interested in finding out the time, for this algorithm means here it is not the watch time, it is the number of steps, number of unit of time, now consider this statement if we see this statement requires one unit of time that is temp A, A is equal to B requires one unit of time, B is equal to temp again requires one unit of time therefore this entire algorithm swap requires three units of time that is function of f of n is equal to three units of time. Now we will consider the space analysis of the same algorithm, if we see here there are one variable that is A, the second variable that is B and here we have the third variable that is temp, each of this requires one unit of space and therefore we say that the space s of n is equal to three, when we want to convert it and what is this three, this three is nothing but a constant that is o of one, so the time complexity of this loop is o of one, also the space complexity is o of one that is constant. Now moving ahead to the next example, now the algorithm sum here you have the algorithm sum with A and n, now perform the addition of this array of n numbers, so here we have a loop, now when we say we want to analyze the working of this algorithm means that we have to understand how much function of time that is unit of time are required for executing this loop, now consider this statement this will require one unit of time, this statement will require n plus one, now how is this n plus one, this is because this statement will be executed for one time, i is less than one will be executed for n plus one time, means if the value is five it will check for five less than five also plus one, so this particular loop will be executed for n plus one time, now however whatever is inside this loop will be executed n number of times, so whatever is inside this loop will be executed n number of time, now it is important for us to understand that this algorithm after totaling we get f of n is equal to 2n by adding this execution of every step we will get 2n plus 2 that is p of n is equal to n, n is here nothing but linear that is o of n, now consider the third example for finding sum of two matrices here the algorithm add is given add a b n, now this algorithm has one for loop with i second for loop with j, now in order to understand and compute the time complexity of a nested loop we will execute this one after the other, when as in the previous example we have seen that the for statement gets executed for n plus one time and whatever is inside the for loop will be executed n times, so for that sake this statement will be executed n time, this second statement also will be executed n time, now for the second loop that is for j is equal to 0, j less than n j plus plus, this statement will be executed for n plus one time a senior, now whatever is inside this loop will be executed n time, so this n is of the first for loop this n is of the j loop, on performing the multiplication we get this n square that is 2n square plus 2n plus 2 that is p of n is equal to n square that is quadratic, now here we will understand and see the space complexity for the same program, as we can see here the variables that have been used here are a, b and c, the space is here required for n that is n square, b, n square and c, n square and for n it is x1, i it is 1 and for j it is 1, on adding this all variables we get s of n is equal to 3n square plus 3, so reducing it we have s of n is equal to n square, so we can from these previous examples we can trace that here when we have nested for loops the execution frequency goes on increasing, so for finding the sum of two matrices the time complexity t of n is equal to n square that is also the space complexity s of n is equal to n square, now pause the video for some time and solve the following code for finding the time complexity, the answer is n cube, as we have seen that nesting of loop causes the for loop to be executed n plus one time, here there are three loops and then multiplying by n into n into n gives you it as 3n cube, therefore on reducing that we have t of n is equal to n cube, these are the references, thank you.