Which approach to summing 1 to n is most efficient?
- The formula n(n + 1)/2
- Recursion adding one at a time
- Two nested loops
- A loop adding each number
Answer
A) The formula n(n + 1)/2
The formula needs a single calculation whatever the size of n. SLO CS-11-B-01
Computer Science MCQ · More Unit 2: Computational Thinking and Algorithms MCQs · Practise