00:00Now let's talk about our next nested loop.
00:02In this case, there is also some constant work.
00:05So in this case, there is a work of k.
00:07How many times it is running out of loop?
00:09In the outside loop, i value is going to 0 to n or n-1.
00:14So how many times it is running out of time?
00:17How many times it is running out of loop?
00:18How many times it is running out of loop?
00:19The inside loop is going to 0 to i-1.
00:24Because it is less than i, so i-1.
00:27Less than n, so n-1.
00:28So what can I say?
00:30For i is equal to 0, how many operations or how many operations will be?
00:33My j will go from 0 to n-1.
00:37So the condition is wrong.
00:39So what will happen here?
00:40How many times it will run out of loop?
00:41It will run out of 0 times.
00:43What can I say?
00:44For i is equal to 1, my j will go from 0 to 0.
00:48So my loop will work one time.
00:50And what will I do in loop every time?
00:52What will I do in loop?
00:53So in this single turn, in this single iteration,
00:58In order of loop, i is equal to 1.
01:03I am using inner loop to 0,
01:04what will I do in loop every time?
01:07How many times I do in loop?
01:10In order of loop all the time,
01:10I work on this single iteration.
01:13Now let me look at the next iteration.
01:14For I is equal to 2, I will take my loop from 0 to 1 I will run and let
01:19my loop do 1 so I will run 2 times K.
01:20So total matters is my 2K. For I is equal to 3, I will take my loop from 2.
01:29So I will do 3 times my loop how much do I work? K total job is 3 into K
01:35i.e. 3 K.
01:36i is equal to 4
01:38for my loop j is equal to 0
01:40from 3 to go
01:414 times run
01:42every time k
01:444 times k
01:454 times k
01:454 times k
01:47i is equal to 5
01:48for my loop j is equal to 0
01:50from 4 to go
01:515 times run
01:52every time k
01:54this is multiplied by this
01:57which is 5k
01:58so what can I say
01:59i is equal to n-1
02:02so how many times
02:04I will run
02:04from 0 to n-1
02:06how many times
02:07n-1
02:08is equal to n-1
02:10this is n-1
02:11this is n-1
02:12in this way
02:12the working loop
02:14will be working
02:15so what can I say
02:17that my total work
02:18will be added
02:20so I will add k
02:22with 2k
02:23with 3k
02:24with 4k
02:26and when I add it
02:27I will take n-1
02:28k
02:29so this is ap
02:311 plus 2 plus 3 plus 4
02:33till n-1
02:34what is the sum
02:35what is the sum
02:36what is the sum of ap
02:37n into n-1
02:39by 2
02:39will get the sum
02:40because it is n-1
02:41and it is not
02:42this will be basically
02:44equal to
02:44k n square by 2
02:46minus k n by 2
02:48so if I put this
02:50here
02:51I can write
02:52here
02:52if I have to convert
02:53this into big
02:53then this will be
02:55big of
02:56k n square by 2
02:57minus k n by 2
02:58if I ignore constant
03:00this will be
03:01n square
03:02minus n
03:03and the largest term
03:04from this
03:05is big of n square
03:06so this is my
03:07final time complexity
03:09for this loop
03:09which is n square
03:10and mostly loops
03:11especially for patterns
03:13their time complexity
03:14is n square
03:15here
03:16homework problem
03:16is that
03:17if we analyze the pattern
03:18the time complexity
03:20if we analyze the pattern
03:21then it will mostly
03:22n square
03:23although
03:23you have to do it
03:24by yourself
03:25I will tell you
03:27first
03:27if there is a pyramid
03:28shape
03:29to analyze the pattern
03:29time complexity
03:31if there is a difficult question
03:32then analyze the pattern
03:34not
03:35if we analyze the pattern
03:36the pattern
03:36if we analyze the pattern
03:37the time complexity
03:40will be clear
03:41now
03:42we have to not see the loop
03:44how much time is
03:45coming out
03:46we have to think
03:47intuitively
03:48how do we think
03:50we think
03:51where is the outer loop
03:52from the outer loop
03:54i is equal to 0
03:55from the end times
03:56where is the inner loop
03:57from the inner loop
03:58from the inner loop
03:58every time
03:58i is going to 0
04:00so I can say
04:01that the first time
04:02it will be 0
04:03the second time
04:04it will be 1
04:04and the third time
04:05it will be 2
04:06how many times
04:08it will be
04:08n-1
04:10times
04:11n-1
04:12so this is my
04:12whole series
04:13I have to take the sum
04:15I have to take the sum
04:16that the sum is
04:16n square
04:19so this will be
04:20big of n square
04:21so this will be
04:22this process
04:23should be
04:23in our mind
04:24every time
04:25we have to write
04:26the inner working
04:27every time
04:28we have to take the sum
04:28despite the sum of
04:28these types of