Thread: Big oh problem
View Single Post
  #2  
Old October 15th, 2009, 11:39 PM
CaptainBlack's Avatar
CaptainBlack CaptainBlack is offline
Grand Panjandrum
 
Join Date: Nov 2005
Location: South of England
Posts: 12,271
Country:
Thanks: 777
Thanked 3,995 Times in 3,223 Posts
CaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond repute
Default

Quote:
Originally Posted by Acessd23 View Post
I couldn't solve this one ?

What is the Big O of this function ?

Void two(int n)
{
int
i,j,k,n;

for
(i=1;i<=n;i++)
for (j=(i+1);j<=n;j++)
for (k=1;k<=j;k++)

o(1) statment;

}
The loop operations count of the inner most loop is o(1)j, so that of the next outer loop is:

\sum_{j=i+1}^n o(1)j

ans so for the outermost loop:

\sum_{i=1}^n \left[ \sum_{j=i+1}^n o(1)j\right]=o(1)\sum_{i=1}^n \left[ \sum_{j=i+1}^n j\right]

CB
__________________
Truth does not change because it is, or is not, believed by a majority of the people.

Giordano Bruno
Reply With Quote