How to find the average, worst complexity of a code
-
How to find the average, worst complexity of a code?? say for ex,
for i= 1 to n
{}
for j= 1 to i
{
x=x+1}
Please help me ..
Huh? :confused: Did you bother looking at your post? Notice anything "strange" about it? :doh:
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
How to find the average, worst complexity of a code?? say for ex,
for i= 1 to n
{}
for j= 1 to i
{
x=x+1}
Please help me ..
You have to claculate from your program; for this example first for loop execute "n" times and second loo execute n times because value of "i" is "n" suppose "T1" time need to execute one iteration in the first for loop and "T2" time needs for one iteration in second loop so it take T1*n + T2*n that is an order of n, ie it depend on input variable "n" This is the time complexity
-
You have to claculate from your program; for this example first for loop execute "n" times and second loo execute n times because value of "i" is "n" suppose "T1" time need to execute one iteration in the first for loop and "T2" time needs for one iteration in second loop so it take T1*n + T2*n that is an order of n, ie it depend on input variable "n" This is the time complexity
-
Hai Radhakrishnan, Thanks for your responce. Can you come again to tell me how it can be represented in Big O notation...
O(n) ?
Watched code never compiles.
-
O(n) ?
Watched code never compiles.
Yes it is the order of n O(n)