Efficiency of algorithms

EasyMedium
123456789
Question 9
Easy

Figure 1

Program X

limit = int(input("Enter a value: "))
sum_even = 0
counter = 1
while counter <= limit:
    sum_even = sum_even + (counter * 2)
    counter = counter + 1
print(sum_even)

Program Y

limit = int(input("Enter a value: "))
sum_even = limit * (limit + 1)
print(sum_even)

Select one option to indicate which of the statements is true about 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.

The efficiency of the programs cannot be compared without knowing the value of limit.

Efficiency of algorithms Questions

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