Efficiency of algorithms

EasyMedium
123456789
Question 2
Easy

Two programs are written to calculate the total number of unique handshakes that occur when N N\,N people in a room all shake hands with each other exactly once.

Program A

people = int(input("Enter number of people: "))
handshakes = 0
for i in range(1, people):
    handshakes = handshakes + i
print(handshakes)

Program B

people = int(input("Enter number of people: "))
handshakes = (people * (people - 1)) // 2
print(handshakes)

Justify why Program B is more efficient than Program A, particularly when the user enters a very large number.

[2]

Efficiency of algorithms Questions

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