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.
Practise AQA GCSE Computer Science Efficiency of algorithms with exam-style questions for GCSE Computer Science. 15 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.