IOI · feeder round mock

Informatics mock paper 2.

Modelled on a written first-round informatics olympiad paper of the kind several countries use before their programming rounds: short questions on tracing code, logic, counting and complexity, then hand-worked algorithm questions; the medal bands are only a rough guide.

90minutes50marksNo calculator
  • Answer all questions. You have 90 minutes.
  • Section A: choose one answer for each question. Section B: show your working and reasoning.
  • Code is written in Python. Pseudocode in Section B uses the same ideas in plain words.
  • You may use scrap paper to trace programs by hand. No computer or calculator.
  • Total: 50 marks (Section A 24, Section B 26).

The clock starts when you press Start. Multiple-choice answers are marked for you; for written answers you get the mark scheme and give yourself the marks. Your answers stay on this device.

Feeder round mock paper 2
TheLucidSTEM · Informatics olympiad feeder round mock · 90 minutes · 50 marks · No calculator
Name: ______________________   Date: ____________ · MARK SCHEME
Data sheet

Python reminders

  • range(a, b) gives a, a + 1, ..., b - 1.
  • // is whole-number division (rounding down) and % is the remainder.
  • max(p, q) gives the larger of p and q; sum(a) adds up a list.
  • Lists are indexed from 0: a[0] is the first item.
  • not, and and or combine true/false conditions; != means "not equal to".

Section A: multiple choice

Suggested time 35 minutes. Two marks each, no penalty for wrong answers.

1[2]
What does this program print?
n = 12
steps = 0
while n != 1:
    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1
    steps += 1
print(steps)
2[2]
x and y are whole numbers. Which condition is true for exactly the same x and y as
not (x > 3 or y <= 2) ?
3[2]
What does this program print?
a = [3, 1, 4, 1, 5, 9, 2, 6]
for i in range(1, len(a)):
    a[i] = max(a[i], a[i - 1])
print(sum(a))
4[2]
How many calls to f are made in total (including the first one) when f(16) is evaluated?
def f(n):
    if n <= 1:
        return 1
    return f(n // 2) + f(n // 2)
5[2]
work() takes constant time. As $n$ grows, how does the total number of calls to work() grow?
for i in range(1, n + 1):
    j = i
    while j <= n:
        work()
        j += i
6[2]
You have 8 different numbers and may only compare two of them at a time. What is the smallest number of comparisons that is always enough to find both the largest and the smallest of the 8?
7[2]
Five friends each say how many of the other four they shook hands with (two people shake hands at most once). Which list of answers is possible?
8[2]
In this map, # is land and . is water. Two land squares belong to the same island if they share a side (touching only at a corner does not count). How many islands are there?
##..#
#..##
..#..
##..#
#.###
9[2]
A heap is stored in an array with positions numbered from 1: the root is at position 1, and the children of position $i$ are at positions $2i$ and $2i + 1$. What is the position of the parent of the parent of position 45?
10[2]
Six trains use a station. Each train needs a platform from its arrival time until its departure time, and a platform holds one train at a time.
T1 09:00 to 09:40, T2 09:10 to 09:30, T3 09:25 to 10:05, T4 09:35 to 10:02, T5 09:45 to 10:15, T6 10:00 to 10:10.
What is the smallest number of platforms needed?
11[2]
Two sorted lists, one with 5 numbers and one with 7, are merged into one sorted list. Each step compares the front numbers of the two lists and moves the smaller one across; when one list is empty the rest of the other is copied with no more comparisons. All 12 numbers are different. What is the largest number of comparisons this can take?
12[2]
How many digits does the number 1000 have when it is written in base 3?

Section B: structured questions

Suggested time 55 minutes, about 18 minutes per question. Explain your reasoning: a correct method earns marks even if the final number is wrong.

13Cabling the school[9 marks]

A school wants to join its six buildings A to F with network cables so that every building can reach every other one, possibly through other buildings. The cables that can be laid and their costs (in thousands of pounds) are:

CableA–BA–CB–CB–DC–DC–ED–ED–FE–FB–F
Cost734659211812

A cheapest network that joins every building is a minimum spanning tree. Kruskal's algorithm finds one: look at the cables from cheapest to dearest, and lay each cable unless its two buildings are already joined by cables laid earlier (then it would only make a loop).

(a) Use Kruskal's algorithm. List the cables in the order the algorithm looks at them, and say for each one whether it is laid or rejected, until the network is complete.

[3]

(b) State the total cost of the network.

[1]

(c) The head teacher insists that the cable A–B is laid (it runs along an existing duct). Find the cheapest network that includes A–B, and its cost.

[2]

(d) Explain why the cheapest cable, D–E, must be part of every cheapest network, whatever the other costs are.

[2]

(e) For a network with $n$ buildings and $m$ possible cables, what is the time complexity of Kruskal's algorithm if the cables are sorted by cost and a union-find (disjoint set) structure is used to test whether two buildings are already joined?

[1]

14Squeezing the message[9 marks]

A message of 100 letters uses only the letters A to F, this many times each:

LetterABCDEF
Count30251412118

We want to give each letter a code made of 0s and 1s so that the whole message is as short as possible. Huffman's method does this. Start with each letter as a tree on its own, with its count as its weight. Repeatedly take the two trees with the smallest weights, and join them under a new root whose weight is the sum of the two. Stop when one tree is left. The code for a letter is read along the path from the root to that letter: 0 for each step to the left and 1 for each step to the right. In this question, when two trees are joined, the one with the smaller weight always goes on the left.

(a) Carry out Huffman's method. List the joins in order, giving the two weights joined and the new weight each time.

[3]

(b) Write down the code for each letter. Find the total number of bits in the coded message, and compare it with a code that uses the same number of bits for every letter.

[3]

(c) Using your codes from (b), decode 0111000001.

[1]

(d) For an alphabet of $k$ letters, how many joins does Huffman's method make? Name a data structure that lets each join find the two smallest weights quickly, and give the time complexity of the whole method with it.

[2]

15Searching a rotated list[8 marks]

A sorted list of different numbers has been rotated: some numbers were taken from the front and put, in order, at the back. For example, this list of $n = 9$ numbers, with positions 0 to 8:

Position012345678
A2331384552491217

Ordinary binary search for a value x is:

lo = 0
hi = n - 1
while lo <= hi:
    mid = (lo + hi) // 2
    if A[mid] == x: report mid and stop
    if A[mid] < x: lo = mid + 1
    else: hi = mid - 1
report "not found"

(a) Trace ordinary binary search on the list above for x = 9. Give lo, hi and mid at each step, and the final result.

[2]

(b) The smallest number is at the point where the list was rotated (position 5 in the example). Describe a method that finds its position in $O(\log n)$ time by comparing A[mid] with A[hi], and trace it on the example.

[3]

(c) Explain how to use your answer to (b) to search for any value x in the rotated list in $O(\log n)$ time.

[2]

(d) Now suppose the list may contain repeated numbers. Give two lists of the same length, both rotated sorted lists, that show why no method can always find the smallest number without looking at almost every position.

[1]

TheLucidSTEM practice paper. Questions are original and written in the style of a first national round; this is not an official olympiad paper.