Computational and Algorithmic Thinking
Computational and Algorithmic Thinking
THINKING 2011—2015
Introduction v
Computational and Algorithmic Thinking v
Algorithmic Thinking and the Australian Curriculum vi
Acknowledgments vi
Questions 1
Applying Rules 3
Logic 9
Analysis 19
Searching 19
Sorting 19
Patterns 21
Number of Routes 23
How Many Ways? 26
Analyse the Problem 31
Algorithms 35
Breadth-first Search 35
Shortest Path 48
Maximum Flow 51
Single Pass Algorithms 51
Dynamic Programming 54
Two Person Games 57
Greedy Algorithm 62
Lists 64
Working Backwards 66
Chains 67
Ad Hoc Algorithms 68
iii
Solutions 81
Applying Rules 83
Logic 87
Analysis 93
Searching 93
Sorting 94
Patterns 96
Number of Routes 98
How Many Ways? 101
Analyse the Problem 105
Algorithms 109
Breadth-first Search 109
Shortest Path 121
Maximum Flow 125
Single Pass Algorithms 126
Dynamic Programming 128
Two Person Games 132
Greedy Algorithm 139
Lists 144
Working Backwards 146
Chains 148
Ad Hoc Algorithms 150
Statistics 173
iv
Introduction
v
The integer answer questions are typically algorithmic. Students must devise and follow some
repeated systematic procedure. For each question the students are given three sets of data
of increasing size. These questions are explicitly designed to entice students into formulating
algorithms. The first data set is often small enough to be solved by ad hoc techniques. By the
second, students should have a feel for the problem and be developing systematic procedures
for solving the problem. These procedures can then be applied to the third data set.
Algorithmic and analysis questions are often variations on well-known classes of problems
such as shortest path problems (algorithm questions) and searching algorithms (analysis
questions), and some students may have already encountered them. Other questions are not
standard and students have to devise algorithms from the context of the problem.
The ‘Questions’ section of the book presents the questions, organised by category and prob-
lem type. The ‘Solutions’ section gives the solutions and answers. Each category is given a
general introduction, describing its relevance to information technology in general and pro-
gramming in particular. Each problem type also has an introduction, including the practical
applications of the problem type and an outline of the method of solution.
Acknowledgments
The AIOC is a department of the Australian Mathematics Trust (AMT), which provides
both financial and administrative support to the informatics program. Indeed, the formation
of the AIOC in 1999 was an initiative of Professor Peter Taylor, then Executive Director of
the AMT. Without the support of the AMT, the AIOC could not survive.
The Chair of the CAT problems committee since 2007 has been David Clark, who is also
the author of this book. For David, this has been a labour of love. His relentless and
vi
continuing enthusiasm is amazing. The problems in the CAT have been devised by past
and present members of the CAT problems committee: Ben Burton, Bernard Blackham,
David Clark, David Kennedy, Andrew Gray, Katherine Kavanagh, David Ananian-Cooper,
Dmitry Kamenetsky, Robert Newey, Christopher Chen, Judith Heglers and Mike Clapper.
Their ability to construct new and interesting problems continues to astonish me. Thanks
are also due to Margot Phillipps, Terry McClelland, Jan Honnens and Katherine Kavanagh:
teachers who have provided second round moderation of the competition. Their comments
and suggestions have helped to ensure that the problems are understandable by the students
and accessible to them.
Special thanks are due to Bernadette Webster for careful proofreading of this book, and of
all of the CAT problems before they go to print, and to Heather Sommariva for the cover
design.
This book was typeset in TEX, the mathematical typesetting system designed by Donald
Knuth. Many contributors have given freely of their time and expertise to extend the ca-
pabilities of TEX. The TikZ/PGF package written by Till Tantau was used in all of the
diagrams in this book. Finally, special thanks are due to the late Ian Lisle for expert advice
on all things TEX.
Mike Clapper
Executive Director
Australian Mathematics Trust
September 2016
vii
Questions
1
Applying Rules
On a distant planet, the dominant carnivore, the zab, is nearing extinction. The number of
zabs born in any year is one more than the (positive) difference between the number born in
the previous year and the number born in the year before that.
Examples: If 7 zabs were born last year and 5 the year before, 3 would be born this year.
If 7 zabs were born last year and 10 the year before, 4 would be born this year.
2 zabs were born in the year 2000 and 9 zabs were born in 2001. What is the first year after
2000 when just 1 zab will be born?
(A) 2009 (B) 2011 (C) 2013 (D) 2015 (E) 2017