Skip to content

Course home

Efficiency of algorithms

Efficiency of algorithms

EasyMedium
123456789
Question 8

Two different programs are written to calculate the sum of the first n n\,n odd positive integers.

Program A

n = int(input("Enter a positive integer: "))
total = 0
for i in range(1, n + 1):
    total = total + (2 * i - 1)
print(total)

Program B

n = int(input("Enter a positive integer: "))
total = n * n
print(total)

Which of the following statements is true about the efficiency of these programs?

A

Both programs are equally efficient.

B

Program A is more efficient than Program B.

C

Program B is more efficient than Program A.

D

The relative efficiency of the two programs cannot be determined without knowing the value of nnn.

Markscheme

Efficiency of algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Efficiency of algorithms

15 exam-style questions on AQA GCSE Computer Science Efficiency of algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank