[00:02:11] Sorry, sorry for the interruption I got. Thank you. So I started and I guess your doubt is done, I guess. That was the, my voice was not going. Thank you. Okay. So we talked about, yesterday we were talking about different types of logics. So likewise, selection logic, sequential logic and iterative logic. [00:02:49] So three types of logics were primarily there in any algorithm or maybe combination of all. [00:02:55] So sequential logic means that the logic that we have written is executed one after another, [00:03:00] one after another, one after another, one after another. But the selection logic will not go one [00:03:05] after another. They may take a jump or may terminate the algorithm after certain instructions [00:03:10] are made out. Similarly, we have iterative logic. So iterative logic means that same behavior is [00:03:17] repeated again and again. Same behavior again. So, for example, when we talk about a for loop, [00:03:39] so we are starting from i equal to 1, reaching a condition, let us say i is less than or equal to [00:03:44] 100 and then i plus plus, a simple for loop in C. So, what will happen? This will again and again [00:03:50] and again and again and again continue for 100 times. So, that becomes a iteration or [00:03:57] iterative logic or sometimes these are also called as the repetitive flow. [00:04:03] And here if you can see in selection logic, we are doing what? Conditional flow. The flow [00:04:07] of algorithm or the execution of the algorithm depend upon certain condition, if it is meeting [00:04:13] out or not. So selection logic has, if you talk about this statement, so it is adding a single [00:04:32] alternative if you consider the else component then we have double alternative that multiple [00:04:37] alternative exam best example is the switch statement okay in c or we can say that [00:04:47] if else later if else if else if else and so on so that is called as the if else later so these are [00:04:58] the selection logic or that depends upon a specific flow of the algorithm when some certain [00:05:06] conditions are meet out. So, this is an example of iterative logic. Iterative means that repeat [00:05:16] for loop using an index variable or repeat statement is followed by module called as the [00:05:23] body of the loop. So, that is called as the iteration or iterative logic. So, loops are [00:05:29] the best example because we are doing same task multiple time unless a specific condition is meet [00:05:36] okay so i will write if i write a single code i equal to one let's say int i equal to one [00:05:44] then i am writing a for loop i will go from one if i is less than or equal to 10 i plus plus [00:05:53] and inside the body of the for loop i am printing i okay then the code is closed okay [00:06:03] but don't confuse if i am writing something it is just a code so inside this wide main if i write [00:06:10] so this is first statement that will be executed next statement is for loop so this is what [00:06:16] sequential logic now when during for you execution we will again and again call this [00:06:25] statement. So, that is a recursive or that is a iterative logic. L will continue for [00:06:34] i equal to 10 that is a specific condition demand that is become the selection. So, [00:06:40] in the same code, we can easily see the three types of logic that is sequential selection [00:06:45] as well as iterative logic. So, this you can witness this is a structure of a simple for loop. [00:06:51] So, if I just write for k initialization with r k if greater than s and k plus plus. [00:07:07] So, this is how the logical structure, we initially do a initialization. Then we are [00:07:14] checking a specific condition. Then we are doing whatever the demand in the body of the loop, [00:07:22] then k is incremented with the factor of t so usually we take one so it could be anything okay [00:07:29] and this will keep on continuing unless this condition is meet if this condition is successful [00:07:35] then we will stop the condition okay if k is greater than s then we will stop similarly for [00:07:43] while loop if i write while there is certain condition i is less than 10 then we will execute [00:07:50] some module. So, this is the structure of this one. So, these both represents iterative [00:07:57] logic and the condition and where we check the condition is a selection logic. So, same [00:08:26] statement is uh you can say giving multiple options okay now i hope three logics are clear [00:08:39] sequential as the name indicates selection as the name indicates respect to certain condition [00:08:44] and iterative means that same thing will appear again and again okay now uh in the yesterday's [00:08:50] class we have started discussion on a you can say theoretical or more likely to be the analysis [00:08:57] aspect where we were discussing and just I will conclude what we have get from the yesterday [00:09:04] discussion one by one. So, first thing is that any algorithm analysis is performed by [00:09:27] assuming the algorithm as a function of input size or f of n. So, what we can say, so if [00:10:01] the input size that is always a positive integer, we will always consider that is a positive [00:10:13] integer increases the computational complexity of algorithm increasing. So this is important [00:10:37] key rather than. Second thing what we have encountered to determine the computational [00:10:56] complexity, to determine the computational complexity, we have to also think about the [00:11:23] key or dominating operation. Dominating operations in algorithm. We have to also talk about the [00:11:44] dominating operation in an algorithm like number of comparison in searching and sorting [00:12:02] algorithm third and last and important point is so first is that the performance of any algorithm [00:12:19] can be theoretically analyzed okay and this analysis analysis is theoretical and [00:12:38] platform independent okay it does not depends upon the in what on which machine we are running the [00:12:44] code analysis is theoretical and platform independent analysis is theoretical and [00:13:11] platform independent and one important thing is that the search space search space when [00:13:17] I refer them set off the element for sorting or the array where we have to identify the [00:13:25] key value. So, that becomes the search space. The search space or the context will also play [00:13:45] a crucial role to determine best average as well as worst case complexity. So, these three things [00:14:03] are important if you understand these three things. So, on today's class what I have discussed [00:14:08] will be summarized and that will be the takeaway thing that you can think about okay so [00:14:17] i hope three things are now clear to you first one any algorithm behavior we can determine [00:14:23] with the help we can represent that algorithm in form of a function of input size second thing is [00:14:30] that we have to also think about the key operations in an algorithm like number of comparison in [00:14:40] searching and sorting multiplication is dominating over addition and subtraction okay but in this [00:14:49] course we will primarily see the algorithm that are using searching or sorting concept okay and [00:14:56] third and the important thing is that the search space likewise if we are searching of a element [00:15:02] and we identify initial locations then we declare that we are in the best case and if we find the [00:15:08] element in the last location or not at all. So we have to make all the comparison till last. [00:15:14] So that that could be our worst case and average case will be in between this. Not exactly we can [00:15:20] mention that it is in the half location. So average case is basically the expected value [00:15:26] assuming that all the locations are equally probable. So therefore we sometime it is also [00:15:32] said that estimation of average case is little bit challenging. So this was you can say the [00:15:42] summary that we can draw from the yesterday's lecture. And that is important because yesterday [00:15:49] that was more theoretical one, so that you can do. Then we started discussion on one of the [00:15:56] important concept that is called growth of the function. So before entering into this concept, [00:16:02] One important thing is that here we will discuss about some well-known function. [00:16:19] Well-known function means that everyone knows n square, n cube, n log n, log n, 2 to the power [00:16:26] n. These are the function, well-known function. And we will represent this well-known function [00:16:31] with the symbol g of n. Later on, you will see what is g of n. Because for algo, we have assumed [00:16:37] what f of n. So, here I am saying f of n is a function that represents our algorithm, [00:16:52] in terms of input size n. And here g n, that is we will talk about, we will talk about [00:17:05] some well-known function that is g n and our aim is to identify the computational complexity [00:17:35] of an algorithm closer to this g of n. So, we try to reach to a situation where f n can be [00:17:56] represented in the form of g of n because we do not know if you think about the study class 3n [00:18:03] plus 3 as a function but everyone knows n as a function okay so if i can resemble 3n plus 3 as [00:18:12] n for a large n where n is greater greater very large value then we can say that the behavior [00:18:19] of the linear search, if you remember the studies class, linear search is of order n. [00:18:28] The behavior of the linear search is of order n. So, primary aim of our algorithmic analysis [00:18:37] is to first identify the behavior of your algorithm in terms of function of input fn. [00:18:47] after determining fn, we will try to identify some g of n that is a well known function [00:18:53] and try to showcase that fn is equivalent to n for a larger value of n. [00:19:02] So, for example, if my algorithm behavior is 5n square plus 3n plus 2, so it will [00:19:10] somewhere resemble to the n square or the known function. So, here are some function [00:19:20] that we have seen yesterday log n n n square n log n n cube 2 to the power n and what we identified [00:19:29] that if your computational complexity goes towards log of n then you are more more efficient here we [00:19:36] can see that when the input size is 100 the computational complexity the number of you can [00:19:43] say key operation okay because here these functions are representing the key operations will be only [00:19:48] 7. However, when it is 2n, then it is 10 to the power 30. So, if your algorithm is here, [00:19:54] it is acceptable. If it is here, acceptable, maybe here it is acceptable. But if it is this, [00:19:59] so it is, you can say, required. So, now I hope this is just how we are changing the input and [00:20:22] how these known functions are behaving. So, yesterday also we talked about in case of tree, [00:20:32] graph, the complexity will touch log of n. And that is the beauty of these, you can say data [00:20:42] structure that they, why they are very much popular. So, from the algorithmic analysis, [00:20:49] there is an important class or aspect that is called as the asymptotic analysis. So, [00:20:55] what is asymptotic analysis? Here, asymptotic analysis means we are trying to identify the [00:21:02] behavior of the algorithm when n is very very large or when n reaches to the infinity okay [00:21:09] if you talk about the algorithmic analysis let's say i make an algorithm okay or i make a website [00:21:15] simply that can tolerate a simultaneous hit of 5000 person at a time but let's say [00:21:25] some developer has given you that website okay and say that it is working fine you have tested [00:21:30] for 10, 20, 30, 1,000, 1,500, 2,000 and it was working perfect. Then what happened when [00:21:38] you have tested for 10,000 people, it is start failing or showing certain delays in operation. [00:21:45] So this means that in case of algorithmic analysis, we cannot check the behavior of [00:21:50] the algorithm for varied set of input. We have to think about something where we can [00:21:58] resemble or determine the behavior of the algorithm when n tends to infinity. So that [00:22:04] is why when we are talking about the behavior of some algorithm when n tends to infinity, [00:22:09] so that analysis or that thing is called as the asymptotic analysis. That is called as [00:22:15] the asymptotic analysis in which we will talk about big O, big O, big omega, big theta, [00:22:29] is little u and this is little omega. So one by one we will explore all these kind of things [00:22:38] and try to determine the asymptotic behavior of an algorithm with respect to the change in the [00:22:44] input size. So let us begin. So first notation that is very important. So that is called as [00:22:56] the theta notation and here that is the asymptotic notation. This is asymptotic analysis and theta [00:23:02] is a asymptotic notation. So, let us read this then we will see. So, let us define what this [00:23:13] notation mean for a given function. So, here it is written, I guess it is little bit blurry. [00:23:18] Okay, so for a given function g of n, we denote theta g of n, the set of functions. Okay, [00:23:52] just a while for a given function, we can denote by theta of g of n. So, this condition [00:24:01] should be fulfilled. So, what it says, g of n is what g of n was a well known function, [00:24:13] known function. And this f of n is a function representing function representing the algorithmic [00:24:35] behavior. So we can say that because f of n was the original value, we can say that [00:24:44] f of n is equal to theta of known function g of n when these conditions are fulfilled. [00:24:52] So we can say or we can convey that the function fn representing the algorithm is equal to [00:25:05] theta of g of a known function when these conditions, when above condition meet. What [00:25:19] is above condition is saying? If there exists positive constant, so of course we will talk [00:25:26] about positive value not negative value c1 c2 and n0 such that this condition fulfilled [00:25:32] that is c1 g of n should be less than fn should be less than c2 g of n okay and where n is [00:25:41] always greater than an initial value n0 n0 okay so where n is always greater than the [00:25:52] initial value n0. So if you see in this graph, so this is the line of f of n and we can see [00:26:11] with using two positive constants c1 and c2, we are getting that this is higher and this [00:26:17] is lower. And here this is the beyond this n0, we are very much ascertain that the same [00:26:24] behavior that is this behavior will repeat throughout this behavior will repeat throughout [00:26:30] then we can declare that the fn is theta of g of n okay so to establish fn is equal to theta of g of [00:26:39] n we have to identify two constants c1 and c2 and n0 after which we are very much ascertain that [00:26:47] this above condition fold then we can easily declare that the computational complexity of an [00:26:53] algorithm represented by f n is equivalent to theta of g of n. Now, so if I take simple example [00:27:22] I am taking, I have to fulfill this condition, I am just writing the condition c1 g of n f of n [00:27:35] c2 g of n. So, just this condition we have to meet. So, if you remember in the yesterday's [00:27:42] class we were writing fn is equal to 3n plus 3 and the known function that can be resembled [00:27:51] to this when n tends to infinity may be what g of n will be of course equal to n. Now let [00:28:00] Let us determine two values c1, c2 and n0 on which we can claim that fn is equal to [00:28:12] theta of n or theta of g of n. So this theta notation before going further is also known [00:28:25] as sandwich notation because we are bounded by c1 and c2 both sides, upper and lower bound. [00:28:32] this theta notation best represents the average case. Theta notations best represent the average [00:28:49] case. So one important thing because I do not want you people to confuse this theta big O, [00:29:00] big omega are only the purpose of nomenclature. And the basic idea is to stabilize [00:29:09] how our algorithm is behaving for example linear search says 3n plus 3 so our behavior is linear [00:29:16] in the sense this one let's say our algorithmic behavior is 5n square plus 39n plus 9 and of [00:29:24] course we will tend toward a computational complexity of order of n square so that is the [00:29:30] the beauty of this approach is that if we able to identify what order my algorithm is following [00:29:36] So, we can easily declare it is theta, whether it is theta, whether it is big O n, big omega [00:29:41] notation. That is just a representation purpose or a nomenclature. Now, let us, I try to identify. [00:29:59] So, here just write it down. Note that c1, c2 are positive constant and n0 is a specific value. [00:30:14] So, let us think about this c1n less than 3n plus 3 less than or equal to c2n. [00:30:28] So, just considering this inequality, just considering this inequality. [00:30:39] So, what we will get c1 is less than 3n plus 3 by n and c1. [00:30:47] okay. So now what this c1 should take. So simply what we can do, limit n tends to infinity and then [00:31:14] we have to check the behavior. So we know that something by infinity is 0 and what we will get [00:31:21] ultimate 3. So c1 should be less than or equal to 3 and we can take any value of c1. That is good [00:31:27] thing. It is not mandate, you have to take 3, you have to take 2. So, let us say I am [00:31:32] taking C1 as 2 and from this we can just have to put one more value. So, here what we will [00:31:38] get? Key C2 is greater than 3. So, let us say I am taking C2 as 4. So, now we get two [00:31:45] positive values C1 and C2 even fractional is allowed. When fractional positive value [00:31:50] is allowed, then we can say that now f n is equivalent to theta of g of n. One more thing [00:31:58] now we have to determine n 0. So for n 0, what I can say if this function is positive, [00:32:04] this f n is positive. So n 0 will be always 1. Okay, if it is negative, so we have to [00:32:10] identify the value after which so let's say this was 3 n minus 3. So for n equal to 1, [00:32:16] become 0, but for n equal to 2, this become positive. This become positive. So n 0 will [00:32:22] be to that there. So we have to identify a specific n 0 beyond which this function behave [00:32:29] as a positive function. And if you remember, the monotonicity property was holding properly [00:32:36] when your function was a positive. So this means that we are now get n 0 1 c 1 c 2 s [00:32:43] C1 as 2, C2 as 4. So we can easily declare that the computational complexity of linear [00:32:50] search f n is equal to theta of g of n or that is theta of n. So if some of you have [00:32:58] known that the computational complexity of linear search is theta of n. So I hope you [00:33:04] people can easily correlate. And here one more important thing is that since we can [00:33:11] take as many value of C2 that are positive, as many value of C1 that are positive. So [00:33:19] we can say that Fn belongs to a value from set of theta of n. So this is not equal to, [00:33:27] this is set of value. So there are many possibilities of C1 and C2. So all answers are correct. [00:33:33] So it does not mean that there is a fixed value of C1 and C2. So if it is fixed, so the things [00:33:39] are a little bit tricky. So, we will solve some more examples on this ground. But let [00:34:07] me conclude this and then we will solve some more problem and I will also try to take some [00:34:11] of your queries. The function f n belong to here it is written a function f of n belong [00:34:37] to set theta of g of n. So I am talking about set. Okay, so we are taking any value f of [00:34:44] n is theta of g of n. We are just taking a single value. So we are using equality. But [00:34:49] it is of course a set of value we have if there exist positive constant c1 and c2 such [00:34:59] that it can be sandwiched between c1gn and c2gn for sufficiently large n. So, read as [00:35:07] f on n is theta of g of n. So, this that what I have said that this notation is also called [00:35:38] as the sandwich notation. So, sometime the question is maybe asked which asymptotic analysis [00:35:43] is also known as the sandwich kind of thing. So, of course, you can say that it is theta [00:35:49] notation and it is read as f on n is theta of n. You can see f of n is equivalent to theta of [00:36:01] g of n. So, that is there. So, I hope I have covered all those aspects. So, let me take some [00:36:09] of the questions and then I will take your queries. So, let us say one important thing [00:36:16] before proceeding fn will be given okay let's say if i ask to establish this then fn will be given [00:36:23] or you have to determine via algorithm okay and g may be given okay so like here gn is 3 of n is [00:36:45] given if it is not given then you have to manually decide which is the best suited or known thing so [00:36:52] we will try to identify a value that will resemble this known value when n is very large, [00:36:59] when n is very large, n is tending to infinity. Or we have to establish one important thing is that [00:37:06] when n tends to infinity, f n by g n should be equal to 1. This is important condition. [00:37:14] So, for 18 n plus 9, I will never consider n square because when n tends to infinity, [00:37:20] f n by g n will never equal to 1. That is important case. So now let me solve this problem. [00:37:26] So we have 18n plus 9 n here. So this is a positive function. This is a positive function. [00:37:44] So we can take n0 as greater than or equal to 1. Now I am establishing c1 3n less than 18n plus 9 [00:37:57] that is further less than c2 3n because 3n is the given gn. If it is not given, then I will [00:38:04] consider n, of course. So now c1 is less than 18n plus 9 by 3n and here we will get c1 less than 6 [00:38:15] 6 plus 3 by n. Just give me a while. So, here again we have reached c 1 less than 6 plus [00:39:16] 3 by n and when n tends to infinity, so behavior will be what? c 6 plus 3 by infinity. So, [00:39:24] of course, we will get 6 and we can put c 1 equal to either 6 or less than that because [00:39:30] that was a less than equal to value and C2 will be one more value higher. So, we do not [00:39:35] have to bother what is C1 and C2, just check that C2 should be greater than C1. And you [00:39:42] are done. Now we can easily declare, now we can easily declare that, just give me a moment. [00:39:50] Now we can easily declare that 18 n plus 9 is equal to theta of 3 n. If 3 n was not given, [00:40:01] we can conclude that it is equivalent to n okay so now i will take your queries then we will move [00:40:09] further okay so krishna you have a number of queries we are having so one by one we will take [00:40:52] so enable mic for them those who are raising hand one by one ah sure sir can you hear me yes yes [00:41:08] Sir, in the last example, where is the g of n is given as 3n? [00:41:13] Yes. So, g n is supposed to be a known function, but in some of the examples, it should be [00:41:21] explicitly given. But is this an example we should consider that g of n is equal to 3n is [00:41:27] like already given? If it is not given, then you have to consider n otherwise it will be explicitly [00:41:33] given also what is the importance of n naught sir you said n naught in earlier example n naught [00:41:40] should be equal to 2 because when we take n of 1 n naught is equal to 1 the function 3 and minus [00:41:46] 3 is becoming 0 so n naught should be greater than 1 what is the importance of n naught and where are [00:41:52] we using it okay so here if you see this graph now so after n naught if this function fn is positive [00:42:00] then we are very much sure that what we are claiming is remain same throughout. Before n naught, [00:42:06] we cannot claim that this behavior will persist or not persist. So if you take let us say 18n minus [00:42:13] 72, so n will be of course n will be greater than 4 or n should be 5 where this function become [00:42:20] positive. So we try to identify a value beyond which the behavior of the function is positive [00:42:26] and we are very much uncertain that what c of 1, c of c2 or what we have determined is obviously [00:42:33] correct. So, that is why this is needed. So, for the when the function become positive, [00:42:37] so what we are claiming is truly correct when n tends to infinity. Otherwise, there might be some [00:42:43] chance where this condition may fail because we are dealing with a negative function. [00:42:47] got it thank you yeah yeah yeah good morning sir good morning my question my question is the [00:43:12] starting of the slide when you say that function fn is the function of input or let's say take an [00:43:20] example there's an array in that there's a 12 element okay so n will be 12 or what and one [00:43:28] more thing in that only if to search a particular element let's say we took 10 dominant x dominant [00:43:35] operation or 13 dominant operation then fn will be that i mean number of size or element into the [00:43:43] array or the dominant basically test that out no no okay the good question you were asking so now [00:43:49] when I say f of n, so here n is the input size. Input size is what? When we are searching, [00:43:58] so we have to search a specific key in a set of elements. So your search space is this one, [00:44:03] where we are having 20 elements. So the f of n will represent the number of array present in [00:44:09] this element. Similarly, when we talk about sorting, then we will primarily talking about [00:44:13] the set of 20, 30, 40 element where we have to apply something, sorting, some sorting [00:44:19] algorithm to sort this array. So I hope this n represents the entire search space on which [00:44:26] we have to perform the operation. If n become 100, if we are taking 100 numbers as an input [00:44:31] and then we are searching some element or we are taking 100 element as an input and [00:44:35] we are doing the sorting operation. So this is what this is represented by the f of n. [00:44:41] Now f of n is denoting like 3n plus 3 in linear search if you are talking. So this is the [00:44:48] entire cost the algorithm will consume and this 3n will be the cost consumed by the looping [00:44:54] operation where comparisons are also performed. Then this is called as the dominating operation [00:45:00] and we see the behavior of algorithm is ultimately resembling like n. So f of n is the function [00:45:09] resembling the search space and dominating operation is the key operation that is being [00:45:15] performed in an algorithm to apply over that search space. I hope now the doubt is clear. [00:45:21] Yes sir the consecutive doubt in this only. Let's say you told that there is a 100 element into the [00:45:27] array and the whatever fn came it become 3n plus 3. Yeah. So if we will solve for n I mean we are [00:45:36] not considering let's say we are not considering that n is going to infinity 400 only we have to [00:45:42] calculate it so f of n we can say it will become 300 or 300 plus 3 300 plus 3 yes if it is 10,000 [00:45:51] then it will be 3,000 plus 3 okay okay then got it clear thank you answer one more doubt in that [00:45:58] recently that n naught right so c1 c2 is clear but n naught is not clear can you just give a little [00:46:04] So n0 is just a way of making the function or identifying the value beyond which our function remains positive till infinity. [00:46:13] Just a single line if I say. [00:46:15] And that will be given. [00:46:17] That will be not given. [00:46:18] That you have to determine. [00:46:21] Okay. [00:46:22] n0 is the value beyond which function is positive. [00:46:34] But what graph you have shown. [00:46:39] Right. [00:46:39] then that is not relatable to this. I am not able to relate this. [00:46:43] This is relatable. So beyond this, this n naught, we are very much certain that this behavior will [00:46:49] remain throughout. So I am saying it is positive because in positive function, if let us say it [00:46:55] is 3n plus 3, so we are very much sure that whatever the value of n, we will always get [00:47:00] the same behavior. If it is 3n minus 9, so for 3 equal to 3, it is 0 and before that it is a [00:47:06] negative value so the behavior could not be similar throughout so beyond so here we have to [00:47:11] take what n should be 4 or greater so if it is there then the behavior is remain positive and [00:47:17] remains the same if you remember the in the previous classes i will talk talking about [00:47:21] monotonically increasing so our target is to make the function monotonically increasing [00:47:26] such that we can claim whatever the computational complexity we have established is valid till [00:47:32] infinity okay means you are telling first function should be monotonically increasing [00:47:37] then only then only we can determine the computational complex otherwise we cannot [00:47:42] be certain about the behavior okay thank you sir thank you so much yeah sorry i've allowed your [00:47:57] mind morning sir actually i was having the doubt on the thing that you just put it a strict on it [00:48:07] that is f of n by g of m should be equal to one that is one of the doubt because there's [00:48:12] we know 3 and plus 3 should be less than c2 g of n so i can take g of n to be n square as well [00:48:18] so that was a bit of clarification i need because okay wait wait wait that is good question you have [00:48:24] asked and i hope number of people have seemed out but you have shown courage to ask thank you for [00:48:30] this question okay so that is very good question and even uh you can say that is the trickiest [00:48:36] question among these analysis okay rather than determining c1 c2 that is easy to go but that [00:48:41] is the trickiest part of this. So where what we are saying, I am saying that when limit n [00:48:48] tends to infinity, that is input size, this f n by g n should be 1. So if I am considering 3 n [00:48:56] plus 3 as f n and I am assuming g n is n square. So what will happen for let us say for some value [00:49:05] of 1 or even for n equal to 2, this may hold, but when n tends to infinity, there will be [00:49:13] a mismatch. [00:49:14] And what is our ultimate aim in asymptotic analysis is to determine or to identify a [00:49:28] well-known function that resembles the behavior of our algorithm. [00:49:46] algorithm even for n tending to infinity. That is important part of asymptotic analysis. [00:49:53] Soon we will talk about little O and little omega where you are free to take different [00:49:58] value of fn and gn. But for theta or that is big theta omega and big O, this is a mandate [00:50:08] condition that we have to consider a function that is as equivalent as the behavior of the [00:50:15] even when the value of n is very large. I hope it is clear now. [00:50:21] Sir, is there any sort of example that you could give? It is though clear but it is not 100% clear [00:50:28] so possible any sort of example. Okay, so let me do this same example 3n plus 3 and here we are [00:50:39] saying c1n square and here we are saying c2n square. Okay, now let us try to identify since [00:50:46] this function is positive. So n0 will be of course 1. Now what I am doing c1 less than [00:50:51] cn plus 3 by n square. So what basically we are getting c1 less than 3 by n plus 3 by [00:51:01] n square. Okay. Up till this I hope it is clear. Yes sir. So when I put n tends to infinity [00:51:08] so c1 becomes what? c1 should be less than or equal to 0. And if you remember I was always [00:51:14] saying c1 should be a positive value and here it fails so this is the simplest way you can determine [00:51:20] yeah okay so i got now i got it thank you yeah any other doubt barun i have allowed your mic [00:51:41] please um hi sir thanks for clearing the first doubt that's what my doubt also but um i have one [00:51:49] more thing by we are all looking for a positive value because the whole idea was to get a [00:51:55] computational analysis of our algorithm is it correct yes yes so what is the band what is the [00:52:03] rationale what is the idea of getting a positive value of this growth function this fn positive [00:52:11] value i guess okay yeah so a simple statement if i say about this is that is there any algorithm [00:52:19] possible on this globe whose behavior is a negative function or we can say that whose [00:52:27] computational complexity decreases with the increase in the input size. So, your answer will [00:52:33] be no. So, that's why our target is to identify a positive function that best represents our [00:52:39] algorithm. Because we know that we can never get an algorithm whose time complexity reduces with [00:52:45] input size i hope it is now clear got it any algorithm any algorithm you consider if you [00:52:54] increase the input size its behavior is to increase the complexity so how we can consider [00:52:59] a function fn that is going in a negative direction clear clear good morning sir good morning [00:53:18] yeah yeah sir can you please re-explain the slide in which you have mentioned the graph okay [00:53:23] This one? Yes or this one. So, we have to identify beyond some n0, the function behavior [00:53:36] is likewise this relation that is c1 g of n should be less than or equal to f n should [00:53:42] be less than or equal to c2 of g of n. And here we have to consider two positive constants [00:53:48] c1 and c2 okay and if we able to establish then we can easily declare that the behavior 3n plus 3 [00:53:57] is as equivalent to the n okay so that is how our target is to determine g n uh g n that best [00:54:05] represents our algorithm even when n tends to infinity that is the thing so what is your [00:54:10] specific doubt you can tell also this one only okay thank you thank you yeah good morning sir [00:54:34] good morning i said one small doubt related to c2 so when we are calculating c1 we are taking [00:54:41] limit to infinity or c2 we are taking limit to one uh is it correct or no no okay so i have [00:54:50] just making making the calculation easier. So, you can also take 3n plus 3 less than c2n. [00:54:58] So, it is just taking this value to the backslide 3n plus 3 less than c2n. So, that is 3n plus 3 [00:55:07] less than c2n. So, what I will get basically c2 is greater than or equal to 3n plus 3 by n. So, [00:55:15] of course c2 should be greater than or equal to 3 plus 3 by n. When n tends to infinity, [00:55:20] then c2 should be greater than or equal to 3. So, I can take any value that is greater than [00:55:25] 3 or equal to 3. So, in this case, we have to consider c1 either should be 2 or anything. [00:55:32] So, for making the computation easy, I am calculating one side and taking one [00:55:36] or more positive value for c2. But if you officially want to calculate, [00:55:42] so you have to calculate on both the sides okay okay sir yeah okay i will take a two minute break [00:55:58] then come again and start our discussion okay but you people are asking really good questions [01:00:09] okay uh krushna so i will take one or two queries i hope people are asking good question and most [01:00:15] of the doubts are being cleared this is important why i'm emphasizing more on this because if this [01:00:20] theta notation is clear then all the notations are very easy to go it will take hardly just [01:00:26] uh sure yeah yeah because your mic was allowed those who have raised just just give them a minute [01:00:57] just those who have raised hand and their doubt is already clear they can uh down their hand as well [01:01:02] okay because uh handling the queries from 60 70 people will definitely kill more time okay yes [01:01:07] Sir, basically you are asking about N0, because we know beyond N0 we have a positive question. [01:01:22] Your voice is a little bit not clear. [01:01:30] Hello, am I audible? [01:01:37] Yes, yes, you are audible. [01:01:42] Sir, I was just asking about how... [01:01:46] So, I am not getting your voice clearly. So, you are just how to get this value n0, I guess, if I am correct. [01:01:58] Yes, yes, yes, sir. [01:02:00] Okay. So, for example, this is just what you can say hit and try technique I am using beyond this function become positive. [01:02:09] But you can explicitly determine the value of the n0 beyond this that will be a positive. [01:02:16] So there are a number of mechanism to determine beyond which value this become positive, there [01:02:23] are certain set of function as well. [01:02:25] So exact technique of identifying will be probably be the simplest one what I was talking [01:02:31] about and so I guess that could be the simplest one but to determine n naught we have to just [01:02:43] solve this equation. [01:02:44] I am not making the things more critical, we have to solve this equation. [01:02:48] then only we can determine which value, what values of the n we are getting. So for example, [01:02:53] if I has 3n plus 3 equal to 0, so what will be the value of n? So n equal to minus 3 by [01:03:01] 3, so n equal to minus 1. So while doing this, I can skip, we will tell you in the next class [01:03:16] you how we can exactly determine. So, let us say we have 3n minus 3 equal to 0. So, [01:03:22] n will be equal to 1. So, from here we cannot comment. So, you have to determine explicitly [01:03:30] when this function positive. So, there is no specific technique, but I will search out and [01:03:35] let you know when this function positive. And in the next few slides, you will also identify [01:03:43] how to determine l and 0 via some formula for quadratic expression as well so that we will [01:03:48] talk about in after some slides yeah next yes okay okay thank you sir yeah amit please go ahead [01:04:01] yeah uh sir can you go on the example sheet i think 29 sheet number this one [01:04:10] uh where you have given example actually one example you have given [01:04:14] so sir actually f9 n naught you have told like the value after which fn will be the positive [01:04:22] positive yes yeah so uh where function is given fn is 18 n plus 9 so we mentioned n naught is equal [01:04:31] to 1 for 1 fn will be positive but why n is not equal to 0 if we put n is called n naught is equal [01:04:38] to 0 then fn will be 9 that also will be the positive number then why we have not taken n naught [01:04:42] is equal to greater than equal to zero why one okay a very good question and a very simple answer [01:04:50] n not equal to zero means what we are assuming there is no nothing as input when n is one we [01:04:58] are considering what there is at least one input to the algorithm getting now i hope your query is [01:05:04] resolved okay so why to analyze the behavior of the algorithm when input size is zero there is [01:05:11] is no significance at least it should be one okay got it got it thank you hello sir hello [01:05:34] Actually, turn 18 does not come under the control of computer center, but I will talk. [01:05:55] I guess it is applicable for the faculty is only orientation class. [01:06:03] you can write to the support something there is CT support something so they will help you out [01:06:13] so I will check so it's come separately talk I guess that that will be better I will convey okay [01:06:32] because other will be in different mode now so we will talk separately you just mail me out or [01:06:39] and then i will we can have a meeting as well for this okay [01:06:42] name rahul underscore mr or even on this mail id from which i'm teaching [01:06:50] okay done thank you sir or or you can say that aditya will help you out in this [01:06:56] so he will connect with me and then we can discuss definitely thank you sir i know yeah [01:07:11] hello sir good morning good morning thanks for a great explanation sir actually my query is with [01:07:26] respect to the mandate condition which you were mentioning a few minutes back that is for a theta [01:07:31] and big o uh it's a mandate condition i just lost that point yes this one fn by gns would be equal [01:07:38] to one when n tends to infinity [01:07:39] i guess this this point yeah yes yes so if you can just give a glimpse over there like [01:07:47] why it's a mandate condition because i just got that we have to identify the behavior of [01:07:53] our algorithm function in terms of some known function okay so if they are different likewise [01:07:59] 3n plus 3 by n square so what we are getting is c1 should be less than 0 that violates the [01:08:04] condition of theta notation. Similarly, if I say that linear search is this and I am assuming its [01:08:10] behavior is like n square, so there will be no comparison. What is our target to best represents [01:08:16] the computational complexity of our algorithm in terms of a known function. So if it is odd, [01:08:23] like n square we have taken, so it is not the actual behavior of our function. It will fail [01:08:28] beyond some value of n and that we never want because we have already established a condition [01:08:33] of c1 g n less than f n less than c2 g n so that's why this f n by g n should be equal to one when n [01:08:39] tends to infinity or we can say that they are as similar as um both f n and similar g n are very [01:08:48] similar to each other okay or f n is as similar as g of n so so in that case sir uh as you were [01:08:55] just mentioning a few questions sorry a few answers a minute back to a student [01:09:01] like n cannot be zero and that means n is a basic input condition that yeah [01:09:09] that is a number of input to your algorithm so your algorithms would accept at least one input [01:09:13] absolutely so now how come this n square is representable the same way with respect to the [01:09:21] is it is it anyhow representing the same elbow input or something else no so we [01:09:28] will talk about other problems where you will find 5 n square plus 29 so here [01:09:34] this will be equivalent to any square then and is very large okay so we will [01:09:43] talk about those algorithms like in insertion sort we will see the [01:09:46] computational complexities of order and square so that we will talk about [01:09:50] okay I mean that's kind of a colliding way though I'm just trying to understand [01:09:55] okay sir thank you thank you so much just give some more time to me then your [01:09:59] all doubt will be automatically resolved okay thank you and one last thing sir [01:10:04] actually I was just trying to get through a few notes as well as some [01:10:09] books here so is there is any basic book which actually covers the similar way [01:10:14] you are teaching I mean it's very good to have an understanding like this so [01:10:18] there is any basic book which uh explicitly helps us to have this kind of basic so i will recommend [01:10:25] the the book that i have authored okay so that is uh i am around that only so i will share the link [01:10:32] in the in the lecture note section okay sure the book is okay yeah yeah so i had a pdf on that link [01:10:40] you have to add your mobile number you will receive an otp and then you can easily download the book [01:10:45] thank you so much sir if you can help out that will help everyone actually so that is you can [01:10:49] say a concise version of four men but with different set of examples even objective questions [01:10:54] are also there so just go through it okay yeah yeah i mean absolutely that would help everyone [01:11:00] so i just thought of asking it okay thank you thank you thank you so much so krishna i guess [01:11:10] we can proceed or there are some queries left uh another two people are there sir okay okay [01:11:16] because we have to cover some more slides. So we need some time. Yes. Yes, please. [01:11:27] Yeah. I'm going to pressure. Please. [01:11:33] Hi, sir. Good morning. [01:11:35] I have the, like a few, we are using this, [01:11:41] you are explaining this as a notation in real time. [01:11:46] We have many, [01:11:49] many problems and all those problems we are putting into the solution logic [01:11:54] right so how how these things we have to apply in the real-time world is it like [01:12:04] for all the algorithms is it applicable or whenever we develop any algorithm how [01:12:10] do you make sure that we will be applying these things yeah so we will [01:12:17] definitely talk about the number of algorithm in this course like insert [01:12:20] and sort selection sort merge sort binary search bucket sort so all the [01:12:24] sorting algorithm has its own kind of pseudo code or own kind of algorithmic implementation so from [01:12:30] this analysis we can directly resemble what could be their behavior when n is very large and one [01:12:35] next important thing is that here we are considering the dominating operation as comparison and [01:12:40] comparison so this is applicable for those algorithm that is considering you can say [01:12:46] comparison but let's say we are going beyond this we are going for multiplication or we are going [01:12:51] for tensor multiplication in ml or ai stuff so then also this algorithm will use but with a little [01:12:58] little bit of modification your fn will not be of order n or n square it will be n to the power [01:13:02] 4 or so on so more or less the behavior of the all the algorithm is one single thing is clear that [01:13:09] it increases the complexity with the increase in the input size that is clear so your function [01:13:15] could be anything but behavior will be more or less likewise so here what basically we are trying to [01:13:20] identify the nature of the algorithm that is it is quadratic linear logarithmic okay cubicle or so [01:13:28] on so that is there so exactly you can say it could be directly applied on all so my answer [01:13:33] will be no but of course it will create a base to determine the computational complexity of any known [01:13:38] algorithm okay whichever from ai ml anywhere we have to identify key what are the segments [01:13:44] or the components that are imposing the computational complexity to the system [01:13:47] and then only we can conclude case the complexities likewise this one and this one [01:13:51] so uh because being a being a you can say researcher so every time we have received [01:13:56] the queries key what is the compute complexity of your algorithm so we definitely come to these [01:14:01] these things and then uh take a pants like okay this could be the n4 or log n4 or something so [01:14:08] that i can say at this stage right now okay thank you very much sir thank you i hope we are taking [01:14:19] last query uh yes sir parambir is there last yeah uh sir good morning sir i have uh two queries on [01:14:27] that last slide which was shown where you had given that example function n is equal to 18 [01:14:32] n plus 9 if you can go on that slide okay this one yes sir uh we have understood how you have [01:14:39] calculated c1 uh can you explain how c2 is calculated and how it comes to 9 and secondly [01:14:45] the condition where gn is not given then how do we proceed ahead these are my two points so when [01:14:51] gn is not given so we have to identify the dominating term in our algorithm and try to [01:14:56] identify which known function best resembles the so for example 18 n plus 9 so of course this is [01:15:02] the dominating term so we have to identify a known function that resembles this one so of course the [01:15:08] answer will be n i hope the doubt is clear yes yes and how to calculate and the simplest simplest [01:15:14] ways to identify the highest order term in the expression of n and that would be the simply the [01:15:21] representation for example if i had 5 n square plus 19 n plus 276 so of course this 5 n square [01:15:30] will dominate but dominate after some time so we can easily declare that it is resembling to the [01:15:36] behavior of n square. Now the second thing is C2. So I was just considering one part. [01:15:43] Now you can also consider the second part. So what you will get 18n plus 9 by n less [01:15:48] than C2. So of course there is 3n. So of course the resultant will be what? It should be greater [01:15:54] than C2. C2 should be greater than 6. So we are taking 9. You can take 7. Anything. [01:16:00] but not equivalent to c2 once you've collected once we found the lower bound that is c1 as six [01:16:07] so c2 can be anything more than six more than six that is fine that is there right right thank you [01:16:12] okay so you people are asking very good questions and and hopefully because there are plenty of [01:16:18] people who are sitting that they are not asking and their doubts are also clear so that's why i [01:16:23] i take time and resolve the queries on book and one important uh thing is at at this level what [01:16:29] understand that whatever we taught though we may be possible we are not able to cover up entire [01:16:35] syllabus but whatever we learn we should learn very clearly and whenever you go somewhere and [01:16:42] talk about the asymptotic analysis so you are very much confident that okay i can do this [01:16:46] irrespective of the from which background you are coming okay so let let me proceed and do some more [01:16:52] problems. So, this is just some repetition. So, here we have this problem already we have solved. [01:17:07] So, some more problem I will take and then we will. So, let me take f n equal to 3 n square [01:17:19] minus 9 n plus 17. Now, I have to determine after which value this function become positive. So, [01:17:27] So that will be treated as n0. I will also tell about one formula where in case of quadratic [01:17:34] expression, quadratic expression, this is a quadratic expression because this is having [01:17:40] a term of degree 2, quadratic expression to determine n0, c1 and c2. So that is in upcoming [01:17:50] slide. So there is a dedicated formula, but do not try to cram it. What the technique [01:17:56] I am telling that will be more than enough. Now, so if I take n equal to 1, I am just [01:18:14] getting a hit and trial method. So one way is that the solve is algebraic expression [01:18:18] and we will get some value of n and if it is values are negative, then we have to rethink [01:18:23] and take the positive side. But that will be a little bit complicated, but I will try to convey [01:18:28] in the next class. So now when I am taking 2, then also this is negative. When I am taking 3, so [01:18:36] So this become a positive thing, but n component is missing. When I use 4, let us say I use [01:18:42] n equal to 4, then what I will get? 3 into 16 minus 36 plus 17. So that is 48 minus 36 [01:18:52] plus 17. So what we will get? 12 plus 17 that is. So of course it is positive. When we are [01:19:02] taking n equal to 3. So what we are getting? 3 into 9 minus 9 into 3 plus 17. So this means [01:19:11] that if we take any value greater than or equal to 3, the behavior of this function [01:19:16] is positive. If you can check, it is applicable. Now n naught is greater than 3. That is now [01:19:23] a certain and it is clear. So c1, g of n here we are assuming we have to check the higher [01:19:29] degree term, if it is negative, one important thing that I missed, if it is negative in [01:19:34] any way, so we cannot apply asymptotic analysis here. Just give me a minute. If in any circumstance, [01:19:53] the high order, so that is important, you can say assumption or notation, if the highest [01:20:00] degree term is negative in any condition, highest degree term is negative in any condition, [01:20:19] then we cannot perform asymptotic analysis. Then we cannot perform asymptotic analysis [01:20:36] because ultimately the function is negative. So, we can never apply. So, now coming to [01:20:56] this current problem. So, we have c1, we are considering the higher degree term n square as g [01:21:03] n, n square less than 3n square minus 9n plus 17 less than c2n square. So, c1 of course will be [01:21:16] 3 minus 9 by n plus 17 by n square. So, of course, we have to put c 1 that should be [01:21:25] less than 3. So, let us say we are putting c 2 equal to 2. And similarly, we can determine [01:21:31] c 2. So, for any problem, first we have to identify n 0, then we can proceed likewise. [01:21:38] An important thing is that if the highest degree term is negative, then we have to be [01:21:43] very much considered. So, we can say that this function fn that is 3n square minus 9n [01:21:50] plus 17 is equal to theta of n square for all n0 greater than or equal to 3 and c1 and [01:22:03] c2 can have any positive value that we can estimate, but that should be beyond n0 greater [01:22:08] than 3. So, there are a few blank slides, so I was supposed to write some question. [01:22:15] Now, coming on to one of the interesting thing, where we will also deduce some formula. Now, [01:22:22] we have a function half n square minus 3n equal to theta of n square that we have to establish. [01:22:30] So, this n square means that this is of course g of n and this one is f of n. So, of course, [01:22:50] we will apply same strategy and here the n0, so here determining n0 is little more tricky. [01:23:09] So in the next slide I will show you the formula how to determine n0. Now I have done half c1 n [01:23:15] square half this one and if I solve for one part, so I am getting this value. So c1 should be less [01:23:23] than 1 by 2 that any value you can take and c2 should be greater than 1 by 2 of course [01:23:31] again you can take any value okay and here if you see n should be greater than 7 and [01:23:37] should be greater than 7 for which this is applicable so this means that we can establish [01:23:41] this for a positive function and even the positive function with some negative terms [01:23:48] we can establish. But for that case, we have to determine a specific value of n naught. [01:23:55] Here it is. So if a function fn is, this is a quadratic expression. If it is so a b c, [01:24:08] so it is applicable only when a is greater than 0, your function should be positive or [01:24:13] high order term should be a positive, having a positive constant. So we can calculate c [01:24:19] c1 equal to a by 4 simply c2 equal to 7 a by 4 and your n naught is nothing but 2 into [01:24:30] max of mod b irrespective of the sign by a and there will is underscore mod c by a. [01:24:38] So this is, there is a comma. So this is a simple way of mechanism of determining c1, [01:24:45] C2 and N. So in the next class, we will discuss more on this and we will start at one of the [01:24:51] interesting algorithm of this that is the insertion sort. Afterward, we will see big [01:24:57] O, big omega and other notations. But if you are very much clear with this theta notation, [01:25:03] so all you doubt in upcoming notations will be definitely clear. [01:25:08] So now here I am closing today's session. We will see again in the lab. And one important [01:25:13] thing because we are not covering any algorithm so far, we are just discussing about the complexity [01:25:18] of the algorithm. [01:25:19] So in the lab, you may face some new type of problem. [01:25:23] So do not effort and after insertion sort, we will repeatedly start getting new type [01:25:28] of sorting algorithms. [01:25:30] So that will be parallel teach with the class. [01:25:33] So thank you all for joining and thank you for your good queries. [01:25:38] And of course, thank you moderator who has made this class possible and make me comfortable [01:25:43] while taking your queries so thank you everyone uh for joining and thank you krushna for supporting [01:25:49] me a lot okay so i'm yeah closing the session now and we'll see you in live