A game developer is designing a script to calculate the total experience points (XP) required for a player to reach level NNN. The XP required for each level i i\,i is defined as 50i50i50i. The developer considers two different algorithms to perform this calculation.
N = int(input("Enter level: "))
total_xp = 0
for i in range(1, N + 1):
total_xp = total_xp + (50 * i)
print(total_xp)
N = int(input("Enter level: "))
total_xp = 25 * N * (N + 1)
print(total_xp)
Algorithm Q is more efficient than Algorithm P.
Justify this statement.
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.