Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
Good Day,

Given a pseudo code below:

<br />main()<br />{<br />for(int i=0;i<n;i++)><br />{<br />x[i]=func1(func2(x[i]));<br />}<br />}<br /><br />func1(x[])<br />{<br />for(int i=0;i<length(x);i++)><br />//Do something here<br />}<br /><br />func2(x[])<br />{<br />for(int i=0;i<length(x);i++)><br />//Do something here<br />}<br />

How can I compute for the Asymptotic notation? I know that the loop in main() is O(n) and both func1 and func2 are O(n). But How can I combine the 3? Can I even combine the 3 to get O(N^3)? or it will be just O(3N)?

Thanks! :)

Posted

1 solution

What would be your analysis of this?

<br />main()<br />{<br />	for(int i=0;i<n;i++)><br />	{<br />		for(int j=0;j<n;j++)><br />		{<br />			for(int k=0;k<n;k++)><br />			{<br />				// do the something from func2<br />			}<br />			// do the something from func 1<br />		}<br />	}<br />}<br />


Edit: Ah, better.
 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900