PDA

View Full Version : Closed Form Problem


joegonota
Mar 14, 2011, 07:31 AM
Hi all,

Please have a look of following question


Q:

Find the exact number of times, in terms of the natural number n that s is executed in the following algorithm


I:=0

while I<n do

s;

I:i+3;

od


Please give me some advise to solve this question... thanks a lot

Unknown008
Mar 14, 2011, 11:30 PM
I'm having trouble understanding your problem...

I'm particularly not familiar with the functions 'do', 's' and 'od' do...

jcaron2
Mar 15, 2011, 10:30 AM
The variable i starts at 0, then gets incremented by 3 each time through the loop (assuming I'm reading the syntax correctly; I'm not familiar with whatever language that is). The loop ends when i is no longer less than n. That means the loop runs approximately n/3 times.

If you want to get really specific, it actually runs (floor(n/3) + 1) times, where the "floor" function means that you round down to the nearest integer.