[00:01:08] Okay, so good morning everyone. Siddhant, so just clear the lobby when some people are there. Still I am just, this is just gentle reminder to everyone. Please join via your ITP ID. So it will not lead to wait in the lobby as well as there will be no issue with the attendance and all other stuff. Okay. [00:01:31] So, in the last class, we were discussing about different properties that we may encounter [00:01:48] while solving the or doing the algorithmic analysis. [00:01:53] So, we talk about monotonicity, we talk about factorial function, we talk about monotonicity, [00:02:04] we talk about modulo function, we talk about integer, we talk about this [00:02:18] factorial and Fibonacci series. And a number of other, we talk about the logarithmic property. [00:02:30] We talk about exponential. So these are the very basic property [00:02:39] that we talk about floor and ceiling. So, this floor and ceiling will appear again and again [00:02:44] in different set of algorithm that we will cover. So, these properties why we have covered so far [00:02:50] because some of them will directly or indirectly use during the algorithmic analysis. [00:03:01] Then we talk about the component of the algorithm like start and end statement, [00:03:06] there will be a control structure and other stuff. So that already we have covered. [00:03:13] Then we talk about the three types of control logic. So it could be sequential, it could be [00:03:21] selection or it could be iterative. So sequential means that 1, 2, 3, 4, 5, 6, 7, 8 and so on [00:03:29] will go like usual. But when we talk about the selection logic, so that is important. [00:03:37] So that does not follow the normal flow. So let us say it is 1, 2, 3, then it can be 17, [00:03:45] 20 and so on. So it depends upon the specific condition. When a certain condition meet, [00:03:51] so it has certain set of conditions. It has certain set of conditions that we need to [00:04:10] fulfill. Similarly, we have an iterative logic. So for iterative logic, we can say for loop, [00:04:17] we can say while loop. So all the loops specifically follow, will execute, will let [00:04:25] say print something, then check the condition and then print something and so on. So [00:04:41] So sequential logic is very basic, we have to follow the steps, then selection depends [00:04:50] upon the different state or the condition that we have to meet and then for loop and [00:04:56] while loop are there for reflecting the iterative logic. [00:05:00] So this already we have covered. [00:05:09] let us start the important topic that is algorithmic analysis and runtime. [00:05:15] So as we know, we are studying this designing analysis of algorithm. So [00:05:32] what is analysis of algorithm? Design means that we have to build a code or we have to write a [00:05:38] function for performing certain operation. But in case of designing already we have [00:05:44] around 146 algorithms that are given in the, this course as well. So, you can design of your own. I [00:05:54] will tell about some of the, at some stages how you can make an algorithm or what could be the [00:06:01] relevant topic or what could be the relevant problem for which you have to write the algorithm. [00:06:07] So, that come under the category of designing. So, designing is not tough, but analysis is [00:06:15] little bit tough. So, what is the goal of algorithmic analysis? Let us say I float a problem [00:06:22] P to 4 people. So, 4 students, I can say S1, S2, S3, S4. Now, all had write their code C1, [00:06:42] C2, C3, C4. And now I am a judge or a teacher. I want to evaluate who has written correctly. [00:06:51] So surprisingly what I found that all 4 L code, 4 codes that is C1 to C4 are perfectly fine [00:07:04] and working. Okay. There is no bug. All the 4 codes are running. Now a question arises, [00:07:17] how I will determine which code is superior and which code is inferior? Okay. So to do so, [00:07:24] we have to analyze the algorithm okay and determine the complexity of algorithm how it will [00:07:32] behave when the value of the input size increases when the machine changes and number of stuff [00:07:38] but the important consideration is that we want to develop a theoretical and [00:07:51] we want to develop a theoretical and platform independent analysis model. Okay, so that is [00:08:17] important. If I have to, let us say if the number is 20, 30 or in millions, the algorithms are [00:08:25] available. So which one is better for me or which one is best among them that we have to decide in [00:08:32] such a manner that we do not rerun the code. By just doing a theoretical analysis that also offer [00:08:40] platform independence, we can do the analysis of the algorithm. And here it is written algorithmic [00:08:47] analysis and runtime. So we will try to identify the theoretically identify the runtime. [00:09:03] okay and that will help in doing the analysis of algorithm that is platform independent okay [00:09:12] we need not to mention because we know that let's say two people have makes exactly same algorithm [00:09:18] and one is running on a low configuration device and other is running on a high configuration [00:09:23] device so obviously the high configuration device will do the things fastly okay so similarly [00:09:31] someone using a hard disk drive in their code for fetching the value and someone is using solid state [00:09:38] drive then of course the speed is high so in this manner we cannot say that the algorithm [00:09:44] is poorly developed by someone so here it is dependency on the platform so we have to also [00:09:49] think about the analysis that we are making is platform independent okay so algorithmic analysis [00:09:59] So let us see some theoretical aspect, then we will talk about the practical aspect of this. [00:10:04] So algorithmic analysis is the process of evaluating the performance of an algorithm [00:10:12] in terms of efficiency and scalability. That is important aspect. Efficiency, scalability means [00:10:18] that when let us say we assume the as the input size, for example, in a linear search, the size [00:10:26] of array is 20. In linear size, the size of array is 100 and so on. So that becomes the [00:10:32] input size. Okay. So input size. Okay. So how your algorithm will behave with respect to [00:10:42] the changing input size will be treated as scalability. Okay. Scalability means that [00:10:48] when I make an algorithm for 10 number, it is also applicable for 100 number. It is also [00:10:54] applicable for 1000 number and so on. And efficiency means that how much time the algorithm [00:11:01] will take to execute the code. So efficiency means that time taken by algorithm to run. [00:11:22] Time taken by algorithm to run. So algorithmic analysis is the process [00:11:27] of evaluating the performance of an algorithm in terms of efficiency and scalability. That is [00:11:34] important. Second thing is that the primary goal of algorithmic analysis is to understand [00:11:40] how an algorithm will behave as the size of input data increases. So let's say two people P1 and P2 [00:11:49] are there okay and both are working on n equal to 10 10 elements are there okay and if if they [00:11:59] has written algorithm a1 and a2 okay and we cannot determine how efficient a1 over a2 because the [00:12:09] size of n is very small but when n becomes let's say 10 000 then you can easily see the difference [00:12:17] And you can say a simple example if you want to consider, just do a factorial 5 [00:12:27] and do factorial 25. So you will see the difference in the time of execution. The clock [00:12:34] difference will be definitely there. So you can just attempt and what it will clearly indicate [00:12:40] when the size of input increases, the computational complexity automatically [00:12:45] increases that is the scalability aspect. So now, next one of the common approach [00:12:52] to algorithmic analysis is to measure the running time of the algorithm as a function of input [00:13:00] that we want to identify. So what is the basic mode of operation here is, we will try to, so [00:13:08] let us say an algorithm is given, an algorithm is given, an algorithm is given, then we will try to [00:13:14] identify a function that reflects best the algorithm and that function also says how your [00:13:24] algorithm will behave when the size of input changes. And next thing if you see the time [00:13:32] complexity of an algorithm can be analyzed theoretically by analyzing the number of [00:13:37] operation the algorithm perform as a function of input size, as a function of input size. [00:13:58] So, for example, if I just write a code for i equal to 1, i should be less than or equal to 10, [00:14:14] i plus plus okay and inside this loop i am doing what i am printing i okay simply i am doing this [00:14:29] so and here i have done some int i okay so now this for loop will run for how many times this [00:14:41] will run for 10 successful and 1 failed case when value become 11. So, totally this loop [00:14:51] is running for how many time? 11 time. So, what we can say that the function fn for this [00:15:03] entire algorithm is how much will be somewhere 10. Similarly, when we run for 100, then it [00:15:12] will become 100 plus, 10 plus 1, this plus 1. So overall, if you represent a function [00:15:17] fn for this algorithm, that will be n plus 1. So the computational complexity will follow [00:15:23] the simple function that is n plus 1. Or when n become very large, then we can say that [00:15:30] it is equivalent to, it is equivalent to n. So when input is 10, the algorithm will 10, [00:15:38] is 100, algorithm behaviors will run for 100 times, 10,000 times, millions time and so [00:15:44] on. [00:15:45] So here basically what we have did, we do not run this code, just do a dry run and identify [00:15:52] how many time it will run and convert it into the form of a function fn. [00:15:58] So similarly, other factor that affect the performance of an algorithm that obviously [00:16:05] we are not going to cover is the use of memory. How much memory the algorithm needed? So, [00:16:11] this we will see, this is just one among it that we will, we can accommodate. So, in case [00:16:19] of merge sort that we will cover, do not worry those who are not aware of. Merge sort, they [00:16:25] use extra memory, extra space for storing the result. The use of parallelism, how you [00:16:33] can ensure that your algorithm will run in parallel. Use of heuristic and other optimization [00:16:41] techniques will also reduce the computational complexity or will determine which algorithm [00:16:48] is suitable or best among the all. These factors can be, there are other tools, [00:16:59] can we understand the performance of algorithm and design efficient algorithm for a complex [00:17:05] problem. This is important aspect if we understand how the algorithm behavior changes over time [00:17:12] using this theoretical analysis, then we can design an optimized algorithm. [00:17:19] Now, let us talk about in detail. Suppose we have M is an algorithm and suppose [00:17:29] n is the size of input. So let us say there is an algorithm which name is m and it [00:17:39] accepts the n that is the size of input. Simple size of input example you can take, [00:17:47] you have to sort 10 number then n is 10, you have to sort 20 number then n is 20 and so on. [00:17:55] Okay, so that is not a big deal. So n is the obviously the input size and one more thing that [00:18:03] this n is what input size in my algorithm except one number, two number, three number, four number [00:18:09] is always a positive integer that is important. Okay, the entire analysis that we will study [00:18:17] will assume the input size to an algorithm is always a positive integer. Okay, [00:18:24] So, there may be the cases where we can say that n is, you can say floating or fractional, [00:18:31] but that is not considered in the analysis. Now, so our algorithm name was m and it, [00:18:51] n was the input data. So, the time and space used by an algorithm m are the two main measures for [00:18:58] efficiency of the app. So, two main major, important one is time and another one is space. [00:19:05] But we will primarily talk about the time. Now, time is measured. How time will be measured? [00:19:16] It will be measured by counting the number of key operation. Important aspect is that [00:19:22] in algorithm there is assignment, there is for loop, again there is some assignment, [00:19:28] then there was condition check that is less than 10 or something. So, in sorting and searching [00:19:36] the number of comparison will be treated as your dominating or the primary operation. [00:19:42] That is important, dominating or you can say primary or key operation. So, let me take [00:20:02] Take one simple example for this. [00:20:06] If we did one multiplication and several others addition, so when you, when I say which one [00:20:15] is more complicated, then obviously you will say the multiplication is more complicated [00:20:20] and we can say that it is dominating operation. [00:20:25] If you increase the number of multiplication in your code, so your complexity will increase [00:20:31] and let us say some student come and write a code that is having very few multiplication [00:20:37] and more are addition and subtraction, then efficiency of that algorithm is much, much [00:20:42] better than that of that is using more number of multiplication. Similarly, in case of [00:20:51] searching and sorting algorithm that we will cover after some time. [00:20:55] Okay, so that we will cover after some time where the comparison is the key operation [00:21:02] because assignment is what we are, we have a value in which we have given some number. [00:21:08] So that is just a address redirection. [00:21:11] But in case of comparison, first what we have to do, we have to convert both the values [00:21:16] in the binary equivalent and then compare bit by bit and then declare a result whether [00:21:21] the particular thing is happening or not. [00:21:24] So therefore, in case of searching and sorting algorithm, that will be the primary algorithms [00:21:29] that we are going to cover, the number of comparison will be treated as the dominating [00:21:35] operation. [00:21:36] So, if you see back, so here number of comparison is how much, 10 for the success case and one [00:21:43] for the failed case, the total number of comparison is 11. [00:21:46] So this algorithm if you see the computational complexity was also turning around the number [00:21:54] of comparison that we were making. [00:21:56] So that becomes the dominating operation or we can say that key operation or we can say [00:22:10] dominating operation will consume most of the time to run the algorithm, to run the algorithm. [00:22:39] So, what is specifically we are trying to convey here, the key operation are so defined that the [00:22:46] time for other operations is much less than that of most proportional to the time of the key operation. [00:22:54] For example, multiple addition does not cost more, but multiplication will cost more. [00:23:01] So likewise, comparison will cost more, assignment will not cost more and so on. [00:23:15] The space measured by counting the maximum memory needed by the algorithm. So that is [00:23:21] important aspect. The space measured by counting the maximum number of memory needed by the [00:23:28] algorithm okay so this already we have understand the complexity of an algorithm m is function of [00:23:39] fn which gives the running time and or space requirement of the algorithm in terms of [00:23:45] size of input data that is important part whenever we determine a function fn that reflects the [00:23:51] property of fn. So that will show how your algorithm will behave, how your algorithm [00:24:05] will behave when input size increases or changes. So this is important question. [00:24:21] This function fn that resembles the algorithm will try to identify how your algorithm will behave [00:24:30] when the input size increases. So, Fn is the function of input size n that showcase how [00:25:14] your algorithm will behave with respect to the key operations, will behave with respect [00:25:42] to the key showcase, how your algorithm will behave with respect to the key operations [00:25:48] over input n. So, that is important. We have to always identify in an algorithm which operation [00:25:58] is a key operation. So, for searching, sorting, the key operation is comparison. The key operation [00:26:14] is comparison. So, here the space required by an algorithm is simply the multiple of [00:26:22] data size. So, in case of merge sort, we will see the space complexity is 2n because it uses [00:26:31] one more space for execution. So, here this line is important, unless otherwise stated or implied, [00:26:41] the term complexity shall be referred as runtime, not space complexity, we will say as [00:26:49] the time complexity now one important aspect that is remain challenging is that [00:27:03] those who have studied algorithm before they know there are something best case [00:27:09] average case this we will talk about just after this or worst case now one thing we understand [00:27:16] how our algorithm fn will behave when input size and changes okay but let us talk about a situation [00:27:27] okay okay i had one array here numbers are seven nine three two five twenty one thirty one the [00:27:41] The number is 1, 2, 3, 4, 5, 6, and 7. [00:27:46] This is Eric. [00:27:48] Now I ask search 9. [00:27:55] Then you will find here just only 2, 3 comparisons we performed. [00:28:00] Okay. [00:28:00] Similarly, I ask search 21 or search 5. [00:28:08] Then it will take some more comparisons. [00:28:10] Then you can find 21 or 5. [00:28:13] Now I say search 31 or 41. So, 31 we have to do comparison with all and then we will [00:28:25] reach to the 31 or for 41 we can say that 41 does not present in the array after being [00:28:33] comparison all the elements. So, what does this indicate? This indicates that we have [00:28:40] design algorithm fn has in a computational complexity and with respect to the input n [00:28:46] but where we are getting the value will also matter so here for searching 9 we can say that [00:28:51] the situation is the best situation but searching 21 and 5 it could be an average situation and for [00:28:58] searching 31 and 41 it could be worst situation worst situation means that we have to perform [00:29:03] all the comparison and then only the element is identified or does not identify at all [00:29:10] but when we encounter the element in a very beginning of the array, then it would be the [00:29:14] best case because here the algorithm will stop. And average case is in between the best case and [00:29:23] the worst case. So, exact position we cannot declare that if I will search in the middle, [00:29:28] it will be average case. It depends upon the best case and worst or it is something in between the [00:29:37] best case and worst case okay so we will talk about what is best case what is worst case what is [00:29:43] but every time remember this simple example we have to search a particular element [00:29:48] in an array and if we encounter in first or very initial stage then we can declare that we are in [00:29:55] the best case worst case means that we we have to perform all the comparison and at last we [00:30:02] encountered the element or the element is not there. And the third aspect is the average [00:30:09] case so that we can say that is somewhere in between best case and worst case. So because [00:30:15] average case estimation is a challenging stuff that we will talk in the next examples. [00:30:22] Now here is written. Let us say we had a story. If we had an English story [00:30:29] whose name is TEXT, text. And someone say identify the occurrence of three word letter [00:30:41] that is the. So obviously, it is a story that is based upon the text. So we will definitely [00:30:51] find the in the, you can say very initial stage. [00:31:02] And similarly, when I say identify Jew in this text, so maybe possible Jew is not there. [00:31:09] So that will be that what we will do, we have to search till last, search till last. [00:31:20] So that is important part, if for this Jew, we were searching all the entities and further [00:31:29] we encountered it very soon. [00:31:31] So same text, same algorithm, behavior changes because of the, we have encountered TH in [00:31:39] the very earlier and ZOO does not present in the text. [00:31:45] So this means that when we encounter in very initial stage, so that becomes the best case [00:31:50] and the second condition becomes the worst case. [00:31:54] And if we identify elements somewhere in between or somewhere at any location, that is not [00:31:59] the best case and not the worst case then we will declare it as the average case i hope you people [00:32:05] can visualize what is best case what is average case little bit not analytically but of course [00:32:11] theoretically you got some idea key what is this these cases okay so here it is written algorithmic [00:32:21] analysis and runtime worst case the maximum value of fn for any possible input okay we have explored [00:32:28] all the possibilities average case is the expected value of fn that we will understand [00:32:33] because there is no clear or fine boundary for expected value okay for average case [00:32:41] and base case we also consider minimum possible value of fn so this is the best case so for [00:32:46] example we were searching the and we were searching jute uh today i'm not taking your [00:32:56] queries because let there is some theoretical aspect that i will cover then i will take your [00:33:00] query and and and start doing the you can say mathematical aspect or numerical aspects of this [00:33:07] one okay so analysis of average case assume okay so well i'm taking a two three minute break then [00:33:15] again come back so just see this slide okay if anyone has any query let me know okay otherwise [00:39:42] we'll continue so today it is going a little bit theoretical but that is important because [00:39:46] uh when we do the algorithmic analysis and other stuff so these these statements these theoretical [00:39:52] things is needed so siddhant if anyone has any query let me know otherwise we'll continue [00:39:57] okay no worries uh we'll come back again for the queries okay so uh analysis of average case is [00:40:25] little bit tricky okay and assume that is important if you write and assumes a certain [00:40:32] probability, probabilities, distributions for the input data. Because let us say we had 20 positions [00:40:39] from on which we can identify the element. So, each positions are not equally probable. [00:40:46] Some positions had high probability of getting an element and some. So, that is you can say that [00:40:51] becomes a little bit challenging or complicated to think about those aspects. Now, one such [00:41:00] assumption might be all possible permutation of input data are equally likely. That is very [00:41:05] important. That is very easy you can understand. So if we assume all the positions are equally [00:41:15] probable. So your expected value initially when we are saying each have some probability p1, p2 [00:41:24] and so on. So it is n1, first position into its probability, second position into probability, [00:41:29] last position into probability that is the expected value. And what earlier it was written, [00:41:33] the average case is the expected value of f of n. And here is an example. If we are assuming all the [00:41:43] probabilities of 1 by n, 1 by n, then we can reach to some situation. So that we will discuss [00:41:50] with this example. So I hope you people can now visualize that the complexity of an algorithm [00:41:58] depends upon the input size okay simple example in a linear search we are searching in 10 place [00:42:04] 20 place 30 place 50 place so that places will be deal as the input size okay or we have to sort [00:42:11] certain set of number when we are taking 10 number 20 number thousand number 10 000 number [00:42:16] so that becomes the input size so one thing is clear the complexity of an algorithm increases [00:42:22] with respect to the input size second thing now it is clear that if if we are taking the minimum [00:42:28] value of fn then it becomes the best case and maximum value of fn we are employing then it [00:42:34] becomes the worst case and in between there will be an average case that will be dealed as expected [00:42:40] value okay now we will actually talk about how to let's say your algorithm was m so how to obtain [00:42:48] f of n. That is important because directly for an algorithm, we cannot determine the [00:42:53] computational complexity. We have to first determine the function fn that best represents, [00:43:01] best represents the algo, the function that represents the algo in terms of input size. [00:43:18] Now, here is a simple linear search algorithm. Linear search means that we add an array [00:43:24] and there are some set of values in it. And I ask you to identify a key value. Okay. Let's say [00:43:32] 29, 30, anything depending upon the number. So, what I will do, I will check with first. If it [00:43:37] is the given number, no, then I will check with second. Then I will check with third. Then I will [00:43:41] check with fourth, fifth and so on. So, up till we obtained the key or we are in the last position [00:43:47] and we never obtained the key. So this is simple, the concept of linear search. We have to search [00:43:54] a specific element from a given array. And what we will do, we will start comparing with the first [00:44:01] element and if and keep on comparing and this comparison will run up till we have encountered [00:44:11] the specified key element. Otherwise, the algorithm will go till last and declare that the element is [00:44:18] does not present. So what we say that comparison was key operation and here what we are doing, [00:44:24] we are comparing key with first entry, second, third, fourth and if it is not present then [00:44:30] n entries. So the comparison is performed n times therefore the computational complexity reaches to [00:44:38] order of n. So let us understand this problem and try to identify the computational complexity [00:44:44] for this one or basically we will target f of n. So the linear array data with n element [00:44:53] and a specific item of information are given. This specific item of information is the key. [00:45:00] The algorithm find the location loc of the item in data and or set location 0. Set location 0 [00:45:08] means that the item or the key is not available. The item or the key is not available. Okay. [00:45:24] So here we are initializing two things k equal to 1 and k L O C equal to 0. So this will [00:45:29] run for how many times? This will run for one time. Similarly, here there is a repeat [00:45:35] step 3 and 4 while L O C equal to 0 and k is less than or n. So what will happen here [00:45:41] basically we are doing if item is equal to data k otherwise what will happen the loop will [00:45:47] increment the loop will increment so how many times this this statement will run this will [00:45:52] run for n plus one time this statement will run for n time this increment will run for n time [00:46:01] okay and at last if loc is zero then we are declaring that item is not present [00:46:06] one time one comparison this is else is running for one time and this is executed okay so overall [00:46:16] what we can see that the statement number two three four are running multiple time and here we [00:46:23] can also see if k is less than one is a comparison operation okay and here in if also there is a [00:46:32] a comparison, but that is just one. So overall, if I write the thing, so this step run for [00:46:39] one time, this step run for n successful and one unsuccessful. So that is n plus 1. Internal, [00:46:47] these two statements will run for n plus n time. This if loop is running for one time [00:46:53] and the else is running for one time. So overall, it becomes n plus n plus n that is 3n plus [00:47:01] 3. This is the f of n for this algorithm, simple to determine. Now, if I take n tends [00:47:10] to infinity, then this f of n becomes n because this is the dominating part, this we can eliminate. [00:47:19] So, therefore, if you have heard the computational complexity of linear searches order of n. [00:47:26] you have any issue in this let me know okay any doubt to anyone how we are getting three and plus [00:47:47] three oh siddharth enable mic for them those who are raising hand no one is raising hand sir okay [00:48:01] okay yes yes um i have allowed his mic sir yeah yes you are audible be louder be louder yeah good [00:48:18] good morning sir am i audible yes yes you are audible sir can you please explain this loc1 [00:48:25] what is loc location loc is location just nothing else it is the location zero means that [00:48:31] we have started or we does not obtain that key element loc is means location it's just you can [00:48:38] say it's a kind of flag we are using okay so location is zero means the actually i am not [00:48:48] i'm not having this background so just no no so what i initially said key this is the increment [00:48:54] counter k equal to one and this loc is initially set to loc means that we does not know the location [00:49:00] of the key so i just declare it zero initially okay and what we have to check if location is [00:49:06] still zero and value of k is not equivalent to the n that is the number of size of this one okay [00:49:14] then we will check these two conditions so loc you if you are not if you are confused you can [00:49:20] also eliminate this that is not a issue okay if you don't encounter the element we have a raise [00:49:25] of flag that's value is zero if we encounter element then the value of the flag will be one [00:49:31] and if the value is one here it is then what we will do we will write that the element is present [00:49:37] okay okay thank you sir one more doubt one more patient yeah you have mentioned that uh in the [00:49:45] for loop when i is equal to zero and i is less than three then the loop will run for four times [00:49:52] yeah yeah so so how how it is so um three time is clear to you it will run for three times yes [00:49:59] yes okay so but if i is after last increment the value of i becomes four [00:50:06] there the loop fails okay that you agree yes yes yes okay so the fail condition is also [00:50:13] because we are also doing a comparison whether the four is less than or equal to three so that [00:50:20] at that time it say the condition fails but at that time we are making one comparison therefore [00:50:25] the loop will run for one extra time in terms of comparison because we are determining the [00:50:31] computational complexity so we have to count all the comparison that we are performing so [00:50:36] therefore it is running for one more time that is a failed case thank you thank you okay i guess [00:50:49] we are good to go today's class is a little bit we have served two three more and it's okay we'll [00:50:57] take we'll take arun i have enabled your mic hello sir hello hello hi yes you are audible be louder [00:51:13] sir again this algorithm i'm not getting your voice clearly am i audible ah yes you are audible [00:51:29] can you explain again i will i will do this okay yeah how to find three and plus three i will [00:51:36] explain don't worry yeah yeah any other doubt i will uh re-explain it don't worry those who are [00:52:04] taking that okay so okay let me re-explain this then i will take the queries okay okay so let me [00:52:25] remove this stuff okay so now um we had a array whose name is data okay and that is this one [00:52:49] where elements are stored. E1, E2, E3, E4, E5, E6 and so on. We have to identify an item of interest [00:53:04] item that could be any EI. So, what we will do? Basically, we will start from the first position [00:53:13] and compare. If we found it is there, then we will declare the result. Otherwise, we will keep [00:53:19] on comparing, keep on comparing. And if we reach to the last position, then we declare that the [00:53:25] element EI that what you are shouting is not present. So here one more thing, data is an [00:53:32] array or list of element, item is the key value that we want to identify and LOC is the just [00:53:40] location we are declaring. Just location flag you can say that is location flag. So don't worry [00:53:48] about it is location specifically here i am starting with location one two three four that [00:53:54] is the indices so you can say loc zero is at the zeroth index and we are starting with first index [00:54:00] so whatever the index it will be captured whenever the element is present it will be captured by loc [00:54:06] but primarily loc is a flag value that that indicates the value is present or not present [00:54:23] or not. That is 0, 1 condition. If it is 1, then value is present. If it is 0, then value [00:54:29] is not present. So, what we do? We do a initialization. So, this will run for one time. Just we have [00:54:36] said k equal to 1 and LOC equal to 0. Now, this 3 to 4 statement, it is saying repeat [00:54:43] while LOC is 0 and k is less than or equal to n. So, what basically it is doing, we are [00:54:51] starting from 1 and going to n. And one time when it become n plus 1, then the condition [00:54:58] fail or when LOC is 1, then the condition fail or LOC is greater than 0, then the condition [00:55:06] fail. So, this loop will run for how many times? n plus 1 time. Inside this, this if [00:55:12] comparison will be done for how many times? n time. This set k equal to 1 will run for [00:55:17] how many time? N time. This while loop will, if or if will run for 1, though there is a [00:55:23] comparison, but it will run for 1. Similarly, else will run for 1. So if I aggregately add [00:55:28] them, then what I will get? 1 plus N plus 1 plus N plus N plus 1 plus 1. So we will [00:55:38] get total 3n plus 1, 2, 3, 4. Here we are getting 4, no worry. I am concerned. So what [00:55:48] we are getting? The computational complexity as f of n as 3n plus 4. But when n becomes [00:55:56] very large, then this becomes, this is equivalent to n because this is a constant number and [00:56:03] this, the variable is n. So the computational complexity of linear search become order of [00:56:09] n. So for any algorithm to determine the computational complexity, we have to identify [00:56:15] the operation that is running for longest time that is the and here the loop is running for [00:56:21] longest time which also holds the comparison operator and therefore the computational complexity [00:56:27] of this algorithm becomes 3n plus 4 or 3n plus 3 because 4, 5, 3, 7, 8 are the constant and when [00:56:37] n become very large, then the impact of these values will vanish. So, I hope you people can [00:56:44] now get some idea how to determine the and for other algorithm as well, we will talk about like [00:56:50] this, how we can determine the f of n for this. So, in worst case, what will happen in worst? [00:56:59] yes any doubt no sir okay thank you so in worst case what will happen this loop will run till last [00:57:14] okay and in best case what happened let's say we encountered the element in the very beginning [00:57:19] then the loc value change and we will directly jump to this situation okay so and the in case [00:57:27] of average case, this loop will run for limited number of times rather than running for all [00:57:33] 3n, it will run for less number of times. So we can say that the dominating operation will be [00:57:41] the operation that is performed repeatedly and also hold the comparison. So here the comparison [00:57:47] is being performed. So worst case will be number of comparison will be n and the worst case will [00:57:57] be f n will be some constant value 3 4 fifth position we have identified and for average [00:58:03] case we are assuming all the locations of getting the number is equally probable and the order is [00:58:10] n plus 1 by 2 or that we can equivalent to n by 2 and when n become very large very very large [00:58:19] this n by 2 becomes n when n tends to infinity so n by 2 is also infinity okay so that is the [00:58:27] important observation that we have made, worst case complexity and average case complexity [00:58:33] becomes equivalent when n is a very large value, n is very large value. [00:58:44] So here is one important observation we can also make, the complexity of average case [00:58:49] of an algorithm is usually much more complicated to analyze than that of worst case. Worst [00:58:55] Worst case means that we will go to the last and declare, but average case is moving here [00:59:00] and there in between, average case is moving here and there in between. [00:59:10] So we can say that in most of the cases we will observe that we are talking about the [00:59:16] worst case because worst case is the maximum time your algorithm will take for execution. [00:59:23] So worst case, if we know the worst case, what is the maximum time taken by an algorithm? [00:59:30] So obviously your performance will be better or equivalent to it. [00:59:34] Worst case is the maximum time taken by the algorithm for execution and assuming probability [00:59:59] distribution again make the condition little bit more critical. [01:00:03] So therefore, in most of the cases you feel you will find that the when we talk about [01:00:08] the computational complexity, we talk about the worst case scenario. [01:00:15] Now, growth of function, growth of function means that we have determined this 3n plus [01:00:27] 3, but that is not a well known function, this is a specific to algorithm. [01:00:32] But we know if we, it is equivalent to n, then n is a function, n square is a function, [01:00:37] n cube is a function and 2 to the power n is a function, factorial n is a function. [01:00:45] So here if you see growth of a function, so these are the well known function log n and [01:00:51] these are the well known function. So whenever we got any fn for an algorithm, we will try [01:00:58] to identify a well known function and if they are equivalent for a higher value of n, then [01:01:04] our task is done. So, for example, the linear search has an order of n because we have eliminated [01:01:10] 3n plus 3 or 4 because we are assuming the n is very large value, n is a very large value. [01:01:20] So, if you see here how these functions behave log of n base 2n log of base 2n log n n square [01:01:31] n cube and 2m so when n is 5 its value is 3 5 15 25 125 32 when n is 10 it is 4 10 40 100 10 cube [01:01:43] 10 cube when n is 1000 still if you can see log value is 10 it is 10 to the power 3 this 10 to [01:01:53] the power 300 so this means that if your algorithmic complexity is log of n it is very effective so [01:01:59] when we see the tree algorithm we will find the largely the algorithms are following the log of [01:02:06] n order for linear search it is obviously acceptable if you if you see it is going just [01:02:13] equivalent with the value then there is and most of the algorithm sorting algorithm will follow [01:02:17] analog n okay and there are some algorithms that will also offer n square and n cube okay so now [01:02:25] This is how a function grow and here our target is to identify a known function g n [01:02:42] that resembles our estimated function f n. So like 3 n plus 3 is as equivalent as n for a [01:02:50] larger value of n. I hope you people understand the growth of function. Now the important topic [01:03:00] come into the picture that is asymptotic analysis. Here this is was an algorithmic analysis. Now we [01:03:07] will talk about asymptotic analysis. So if you talk about the dictionary meaning. So [01:03:15] asymptotic approach gives the value as an expression containing the variable tending to [01:03:20] infinity. So when I talk about asymptotic analysis, I am primarily concerned about [01:03:26] how the algorithm behavior changes when n tends to infinity. That is the asymptotic analysis. [01:03:32] So, here we will talk about big O, big omega and big theta. Then we will talk about little [01:03:40] O and little omega. So, these are the five notations that are quite common [01:03:45] when we are dealing with the asymptotic analysis. So, as we have discussed so far [01:03:54] that running time of an algorithm increases with the size of input as a limit. And here we are [01:04:02] considering that there is no bound, n can reach to infinity. There is no bound key, the value of n [01:04:07] should be in between 1 and 100, it could be anything. There is no bounding over the algorithm [01:04:15] range. An algorithm that is asymptotically more effective will be the best choice for very [01:04:26] very small input. So, the first notation that is called as the theta notation. So, due to [01:04:40] some work, I am stopping class today here and we have to also start a new concept. So, [01:04:47] in the tomorrow's class probably we will extend for some more time. We will start with this [01:04:52] asymptotic notation. So, today lecture is little bit critical in the sense that because [01:04:57] you people are from very diverse background. So I will just upload this PPT. Just read it out if [01:05:03] you have any doubt. So in tomorrow's lab, we will have a separately half an hour session [01:05:08] to let you people understand. Because if you do not understand this, then upcoming around 6-7 [01:05:14] lecture will be problematic or will be difficult. So just read it out. It is very easy. I try to [01:05:20] explain as best of my ability as well. So just read this. Then only we can start the theta [01:05:26] notation and other aspect okay so i'm closing now today due to some work that i have committed [01:05:32] and we'll we'll we'll meet again tomorrow thank you sidan for your help and i'm closing today at [01:05:41] this yeah ganesh i will take your query if you can enable just mic for the so those who have [01:05:47] done can leave leave the class okay yes i will take your query now yes yes yes you are audible [01:06:02] so best case is that keep uh fn is all already there for best case but that function let's say [01:06:19] i have considered three n plus three but n is but that the the execution of that function [01:06:26] kill it is this function run for one time two time three time so that is lesser in case of linear [01:06:31] search we we were identifying element at fifth position so this fn becomes a constant value [01:06:36] like three two or something okay and fn will run whole value or till n when we have reaches [01:06:43] to the tenth or last position okay yes sir thank you okay thank you everyone uh we are [01:06:51] are closing a little early but we will compensate in the upcoming classes.