is this algorithm correct?

2 years ago
10.1K

The indentation implies that it's line 3 that will repeat.So, what the pseudocode is saying is that after starting at zero,for each person in the room,we'll increase n by 1.Now, is this algorithm correct?Well, let's bang on it a bit.Does it work if there are 2 people in the room?Let's see.In line 1, we initialize n to zero.For each of these two people,we then increment n by 1.

Loading comments...