A small correction in your explanation. The FOR loop of course run for N time. The reason for (N+1) is the initialization of i variable take the frequency of 1 time. So the total frequency of loop will be (N+1). The comparison (i
Whenever we write cost as c3 we assume that c3 is the time taken to execute two operations - addition and assignment. So two operation are taken care by the cost (c3). Cost of each line can vary from computer to computer as all computers are different in terms of architecture, operating system ,etc. We could have written cost as 2, (1+1=2) where two 1's are contributed by assignment and addition operation. But this sometimes become confusing as different computer take different time to execute same operation, therefore we have generalized cost to be c1, c2, c3, etc. If I am not clear, do reply! Thanks
Why do you think so ? The statement inside the for loop runs for n times. Whenever there is nesting of loop like this then it would be n^2: for(i=0 to n-1) { for(i=0 to n-1) { //statement here runs for n^2 times } }
@@SunilDhimal because, checking loop is n+1, incrementing rows is i=i+1, then for next i its also i=i+1 again, so thats 2n and for initialization its 1, so n+1 + 2n + 1 = 3n+2 please get your facts right you honestly wasted some of my time other than that thanks.
@Ayman Madi : : My assumption here is this - each instance of for loop takes cost c2.All instance of for loop together has a frequency of n+1. Hence total cost is c2(n+1). The way you are calculating is not wrong, you are considering time contributed by each component of for loop(initialization, condition evaluation and increment). That way it comes to be: For initialization(just once): 1time Condition checking: n+1 times Increment : n times Total : 1+n+1+n = 2n+2 If you consider increment i++ as i=i+1, then it's collection of two operations: addition(+) and assignment(=), so For increment : n+n=2n (n for increment and n for assignment operation) That way It comes to be : Total : 1+n+1+2n = 3n+2 Your answer is always based on what you assume, all these ways are correct as long as you are clear about assumption. Answer is not that important, the steps followed to get the answer is more important. Thank you for commenting. Listen to what I have assumed first before commenting. If any doubts further, do not hesitate to ping me!
how is it that nobody wants to explain it as perfectly as this...
I've been searching for a clear and concise explanation and I've found it
Easily one of the finest overviews of this topic on TH-cam.
This is by far the best explanation. Thank you so much!!
Finally someone explain well 👌
All steps are very clear ! Hope you can make more videos and help the programming beginners !
Finally someone explained it properly .thanks man
Your support is incredible
A small correction in your explanation. The FOR loop of course run for N time. The reason for (N+1) is the initialization of i variable take the frequency of 1 time. So the total frequency of loop will be (N+1). The comparison (i
+1 for this, but here my focus is on Algorithm not how its implemented.
Great work bhai 👍
thank you very much , i now have clearer understanding for this part.Helped me a lot in my discrete structure subject!
Your explaination was great, thank you very much sir!
Wow. You are an amazing teacher!!
god bless you , it helped me a lot
I'm imagining myself in the position ..The way he taught was perfect.
Perfect explanation
Best tutorial on this topic
Really the best explanation I have found so far . Thanks a lot Sir.
Easy to understand tq soo much for your explanation sir
ur the best person ever
the best explanation so far...amazing
whats the difference between step count n freq count ? is c1 c2 ... necessary if we just want the time complexity??
should we write all steps say how it is arithmetic series etc or just the algorithm table and last calculation wil do in paper
any suggestions????????
Go for all steps involved !
Very precise and clear explanation. Thank you sir 🙏
VERY GOOD TUTORIAL SIR.WE NEED MORE TUTORIAL FROM YOU
Sir I have doubt that why c3 is having n freq.but it is having two operations...
Whenever we write cost as c3 we assume that c3 is the time taken to execute two operations - addition and assignment. So two operation are taken care by the cost (c3). Cost of each line can vary from computer to computer as all computers are different in terms of architecture, operating system ,etc. We could have written cost as 2, (1+1=2) where two 1's are contributed by assignment and addition operation. But this sometimes become confusing as different computer take different time to execute same operation, therefore we have generalized cost to be c1, c2, c3, etc.
If I am not clear, do reply!
Thanks
superb explanation !!!
wow, thanks bro!
What would be the cost/frequency for declaration? Like if a statement is int a, b;
How to deal with if else Cases?
Thank you Sunil
Thankyou sir..❤️best video
Life saver
Awesome sir..
you are genius
Thanks a lot
Why you are not having more subscribers 😭😭😭
Fantastic thanks.
my left ear enjoyed the video.
May be that the statement inside the for loop execute for n^2 time
Why do you think so ? The statement inside the for loop runs for n times. Whenever there is nesting of loop like this then it would be n^2:
for(i=0 to n-1)
{
for(i=0 to n-1)
{
//statement here runs for n^2 times
}
}
Why u draw that big O notation..
good video.
i thik the for loop will run n times .
Hocam Allah sizden razı olsun siz Hindistanlı hocalarımız olmasa ne yaparız biz. Kolay gelsin başarılarınızın devamını diliyorum
teşekkür ederim
Thankss:)
why there is no voice?
Thaaaanks!!
Did you mean cost is time required ?
Yes, its the time required to execute a particular line or a step.
GOD BLESS U
For loop time cmplexity is wrong
it is 3n+2
Can you please be more detailed, so that I can understand how did you get 3n+2 ?
@@SunilDhimal because, checking loop is n+1, incrementing rows is i=i+1, then for next i its also i=i+1 again, so thats 2n and for initialization its 1, so n+1 + 2n + 1 = 3n+2 please get your facts right you honestly wasted some of my time other than that thanks.
@Ayman Madi : : My assumption here is this - each instance of for loop takes cost c2.All instance of for loop together has a frequency of n+1. Hence total cost is c2(n+1).
The way you are calculating is not wrong, you are considering time contributed by each component of for loop(initialization, condition evaluation and increment). That way it comes to be:
For initialization(just once): 1time
Condition checking: n+1 times
Increment : n times
Total : 1+n+1+n = 2n+2
If you consider increment i++ as i=i+1, then it's collection of two operations: addition(+) and assignment(=), so
For increment : n+n=2n (n for increment and n for assignment operation)
That way It comes to be :
Total : 1+n+1+2n = 3n+2
Your answer is always based on what you assume, all these ways are correct as long as you are clear about assumption. Answer is not that important, the steps followed to get the answer is more important.
Thank you for commenting. Listen to what I have assumed first before commenting.
If any doubts further, do not hesitate to ping me!
RIP audio
Thank you! I have taken care of audio in my new video: th-cam.com/video/yILL5g5SveM/w-d-xo.html
keep it at 2x .
🔥❣️
there is no voice