<br><br><div class="gmail_quote">On 9 September 2010 23:39, Baba <span dir="ltr"><<a href="mailto:raoulbia@gmail.com">raoulbia@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi<br>
<br>
In below code "the outer loop test in step 4 will execute ( n + 1 )<br>
times (note that an extra step is required to terminate the for loop,<br>
hence n + 1 and not n executions), which will consume T4( n + 1 )<br>
time." (from <a href="http://en.wikipedia.org/wiki/Analysis_of_algorithms" target="_blank">http://en.wikipedia.org/wiki/Analysis_of_algorithms</a>)<br>
<br>
1 get a positive integer from input<br>
2 if n > 10<br>
3 print "This might take a while..."<br>
4 for i = 1 to n<br>
5 for j = 1 to i<br>
6 print i * j<br>
7 print "Done!"<br>
<br>
Why does step 4 execute n+1 times? what is the exta step mentioned<br>
above<br></blockquote><div><br>Because it does two things:<br> - increase i<br> - check whether i is still smaller than n. If it is not, the loop is terminated<br><br>Still, this is quite a simplification of what's really going on...<br>
<br> Almar <br></div></div>