Make your own free website on Tripod.com
SLIDE 100</TIT;E> <H2>Example 3</H2> <PRE> scanf("%d",&n); for(i=1 ,m=n+66;i<=m;i++) printf("%d\n",i); for(j=n/21,m=n/5 ;j<=m;j++) printf("%d\n",j);</PRE> <P>O(Program) = O(i-loop) + O(j-loop) = O(N) + O(N) = O(N) <H2>Example 4</H2> <PRE> scanf("%d",&n); for(i=1;i<=n;i++) for(j=i;j<=n;j++) printf("(%d,%d)\n",i,j);</PRE> <P>O(Program) = O(i-loop) <PRE>O(i-loop) = SUM(i,1,N) of O(j-loop) = SUM(i,1,N) of (N-i) = N*(N-1)/2 = O(N*N)</PRE> </body> </HTML>