00:00First let's talk about a simple loop
00:02If we have written a simple loop in a simple for loop
00:07What is the value? Iterator
00:09I is equal to 0
00:11I value N
00:13What can I say to N?
00:14N is my input size
00:17This can be the length of the array
00:19This can be the length of my string
00:20or any other input
00:22What happens every time? I is plus plus
00:24I can write the most simple loop
00:26which I can write
00:27Now there is a constant work in this loop
00:30It can be that this loop is something like this
00:32For the loop
00:34all the conditions
00:35What is constant work?
00:37To print value of I
00:39or to print value of N
00:42What is this?
00:43This is my constant work
00:44Why is constant work?
00:46Because this work
00:47It is one operation
00:50It is not multiple operations
00:51It is not multiple operations
00:51So this will always be one operation
00:55What is this work?
00:56Every time I print I
00:58I am also printing
01:00And what I am doing?
01:01I am also printing
01:02I am also printing
01:02And what I am doing?
01:04I am also printing
01:04I am also printing
01:04I am also printing
01:05I am also printing
01:08How is constant?
01:09Why is constant?
01:11Because my group of three is equal to my big O of one
01:14Why?
01:14Because we ignore constant
01:16Every three is one
01:18Every five is one
01:19Every ten is one
01:20Because we do not consider one
01:21Five, ten, hundred
01:23we don't consider such values
01:24or we talk about millions
01:27or billions
01:29or trillions
01:31when we call input size
01:33here 100, 1.5, 200
01:36or in the loop
01:37I have written 50 lines
01:38there is no difference
01:39my program's time complexity
01:44will not increase
01:45now let's talk about
01:46a simple loop
01:47how will I get out of time complexity
01:48I can think that
01:51if I have a constant work
01:53then the time complexity
01:54will be constant
01:56this value is constant
01:57it can be 3, 5, 100
02:00and 500
02:01but it is constant
02:03and the constant value
02:07is always less than n
02:08so how will I get out of time complexity
02:12I analyze
02:14how many operations
02:15I take a look at
02:16how many operations will perform
02:18and how many operations will perform
02:20the time my loop will run
02:21so I can see how many loops will run
02:24this loop will run
02:25this loop will run
02:28for i is equal to 0
02:30for i is equal to 0
02:32then i will update
02:34i value 0
02:36it has been constant
02:37then i value is updated
02:39now i value is updated
02:41then i will have constant
02:42work again
02:43then i will have k
02:44then i will be updated
02:46and i value is 3
02:49then i will be k
02:50it has been constant
02:52when i value is n
02:54i will be n-1
02:56this is my last loop
02:59so in this case
03:00i will have k
03:00then i value will be n
03:02and we will break
03:05How many loops went this loop? This loop went to zero from n-1 and how many I did this
03:11work?
03:12Every time I did k. If I run a loop once, it will work k. If I run a loop
03:17twice, it will work 2.
03:19If I run a loop twice, it will work 2. If I run a loop twice, it will work 3.
03:21If I run a loop twice, it will work 4.
03:22How many of my work did it? My work is equal to n multiplied by k.
03:290 from n-1 is n times and 1 from n is n times.
03:35If I run a loop twice, it will work n-1 or 1 from n. It is the same.
03:392 from n plus 1, 3 from n plus 2. What is happening in everything?
03:44I run a loop twice. If I run a loop twice, it will work k times.
03:52So, what can I say? My time complexity will be big of n into k.
03:57Now, what do I say about my time complexity rules? My time complexity rules were said that
04:01in time complexity, first, ignore constant.
04:04So, what will happen? Ignore constant and big of n.
04:07Because k is my constant. The other thing was that we have to take a big term.
04:11The biggest term is a term. I have n.
04:13So, my final time complexity will be in this simple loop. That will be big of n.
04:18That means, this loop will run in linear time.
04:21And you can also think that we write the same loop when we talk about linear search.
04:25For linear search, the for loop is the outer loop.
04:29That means, the loop looks like something. That is why the time complexity is big of n.
04:34That means, the loop int that's not something for me.
04:34For linear search, the path is the path.