Efficiency of algorithms

EasyMedium
123456789
Question 4
Easy

Figure 1

Program X

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

Program Y

num = int(input("Enter a positive integer: "))
total = num * (num + 1)
print(total)

Select one option to indicate which of the statements is true about the efficiency of the programs in Figure 1.

Both programs are equally efficient.

Program X is more efficient than Program Y.

Program Y is more efficient than Program X.

Program X is more efficient for small inputs, while Program Y is more efficient for large inputs.

Efficiency of algorithms Questions

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