Lesson 7.3 · Answer it
Tournament rounds
4 marksYou mark it yourself against the marking points
In a knockout contest, half of the players are out after each round. This function works out how many rounds are needed for a number of players, a whole number from 1 to 1000000.
def rounds(players):
count = 0
size = 1
while size < players:
size = size * 2
count = count + 1
return count
public static int rounds(int players) {
int count = 0;
int size = 1;
while (size < players) {
size = size * 2;
count = count + 1;
}
return count;
}
(a) State the value the function returns for 16 players. [1]
(b) State the Big O complexity of the function, where n is the number of players. [1]
(c) Explain your answer to (b), using how the loop's counter changes. [2]
[4]