Counting the innermost calls
For , exactly how many times does work() execute in this fragment?
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
for (k = 1; k <= n; k *= 2)
work();
Show hints (2)+
- The two outer loops each run times; the inner one does not -
kdoubles. - Count the powers of two in : . Then multiply the three counts.
Answer
Reveal answer →Final answer
1280
Create a free account to see the full worked solution and track your progress.
Interview format: Prop Trading, Options Trading