Sie sind auf Seite 1von 299

Olympiads

in Informatics

Olympiads
Olympiads
in
Informatics
in Informatics
Volume 10,
2016
Volume
10,
2016

J. ALEMANY FLOS, J. VILELLA VILAHUR


eSeeCode: Creating a Computer Language from Teaching Experiences

3
19

S. COMBFIS, G. BERESNEVIIUS, V. DAGIEN. Learning Programming through Games


and Contests: Overview, Characterisation and Discussion

39

. ERDSN NMETH, L. ZSAK


The Place of the Dynamic Programming Concept in the Progression of Contestants Thinking

61

S. GRTTER, D. GRAF, B. SCHMID


Watch them Fight! Creativity Task Tournaments of the Swiss Olympiad in Informatics

73

J.I. GUNAWAN. Understanding Unsolvable Problem

87

J. HROMKOVI. Homo Informaticus Why Computer Science Fundamentals are an Unavoidable Part of Human Culture and How to Teach Them

99
111

M. KABTOV, I. KALA, M. TOMCSNYIOV. Programming in Slovak Primary Schools

125

E. KALINICENKO, M. OPMANIS. Collecting, Processing and Maintaining IOI Statistics

161

A. KARCZMARZ, J. CKI, A. POLAK, J. RADOSZEWSKI, J.O. WOJTASZCZYK


Distributed Tasks: Introducing Distributed Computing to Programming Competitions

177

M.M.I. LIEM. Reshaping Indonesian Students Training for IOI

195

W. Di LUIGI, G. FARINA, L. LAURA, U. NANNI, M. TEMPERINI, L. VERSARI


oii-web: an Interactive Online Programming Contest Training System

207

W. van der VEGT.


Bridging the Gap Between Bebras and Olympiad; Experiences from the Netherlands

223

T. VERHOEFF. Problem Solving, Presenting, and Programming: A Matter of Giving and Taking

231

REPORTS
M. DOLINSKY. Gomel Training School for Olympiads in Informatics

237

V. DUMANYAN, A. ANDREASYAN.
Armenia: IOI Participation and National Olympiads in Informatics

249

A. GREMALSCHI, A. PRISACARU, S. CORLAT.


Olympiads in Informatics in Republic of Moldova

255

A. IGLIKOV, M. KUTYBAYEV, B. MATKARIMOV. IOI 2015 Report

263

A. KHUDER, D. TSEDEVSUREN. The Informatics Olympiad in Mongolia: Training Resources for non-English Speaking Students

279

I. KIRYNOVICH, A. TOLSTSIKAU. Belarusian Olympiad in Informatics

285

ISSN 1822-7732

ISSN 1822-7732

Volume 10, 2016

J. HROMKOVI, T. KOHN, D. KOMM, G. SERAFINI


Examples of Algorithmic Thinking in Programming Education

Olympiads in Informatics

R. CASTRO, N. LEHMANN, J. PREZ, B. SUBERCASEAUX


Wavelet Trees for Competitive Programming

10

IOI

Inter

n at i

nal

Olym

piad

in

Infor

ics
m at

ISSN 1822-7732
INTERNATIONAL OLYMPIAD IN INFORMATICS
VILNIUS UNIVERSITY
INSTITUTE OF MATHEMATICS AND INFORMATICS

OLYMPIADS IN INFORMATICS
Volume 10 2016
Selected papers of
the International Conference joint with
the XXVIII International Olympiad in Informatics
Kazan, Rusia, 1219 August, 2016

OLYMPIADS IN INFORMATICS

Editor-in-Chief
Valentina Dagien
Vilnius University, Lithuania, valentina.dagiene@mii.vu.lt
Executive Editor
Richard Forster
British Informatics Olympiad, UK, forster@olympiad.org.uk
International Editorial Board
Benjamin Burton, University of Queensland, Australia, bab@maths.uq.edu.au
Michal Foriek, Comenius University, Bratislava, Slovakia, misof@ksp.sk
Gerald Futschek, Vienna University of Technology, Austria, futschek@ifs.tuwien.ac.at
Mile Jovanov, Sts. Cyril and Methodius University, Macedonia,
mile.jovanov@finki.ukim.mk
Marcin Kubica, Warsaw University, Poland, kubica@mimuw.edu.pl
Ville Leppnen, University of Turku, Finland, villelep@cs.utu.fi
Krassimir Manev, New Bulgarian University, Bulgaria, kmanev@nbu.bg
Seiichi Tani, Nihon University, Japan, tani.seiichi@nihon-u.ac.jp
Peter Taylor, University of Canberra, Australia, pjt013@gmail.com
Troy Vasiga, University of Waterloo, Canada, tmjvasiga@cs.uwaterloo.ca
Peter Waker, International Qualification Alliance, South Africa,
waker@interware.co.za
Willem van der Vegt, Windesheim University for Applied Sciences, The Netherlands,
w.van.der.vegt@windesheim.nl

The journal Olympiads in Informatics is an international open access journal devoted to


publishing original research of the highest quality in all aspects of learning and teaching
informatics through olympiads and other competitions.
http://ioinformatics.org/oi_index.shtml

ISSN 1822-7732 (Print)


2335-8955 (Online)

International Olympiad in Informatics, 2016


Vilnius University, 2016
All rights reserved

Olympiads in Informatics, 2016, Vol. 10, 12


2016 IOI, Vilnius University

Foreword
Time flies like an arrow
A popular example from the world of Artificial Intelligence (and Computational Linguistics), the phrase Time flies like an arrow is used to illustrate the ambiguity of language and the difficulty in comprehending structure. As a metaphor, it expresses how
quickly time passes. Study the syntax and you can argue that its an instruction to record
the movement of flies (perhaps in the manner of an arrow, or only those that are similar
to arrows), a description as to the preferences of a breed of fly, etc. Some interpretations have meaning, others less so, but underlying this is the message that something
apparently straightforward can have multiple meanings, nuances, interpretations. An
unexpected depth of meaning within a simple form.

IO
IO Informatics Olympiads. For those of us involved with national and international
olympiads there are numerous reasons why we got involved. For some, it has been
the challenge of competing: an opportunity to flex the intellectual muscles, a delight
in problem solving or even the pleasure of pushing yourself against other similarly
minded individuals. For others, it is the academic pursuit as the olympiads provide a
mechanism for learning and teaching: a way to practice skills and infuse knowledge; a
way to demonstrate that knowledge, skill and application to the wider world. Perhaps
for others it is the sense of community: fellow students, fellow educators, competitors
and friends. All of this before we even ask the question as why we stay involved.

10
There are, so says the old joke, 10 types of people in the world those who understand
binary and those who do not. In our modern world it is increasingly important to be
amongst those who understand. If we go back to the first days of the IOI, computer science was still a specialist pursuit. We had had a decade of home computers, so computers were accessible to many, and computing was appearing school curricula, but unless
you took an interest your exposure could be fleeting. We now exist in a world where
people carry powerful computers in their pockets ask yourself how many of the competitors at this years IOI carry a phone but do not wear a watch. So many facets of daily
life aided by computer programs, a many-headed beast that demands constantly to be

fed. It is not just teaching individuals how to program, most people will never write or
need to write a line of code, but an understanding of what is happening inside the black
box how things work, what is feasible, knowing what is going wrong to know how to
make things right is an important skill.

10
This is the 10th year for the Olympiads in Informatics journal. The first year when we
have publishing two volumes, as we are delighted to publish a special volume celebrating the informatics education of our host special thanks is given to the guest editor
Marina Tsvetkova. We have published a total of 185 papers showcasing 200 authors
from 50 countries. Technical papers and country reports. Algorithms and tasks. Reviews and opinions. The format of the journal is very similar to those early days; a
forum for those in the community to write about specialised technical issues, an opportunity to share our experiences and knowledge, and to give freedom for those who
are not academics to talk about their work. Looking back with the benefit of hindsight
we might have developed the journal in a different direction but, with that same knowledge, we can say that we have fulfilled (in the most part) the vision and aims that we
had when first establishing the conference.
Things are not always as they seem; it certainly does not seem like 10 years already.
Time flies like an arrow indeed.
There are individuals without whose tireless work this volume of the journal indeed every volume of the journal would not exist. As always, thanks are due to all
those who have assisted with the current volume authors, reviewers and editors. A lot
of work goes, not only to the writing of the papers, but to an extended period of review
and correction and, in several cases, translation. Peer viewing all of the papers takes a
significant amount of time and work and special thanks should be given to those otherwise unsung reviewing heroes: Benjamin Burton, Sbastien Combfis, Walter Gander, Gintautas Grigas, Mathias Hiron, Ville Leppnen, Pivi Kinnunen, Jari Koivisto,
Krassimir Manev, Martin Opmanis, Rein Prank, Jrat Skpien, Peter Taylor, Ahto
Truu, Willem van der Vegt. Particular thanks are due to the organisation committee for
IOI2016 in Russia without whose assistance we would be unable to hold the conference. Their assistance, during what is an already busy period, is gratefully received.
Editors

Olympiads in Informatics, 2016, Vol. 10, 318


2016 IOI, Vilnius University
DOI: 10.15388/ioi.2016.01

eSeeCode: Creating a Computer Language


from Teaching Experiences
Joan ALEMANY FLOS1, Jacobo VILELLA VILAHUR2
Fundaci Aula: 34 Av. Mare de Du de Lorda, 08034 Barcelona Spain
Explorium: Samals 1 L3, 08530 La Garriga Spain
eSeeCode.com
2
Aula Escola Europea: 34 Av. Mare de Du de Lorda, 08034 Barcelona Spain
eSeeCode.com
e-mail: jalemany@eseecode.com, jvilella@eseecode.com
1

Abstract. It has been almost 50 years since the creation of Logo one of the first educational
programming languages. Although most people agreed that it was important to teach computational thinking to children, only recently have school and district leaders begun to adopt curricula
to include it mainly through Scratch. In many cases this adoption has failed to provide the right
methodologies and tools to teachers.
In this paper, we analyse some of the different languages used in classrooms today and we
propose an improved alternative that we have created eSeeCode. We also share our experiences
using this language in classrooms and how students can learn using this tool.
Keywords: informatics curriculum, promoting informatics, programming language.

1. Overview
Reading Paperts Mindstorms: Children, Computers, and great ideas, one can have the
feeling that we have not advanced much in the past 35 years (Papert, 1980). Many countries are trying to include Coding as a required skill to learn in schools, either as a specific subject or as part of a technology course. However, in many schools, teachers do
not have the resources, materials and/or knowledge to bring computer science and coding into the classroom. This is the case of Spain, among other countries, where computer
science has been introduced into the curriculum, but has failed to provide the details on
how to implement it properly, thus providing teachers the freedom and responsibility to
decide how to teach some basic computer science concepts (Saez-Lopez etal., 2016,
Ackovska etal., 2015, Duke etal., 2000).
In this paper, we will analyse several computer languages and materials, and we
will explain the difficulties students find when using them in class. As Edsger Dijkstra
explains, the selection of the programming language will influence how the students will

J. Alemany Flos, J. Vilella Vilahur

understand computer science (Dijkstra, 1999). We will base our examples on some of the
most popular computer languages used in Spain today, although this experience can be
extrapolated to many other countries.

1.1. Key Terms


To begin, we will use the term educational computer language in a broad sense, as a
programming language used to teach coding in classrooms, ranging from professional
computer languages such as C++ to puzzle-related languages as Lightbot. Because in
many cases language and programming environment cannot be analysed separately, we
will use them indistinguishably.
We will use the term text-based coding to describe languages that permit students to
type their own code, giving them total freedom in the expressions they write. In contrast,
we will use the term visual block based programming as the type of coding where you
select your own blocks, and build the programs with a drag-and-drop interface. There is
a fundamental difference when discussing the use of these languages in the classroom,
as the former, generally speaking, cannot prevent students from making syntax errors,
while the latter prevents these type of mistakes. Fig. 1 and Fig. 2 show different examples of text-based coding and visual block based programming.
We will differentiate between two kinds of paradigms when discussing different approaches to teaching. The first will be Problem Solving, where the teacher can present
the student a short, self-contained problem that needs to be answered. In the particular
case of this paradigm, we will also use the term Puzzle Solving. Similar in concept
to problem solving, we consider puzzle solving to have more of a recreational focus,
where there is a known set of rules that include multiple variations. For example, when
solving a sudoku puzzle there is a specific set of rules, and by changing the numbers

Fig. 1. Text-based coding example with Logo to create a square.

Fig. 2. Visual coding example with EV3 to make a Lego Robot move in a square pattern.

eSeeCode: Creating a Computer Language from Teaching Experiences

you change the problem. The teacher acts as a problem-setter or planifier, deciding
which problems to be solved at each moment, such as when a student is asked to code
the Eratosthenes sieve.
As an alternative to problem solving we find Project-based learning. In Spain, this
strategy is gaining increased attention in the school setting. As part of project-based
learning, students take a more active and creative role by pursuing an authentic and realworld project that addresses essential questions and works towards gaining an enduring
understanding of a relevant issue. The teacher here is more of a guide or facilitator that
helps the student when needed. In computer science this has the form of software design,
applied programming and modelling. For example, a student could work on solving the
problem of being able to identify a number as prime or not, with the project title being
Create a game that uses prime numbers.

1.2. Languages
To help keep the explanation focused, we have created a list of the main languages used
in schools in Spain, and have classified them by similarity of characteristics.
The final result is shown below:
Under text-based coding we will find two separate groups: the pure educational languages such as Logo or Processing, and the professional languages such as C++, Java,
Python and Javascript.
Under visual block based coding we find again two groups: educational languages
such as Scratch, Alice, Kodu, Ev3, AppInventor, and the group of puzzle languages
such as Lightbot and Beebot. Strictly speaking, Lightbot and Beebot are not complete
languages, but they are used to teach basic structures to students. It is for this reason that
we have decided to include them in our analysis.
Although each language has its own particular characteristic, we will analyse a representative of each group. The languages we have chosen are: Logo, C++, Scratch and
Lightbot.

2. Main Characteristics
To be able to compare the different languages we have created a short introduction for
each one.

2.1. Logo
Originally created by Wally Feurzeig and Seymour Papert in 1967, there are many versions of the language used in schools. Its main objective was to teach programming to
students from ages five to thirteen (Papert, 1980). Due to the fact that it has been around

J. Alemany Flos, J. Vilella Vilahur

for so long, there has been more than 300 versions of the language, with a substantial
amount of literature related to it. (Boytchev, 2013).
Main characteristics:
Educational (ages 513).
The majority of versions use text-code.
The first activities proposed were problem-solving oriented, although there was
some space for creativity. This will vary with versions.
Uses a drawing area where you can move a pointer called a Turtle.
Main academic fields are basic algorithmics and 2D3D geometry depending on
the version.
In general there were no debuggers, but a step-by-step execution was possible
in many versions, which helped locate errors. Also syntax errors are difficult to
correct.

2.2. C++
Designed by Bjarne Stroustrup in 1983, C++ is a professional computer language utilized
heavily in many academic and professional circles. It is a compiled language, allowing
the user to be able to select a programming environment. Its standard library makes it
easier to use, as compared to its predecessor C (Stroustrup, 2007). It is important to note
that in this category that there are very different approaches depending on the paradigms
used (Duke etal., 2000), but we will not take them into consideration for the current
analysis and will common ground.
Main characteristics:
Professional (ages 12+)
C++ uses formal code.
The language accepts both problem-solving activities and project-oriented
learning.
No drawingarea. General interface uses a console to write and read (input/output). This can be extended to use of files.
Main academic fields are advanced algorithms, data structures, and numerical
problems. Uses of classes helps teach system design.
Depending on the Interface there is a good debugger, but syntax errors are hard
to read.

2.3. Scratch
Scratch was created in 2005 by Lifelong Kindergarten research group at Massachusetts
Institute of Technology Media Lab led by Mitchel Resnick. Although you can trace some
of its origins to Logo, its different approach to teaching computer science places it in a
different category (Resnick etal., 2009).

eSeeCode: Creating a Computer Language from Teaching Experiences

Main characteristics:
Educational (ages 816).
It uses visual block based programming.
The language is more focused on project-oriented programming.
There is a drawing area used to place objects and move them around.
Main academic fields cover basic algorithm, software design.
Due to the visual programming interface with blocks, it is impossible to get syntax
errors. There is no debugger.

2.4. Lightbot
There is an educational movement promoted by code.org to reach children in different
regions of the world and give them tutorials to learn how to code. This movement started
as the Hour of code and has had a big impact all around the world. Almost 200,000
events were carried out in more than 140 countries. (Code.org, 20132016)
Many schools around the world use this material as an introductory material for
Computer Science. Among the different tutorials that you can find, we selected one that
had a large acceptance rate in the teacher community in Spain Lightbot.
Lightbot is a puzzle-based game where you need to light some squares on a grid. It
was created in 2008 by Danny Yaroslavski, but it was with the hour of code that it became popular. (Gouws etal., 2014)
Main characteristics:
Educational (ages 48 and 9+).
It uses visual block based programming.
The language is focused only on puzzle solving.
It has nice animations of a robot moving around.
Main academic fields cover basic algorithms (no variables).
Impossible to get syntax errors, the execution can be considered step-by-step.

3. Developing a Curriculum
It is clear that these languages are difficult to compare to one another because of their
fundamental differences. To be able to do so we will analyse its uses in the classroom
and their main drawbacks if used alone. Later we will study the combination of one or
more language.
When considering the development of a curriculum we have to take into account
many factors, but mainly the maturity of the students (their age) and the amount of time
they will spend engaging with that curriculum. In our case we will consider students
from primary secondary schools, and a relatively long length of time of engagement
(34 years). Although some consider this length insufficient (Winslow, 1996), it is a
valid starting point to achieve competence in programming. Some main objectives can

J. Alemany Flos, J. Vilella Vilahur

be found in some studies (Duncan and Bell, 2015) and in some publications like the
Computing Progression Pathways (Dorling, 2014).

3.1. Teaching with Only One Language


Using the code.org tutorials in the classroom may seem like a good idea because of the
students high level of initial engagement; however, over time this strategy can backfire
if it is assigned for too long as the teacher has limited control over the content (s/he cannot put his own problems), and the tutorials are short and very specific.
One of the programs strong points is that the students get positive feedback and do
not feel frustrated when they fail. This is probably due to the fact that they view Lightbot
and other tutorials in code.org as a game, instead of a class problem.
If we look at the drawbacks from Lightbot we can see that the number of commands
is very limited and do not include variables. For younger children this is good because
the less options you give them the more focused and easy it will be to arrive at solutions.
On the other hand it is not good if the students are mature enough to learn and understand
it quickly. The use of loops is another drawback. To create a loop one must make a procedure that calls upon itself (as in recursion). This makes an infinite type of loop. Although
the students can find it intuitive, they have a difficult time understanding conditionals
and being able to predict this kind of behaviour. Fig. 3 shows the use of loops and functions. We have to keep in mind that although some teachers might use it as a tool to teach
programming, it does not cover some basic algorithmic concepts that are important, and
its programs cannot be generalised. (Lightbot 2016, Gouws etal., 2014 )
Currently in Spain the most popular educational programming language is Scratch,
where it has become quite popular, evidenced by the fact that Barcelona hosted the Connecting Worlds Scratch Conference in 2013. With Scratch, students are engaged and
motivated (Saez-Lopez, 2016), but after many years of use their interest wanes. This is
a big drawback because it generates apathy towards programming and, in some cases,
a dislike for programming altogether. There are also some technical drawbacks. For
example, the lack of text coding makes it difficult to read and write long conditionals
and programs. There are some projects to overcome this difficulty (Harvey and Mnig

Fig. 3. Lightbot usage of recursive procedures instead of loops.

eSeeCode: Creating a Computer Language from Teaching Experiences

2010), but it is not included in the main tool. In addition, the high level language makes
the student miss the opportunity to understand what is behind some of the instructions.
Finally, as it can be seen in Fig. 4, Scratch allows some parallel programming, which
is actually not accurate as it is executed sequentially and depends on the order the procedures were created. This is a problem because the student cannot guess the results of a
given program, which is one of the main objectives when teaching CS. (Dorling, 2014)
For a long time the most popular educational programming language in Spain was Logo.
It was used in the 1980s through early 1990s, but its use faded away in the late 1990s. We
can see this, for example, because it disappeared from the teacher majors in universities.
There was not an immediate substitution by another language, but the government stopped
promoting it as it was not news. This is reflected, for instance, in the use of it when training
teachers at that time. (Simon, 1996) At the onset, students were motivated by this new approach to teaching and learning (Rubinstein, 1974), but today the look of a majority of the
Logo platforms appear outdated and need a visual update. There are two major drawbacks
to Logo. Its theoretical use was for students aged 513, with newer versions this could be
extended until age 15, but text-based coding may bring syntax errors, and students need
some maturity to be able to correct them. If not well attended students would get frustrated
with programs that could not run. At the same time, similarly to Scratch, it has a limited
life span in the student studies due to the apparent lack of practical utility.
The last group of languages to analyse is the professional ones. This are the most
common choice among high school students. The students see the real value of coding and can explore other areas such as physics and mathematics, but because it is not
prepared for the classroom the learning curve is very steep. Winslow describes the five
steps from novice to expert (Winslow, 1996), in small-to-medium classrooms, the steep
learning curve produces a clear and early separation between those who understand the
content (and move through Winslow learning steps) and those who do not and remain as
Novices. Another drawback is that due to the lack of visual assistance (in general) and

Fig. 4. Scratch multiple parallel procedures.

10

J. Alemany Flos, J. Vilella Vilahur

less attractive interface it is more difficult to motivate the students to use it. The syntax
of some functions can also be a problem for some students. For instance, the syntax of
the for loop is more complicated than in other languages, which makes basic algorithms
sometimes hard to teach (Finkel etal., 1994, Robins and Rountree, 2003). Depending
on the programming environment used, the syntax errors are very difficult to read to the
untrained eye, as can be seen in Fig. 5, where only a single character missing produces
20 lines of errors when compiling.
One big advantage is the amount of resources that can be found on the internet, in
particular online judges like Codeforces, Timus, Topcoder, etc. With this sort of information it is really easy to prepare lists of problems for the students to engage.
It is worth pointing out that, in general, all of these languages and platforms are
student focused. There are few tools for the teachers, and this makes using only one
language more difficult. There are some positive exceptions, like the case of Jutge.org.
(Jutge 20082016, Gimnez etal., 2012) This online automated judge has been prepared
as a tool for the classroom and not just for self-learning. Teachers can set up classes,
have their own sets of problems and can view students progress. This kind of platform
contributes to the gamification of learning computer science, by giving achievements,
keeping track of the number of problems solved, etc. When students perceive it as a
game, they become more motivated and less frustrated.

4. Our Proposal: eSeeCode


After the analysis of the pros and cons of the different languages we decided that we
should try to create a language that would eliminate almost all the weaknesses.
The result of our work is eSeeCode both a language and a programming environment.
Main characteristics:
Both visual code and formal code. You can transition from one to another.

Fig. 5. Syntax error in C++. The programming environment is CodeBlocks.

eSeeCode: Creating a Computer Language from Teaching Experiences

11

Both educational and professional language.


It is problem solving oriented.
Main academic areas cover basic and advanced algorithms, 2D geometry (turtle
graphics) and numerical problems.
Has a debugger, and includes simple syntax errors handling.

4.1. Description of eSeeCode


eSeeCodes environment offers four different programming levels: from a pure graphical click-and-run interface to a pure text syntax highlighting editor, with two middle interfaces. We call this levels views, because we want to show the students that code is just
a representation that can have different forms. This can be seen in Fig. 6. This allows for
a smooth progress in programming learning while keeping a common general interface,
instruction set and platform. Time saved in this manner can be spent reinforcing other
important objectives or learning a complementary second language.
The Touch view is our approach to the Puzzle Solving problems and is designed to
work with students of ages 58. The set of instructions is represented by a set of icons
(Fig. 7). The icons at this level have no text to maximize ease of use. These instructions

Fig. 6. Different views of the same code and its result.

Fig. 7. Instruction set of the Touch view.

12

J. Alemany Flos, J. Vilella Vilahur

cover the basic movement of the guide, size of the drawing, colours and general positioning. Each time the student clicks one instruction the environment executes it directly.
The second view created is the Drag view. This view still uses icons as instructions
but the student can move them freely once placed in the coding area. These instructions
accept different arguments and the icons change to match the values of the parameters.
Some examples of this behaviour can be seen in Fig. 8. Notice that the icons also include
a name to help the student read the code. To execute a program the student needs to
click the run button.
The next view is the Build view, which is similar to the Drag view as the blocks can
be displaced around the code area freely. However these blocks dont include icons, just
the name of the instructions and the arguments. The student can read the code fully, but
to create it has to choose among a specific set available. This set is larger than the one
from the drag view and contains a greater variety of instructions. This list of instructions
allows the student to be able to explore eSeeCode by him/herselves, and provides the
student with the familiarization of the names without having to memorize the commands
and the arguments.
The last view is the Code view. In this level students can type their own code.
We created eSeeCode based on JavaScript (although this base is well hidden), so after mastering in the programming in Code view the students can program freely using this well-known programming language. The platform accepts and executes any
JavaScript program allowing for a deeper learning. A side advantage to the use of
JavaScript is the fact that it is not required to be installed to function, as it will work
with any browser.
In the Code view syntax errors are possible, but we try to give short errors that the
student can correct. This can be seen in Fig. 9. The platform also has a debugger to be
used in case the students program does not execute as expected. When running a program, the editor will restyle the code to encourage students to use clean code.
In the context of the low-floor, high-ceiling proposed by Papert (Papert, 1980) and
used by Resnick (Resnick etal., 2009), eSeeCode has a lower-floor (easy-to-use) than
Logo and Scratch, and a much higher ceiling (being able to hold complex programs)
comparable to that of C++. The Touch view could be considered our low-floor while the
Code view our high-ceiling.
Although you can try to create long programs, we have designed eSeeCode to be a
problem-solving tool and have provided it with an optional easy-to-use Input/Output
interface.

Fig. 8. The icons of the Drag view adapt depending on their parameters.

eSeeCode: Creating a Computer Language from Teaching Experiences

13

Fig. 9. Syntax error in eSeeCode.

4.2. Teacher Point of View


Programming languages, platforms, and materials are only oriented towards the students use, obviating that one of the most influential parts on the learning of any process
is the teacher. Providing teacher tools, and configurable platforms is key to an excellent
use in class, given the uniqueness of each environment.
One of the main purposes of creating eSeeCode was also to be able to give the
teacher a set of tools so s/he can create high quality exercises and materials for their
courses. The interface is highly and easily configurable and it can be embedded in any
webpage, allowing the teachers to configure it for each problem if needed. The tools
already implemented are:
A tutorial creation assistant, which creates dynamic tutorials
A problem setter assistant, with which the teacher can restrict the views that can
be used, decide which instructions are allowed (and how many times each can be
used), preload code (hidden or not to the student) so that the student only needs to
complete part of it, etc.
Create step-by-step animations of the execution of programs.
Some of this tools are complemented by a Moodle module that allows the teacher to
collect students problems and to set up specific exercises.

4.3. Experiences with Students


Many experiences have been carried out with students, both in an academic context and
as an extracurricular activity.
eSeeCode has been used as a language to transition from Scratch to C++, and avoid
the difficulties that appear from going from a visual block based language to a textual
based language (Dorling etal., 2015). This experience was done with 12 years old students that had previous knowledge of Computer Science since they had taken some

14

J. Alemany Flos, J. Vilella Vilahur

Scratch courses. This allowed the teachers to teach directly using Code view, but they
allowed the students to go back to the Build view to avoid the empty page difficulty
(Resnick et al., 2009), where the student doesnt know how to start because he is used to
having a set of blocks. With the introduction of eSeeCode the teachers had to review the
basic concepts of variables, conditionals, loops, etc. The methodology that was used was
based on Polya problem-solving principles, where the student should take the following
steps (Polya, 1945):
1. Understanding the problem i.e. Can you explain the problem with different words?
Can you create your own paper and pencil examples?
2. Devising a plan. In our case this is clearly the Algorithm. Some things to consider
when devising a plan are to try to find previous, similar problems.
3. Carrying out the plan. This is the implementation of the algorithm. We propose
the baby steps methodology, where you write the code step-by-step and execute
along to avoid syntax errors, while making sure everything goes accordingly to the
plan.
4. Looking Back. Although no judge system has been created, the student should
analyse if s/he obtained the desired result, going back to previous steps if s/he did
not.
Although this experience is different than the experiment done by Lewis in a study to
compare Scratch vs Logo (Lewis, 2010), a similar survey was created and it was taken
by 59 of the students in the course. The survey consisted of 16 questions each being a
4-level Likert scale.
As it can be seen in Fig. 10 it seems that Scratch is easier to program, but in fact
the total number of students that have a positive feedback (Strongly agree and Agree)

Fig. 10. Students responses to a 4-level likert test about the use of Scratch and eSeeCode in class.

eSeeCode: Creating a Computer Language from Teaching Experiences

15

is larger in the case of eSeeCode. One of the difficulties to analyse this question is the
fact that the problems that the students had to solve in the two languages are different.
What is interesting is that students would recommend in general to use eSeeCode to
teach programming, this might have similar reasons to what Lewis describes (Lewis,
2010), as the students feel more self-secure when typing their own code, and might see
Scratch as something different than programming. This would be interesting to analyze
in a future study.
When asking questions about the difficulties when learning the language, we encounter different opinions depending on the topic. In Fig. 11 we can see this results.
Similar to what happened when asking about writing a program the opinion of the
students is less strong with eSeeCode than with Scratch, although the numbers of positive vs negative are similar. We have to take into account that the view students were
using more is the Code view, which makes it difficult to give a precise analysis of the
situation.

Fig. 11. Student responses to a 4-level likert test about the difficulties when learning with
Scratch and eSeeCode.

16

J. Alemany Flos, J. Vilella Vilahur

What might be interesting is that the students opinion about the difficulties of the
concept of repeat is statistically independent of the language (a Fisher exact test gives
us a p-value of 0.3401 which tells us that the groups are not significantly different) This
can be because the repeat concept is very easy to understand by the students.
Another experience we want to share is our own version of hour of code (Fig. 12)
where students had to make programs to draw some typical optical illusions. Placing
this activity in the context of students having an enjoyable time seemed to motivate
the students to complete the tutorials and to try to draw their own images. Some of the
activities were designed to be more difficult than the level of knowledge the students
possessed and were accompanied with a solution code. The students would read the
code and try to figure out the expected result. Although some students were not able to
complete the activity, most of them enjoyed it. Another experiment we conducted was
to give students the partial code for the program. In this activity we eliminated all the
numbers from the code. The student was required to fill the gaps, until the right image
would appear. Very few students would try numbers at random, the majority would
first try to understand what the code did, and place the right numbers directly.
Three different sets of students tried the platform with this activity: Students that had
never programmed before, students that had been introduced to Scratch and students that
already knew Logo and C++. The difficulties found were similar in each group, concluding that it adapts to the students needs.

Fig. 12. Tutorials from our Hour of Code.

eSeeCode: Creating a Computer Language from Teaching Experiences

17

4.4. Further Work


We have released eSeeCode as an open source project, and as such it is a continuing
development. We believe that further work in the platform should include:
A new and adaptable design to make it feel more modern, and more user-friendly.
Not allowing syntax errors in the Blocks and Build views.
Teacher support material to be able to be used in class by non-programmer teachers.
A formal study of the impact in the long run process and how it can be included
in the regular curriculum. We believe this study should contain reports on Scratch,
C++ and eSeeCode.

5. Conclusions
The time has come for teachers in Spain to take on the responsibility of curriculum
development. This responsibility will come first by understanding the different options
there exist, understanding the previous objectives, the ones we want to have in their
place, and taking on a global vision. Right now one language cannot satisfy all the learning process. It is also valuable for the students to know more than one language, which
would provide the option of overcoming the inherent weaknesses of each one.
eSeeCode tries to provide a new platform to overcome the main weaknesses found,
but we believe it does not need to be a replacement but rather a complement to the learning process. The trials so far show that it is a viable language to take into the classroom,
and that the students show a good overall satisfaction with it.

6. References
Ackovska, N., Erdsn NMeth, ., Stankov, E., Jovanov, M. (2015). Report of the IOI Workshop Creating an
International Informatics Curriculum for Primary and High School Education. Olympiads in Informatics,
9, 205212.
Boytchev, P. (2014). Logo Tree Project. http://www.elica.net/download/papers/LogoTreeProject.pdf
Code.org (2013). http://www.code.org
Dijkstra, E. (1999). Computing Science: achievements and challenges. ACM SIGAPP Applied Computing, 7(2),
29.
Dorling, M. (2014). Computer progression pathways. Computing at Schools.
http://www.computingatschool.org.uk
Dorling, M., White, D. (2015). Scratch: a way to Logo and Python. In: SIGCSE 15: Proceedings of the 46th
ACM Technical Symposium on Computer Science Education.
Duncan, C., Bell, T. (2015). A pilot computer science and programming course for primary schools. In: Proceeding WiPSCE 15 Proceedings of the Workshop in Primary and Secondary Computing Education. 3948.
Duke, R., Salzman, E., Burmeister, J., Poon, J., Murray, L. (2000). Teaching programming to beginners
choosing the language is just the first step. In: ACSE 00: Proceedings of the Australasian conference on
Computing education.
eSeeCode (20152016). http://www.eseecode.com
Finkel, D., Hooker C., Salvidio, S., Sullivan, M., Thomas C. (1994). Teaching C++ to high school students. In:

18

J. Alemany Flos, J. Vilella Vilahur

SIGCSE 94: Proceedings of the twenty-fifth SIGCSE symposium on Computer science education.
FMSLogo (20062016). http://fmslogo.sourceforge.net/
Gimnez, O., Petit, J., Roura, S. (2012). Jutge.org: an educational programming judge. In: Proc. of the 43rd
ACM Technical Symposium on Computer Science Education (SIGCSE-2012). 445450.
Gouws, L.A., Bradshaw, K., Wentworth, P. (2013). Computational thinking in educational activities: an evaluation of the educational game Light-bot. In: ITiCSE 13: Proceedings of the 18th ACM conference on Innovation and technology in computer science education.
Harvey, B., Mnig, J., (2010) Bringing No Ceiling to Scratch: can one language serve kids and computer
scientists? Constructionism 2010, Paris. http://www.eecs.berkeley.edu/~bh/BYOB.pdf
Jutge.org (2012). http://www.jutge.org
Lewis C. (2010). How programming environment shapes perception, learning and goals: logo vs. Scratch. In:
SIGCSE 10: Proceedings of the 41st ACM technical symposium on Computer science education. 346350.
Light-Bot (2016). http://www.lightbot.com
Papert, S. (1980). Mindstorms: Children, Computers and Powerful Ideas. Basic Books. Inc. USA.
Polya, G. (1945). How to solve it. Princeton University Press, USA.
Resnick, M., Maloney, J., Monroy-Hernndez, A., Rusk, A., Eastmond, E., Brennan, K., Millner, A., Rosenbaum, E., Silver, J., Silverman, B., Kafai, Y. (2009). Scratch: programming for all. Communications of the
ACM, 52(11).
Robins, A., Rountree, N. (2003). Learning and teaching programming: a review and discussion. Journal Computer Science Educations, 13(2), 137172.
Rubinstein, R. (1974). Using Logo in teaching. ACM SIGCUE Outlook, 9(SI).
Saez-Lopez, J.M., Roman-Gonzalez, M., Vazquez-Cano, E., (2016). Visual programming languages integrated
across the curriculum in elementary school: a two year case study using Scratch in five schools. Elsevier
computers & Education, 97, 129141.
Scratch (20132016). https://scratch.mit.edu
Simon, J. (1996). Levoluci de lensenyament del llenguatge logo a lescola de mestres Blanquerna 10 anys.
VI Seminari Logo Terrassa, Spain.
Stroustrup, B. (2007). Evolving a language in and for the real world: C++ 19912006. In: HOPL III: Proceedings of the Third ACM SIGPLAN Conference on History of Programming Languages. ACM.
Winslow, L. (1996). Programming pedagogy a psychological overview. ACM SIGCSE Bulletin, 28(3).

J. Alemany Flos holds a degree in mathematics and is currently completing a Masters Degree in Advanced Mathematics and Mathematical Engineering. He is a former high school teacher, who now designs
and helps develop programming curricula in schools as a consultant.
He has been involved with the National Informatics Olympiad for the
last eight years, also attending the International Olympiad in Informatics as a team leader and deputy leader since 2010.
J. Vilella Vilahur holds a degree in Computer Science and has been
teaching programming and robotics for the last ten years at Aula Escola
Europea where he also provides the IT support. He has been involved
in several open source projects and has been the lead programmer in
eSeeCode.

Olympiads in Informatics, 2016, Vol. 10, 1937


2016 IOI, Vilnius University
DOI: 10.15388/ioi.2016.02

19

Wavelet Trees for Competitive Programming


Robinson CASTRO1, Nico LEHMANN1, Jorge PREZ1,2,
Bernardo SUBERCASEAUX1
Department of Computer Science, Universidad de Chile
Beauchef 851, Santiago, Chile
2
Chilean Center for Semantic Web Research
email: {rocastro, nlehmann, jperez, bsuberca}@dcc.uchile.cl
1

Abstract. The wavelet tree is a data structure to succinctly represent sequences of elements over
a fixed but potentially large alphabet. It is a very versatile data structure which exhibits interesting properties even when its compression capabilities are not considered, efficiently supporting
several queries. Although the wavelet tree was proposed more than a decade ago, it has not yet
been widely used by the competitive programming community. This paper tries to fill the gap
by showing how this data structure can be used in classical competitive programming problems,
discussing some implementation details, and presenting a performance analysis focused in a
competitive programming setting.
Key words: wavelet tree, data structures, competitive programming, quantile query, range query.

1. Introduction
Let = (1 ) be a sequence of integers and consider the following query over .
Query 1. Given a pair of indices ( ) and a positive integer , compute the value of the
-th smallest element in the sequence ( +1 ).
Notice that Query 1 essentially asks for the value of the element that would occupy
the -th position when we sort the sequence ( +1 ). For example, for the sequence = (3 7 5 2 3 2 9 3 5) and the query having ( ) = (3 7) and = 4,
the answer would be 5, as if we order sequence (3 4 5 6 7) = (5 2 3 2 9) we
would obtain (2 2 3 5 9) and the fourth element in this sequence is 5. Consider now
the following update query.
Query 2. Given an index , swap the elements at positions and + 1.
That is, if = (3 7 5 2 3 2 9 3 5) and we apply Query 2 with index 5, we
would obtain the sequence 0 = (3 7 5 2 2 3 9 3 5).
Consider now a competitive programming setting in which an initial sequence of
6
10 elements with integer values in the range [ 109 109] is given as input. Assume that

20

R. Castro et al.

a sequence of 105 queries, each query of either type 1 or type 2, is also given as input.
The task is to report the answer of all the queries of type 1 considering the applications
of all the update queries, every query in the same order in which they appear in the
input. The wavelet tree (Grossi, 2015) is a data structure that can be used to trivially
solve this task within typical time and memory limits encountered in programming
competitions.
The wavelet tree was initially proposed to succinctly represent sequences while still
being able to answer several different queries over this succinct representation (Grossi
etal., 2003; Navarro, 2014; Grossi, 2015). Even when its compression capabilities are
not considered, the wavelet tree is a very versatile data structure. One of the main features is that it can handle sequences of elements over a fixed but potentially large alphabet; after an initial preprocessing, the most typical queries (as Query 1 above) can be
answered in time (log), where is the size of the underlying alphabet. The preprocessing phase usually constructs a structure of size ( log) for an input sequence
of elements, where is a factor that will depend on what additional data structures
we use over the classical wavelet tree construction when solving a specific task.
Although it was proposed more than a decade ago (Grossi etal., 2003), the wavelet tree has not yet been widely used by the competitive programming community.
We conducted a social experiment publishing a slightly modified version of Query 1
in a well known Online-Judge system. We received several submissions from experienced competitive programmers but none of them used a wavelet tree implementation
to solve the task. This paper tries to fill the gap by showing how this structure can be
used in classical (and no so classical) competitive programming tasks. As we will show,
its good performance to handle big alphabets, the simplicity of its implementation, plus
the fact that it can be smoothly composed with other typical data structures used in
competitive programming, give the wavelet tree a considerable advantage over other
structures.
Navarro (2014) presents an excellent survey of this data structure showing the most
important practical and theoretical results in the literature plus applications in a myriad
of cases, well beyond the one discussed in this paper. In contrast to Navarros survey,
our focus is less on the properties of the structure in general, and more on its practical
applications, some adaptations, and also implementation targeting specifically the issues
encountered in programming competitions. Nevertheless, we urge the reader wanting to
master wavelet trees to carefully read the work by Navarro (2014).

2. The Wavelet Tree


The wavelet tree (Grossi, 2015) is a data structure that recursively partitions a sequence
into a tree-shaped structure according to the values that contains. In this tree, every
node is associated to a subsequence of . To construct the tree we begin from the root,
which is associated to the complete sequence . Then, in every node, if there are two
or more distinct values in its corresponding sequence, the set of values is split into two
non-empty sets, and ; all the elements of the sequence whose values belong to

Wavelet Trees for Competitive Programming

21

form the left-child subsequence; all the elements whose values belong to form the
right-child subsequence. The process continues recursively until a leaf is reached; a leaf
corresponds to a subsequence in which all elements have the same value, and thus no
partition can be performed.
Fig. 1 shows a wavelet tree constructed from the sequence
= (3 3 9 1 2 1 7 6 4 8 9 4 3 7 5 9 2 7 3 5 1 3)
We split values in the first level into sets = f1 4g and = f5 9g.
Thus the left-child of is associated to 0 = (3 3 1 2 1 4 4 3 2 3 1 3) If we
continue with the process from this node, we can split the values into 0 = f1 2g and
0 = f3 4g. In this case we obtain as right child a node associated with the sequence
00 = (3 3 4 4 3 3 3). Continuing from 00, if we split the values again (into sets
f3g and f4g), we obtain the subsequence (3 3 3 3 3) as left child and (4 4) as right
child, and the process stops.
For simplicity in the exposition, given a wavelet tree we will usually talk about
nodes in to denote, interchangeably, the actual nodes that form the tree and the subsequences associated to those nodes. Given a node in , we denote by Left() its
left-child and by Right() its right-child in . The alphabet of the tree is the set of
different values that its root contains. We usually assume that the alphabet of a tree is a
set = f1 2 g. Without loss of generality, and in order to simplify the partition
process, we will assume that every node in has an associated value m() such that
Left() contains the subsequence of composed of all elements of with values
m(), and Right() the subsequence of composed of all elements with values
m(). (In Fig. 1 the value m() is depicted under every node.) We can also associate to every node in , two values l() and r(), such that corresponds to
the subsequence of the root of containing all the elements whose values are in the
range [l() r()]. Notice that a wavelet tree with alphabet f1 g has exactly
leaves. Moreover, if the construction is done splitting the alphabet into halves in every
node, the depth of the wavelet tree is (log).

Fig. 1. Wavelet tree for the sequence = (3 3 9 1 2 1 7 6 4 8 9 4 3 7 5 9 2


7 3 5 1 3). Solid lines illustrate the execution of rank3( 14). Dashed lines show the
execution of quantile6( 7 16).

22

R. Castro et al.

As we will see in Section 4, when implementing a wavelet tree the complete information of the elements stored in each subsequence of the tree is not actually necessary.
But before giving any details on how to efficiently implement the wavelet tree, we use
the abstract description above to show the most important operations over this data
structure.

Traversing the Wavelet Tree


The most important abstract operation to traverse the wavelet tree is to map an index in
a node into the corresponding indexes in its left and right children. As an example, let
be the root node of wavelet tree in Fig. 1, and 0 = Left(). Index 14 in (marked
in the figure with a solid line) is mapped to index 8 in 0 (also marked in the figure with
a solid line). That is, the portion of sequence from index 1 to index 14 that is mapped
to its left child, corresponds to the portion of sequence 0 from index 1 to 8. On the other
hand, index 14 in root sequence is mapped to index 6 in Right().
We encapsulate the operations described above into two abstract functions,
mapLeft( ) and mapRight( ), for an arbitrary non-leaf node of . In Fig.1,
if is the root, 0 = Left() and 00 = Right(0), then we have mapLeft(
14) = 8, mapRight(0 8) = 5 and mapLeft(00 5) = 3 (all indexes marked
with solid lines in the figure). Function mapLeft( ) is essentially counting how
many elements of until index are mapped to the left-child partition of . Similarly
mapRight( ) counts how many elements of until index are mapped to the rightchild partition of .
As we will describe in Section 4, these two operations can be efficiently implemented
(actually can be done in constant time). But before going into implementation details, we
show how mapLeft and mapRight can be used to answer three different queries by
traversing the wavelet tree, namely, rank, range quantile, and range counting.

2.1. Rank
The rank is an operation performed over a sequence that counts the occurrences of
value until an index of . It is usually denoted by rank( ). That is, if = (1
) then
rank( ) = jf 2 f1 g j = gj
So for example, in sequence in Fig. 1 we have that rank3( 14) = 3.
Assume that is a wavelet tree for , then rank( ) can be easily computed with
the following strategy. If m() then we know that all occurrences of in appear
in the sequence Left(), and thus rank( ) = rank(Left() mapLeft( )).
Similarly, if m() then rank( ) = rank(Right() mapRight( )). We

Wavelet Trees for Competitive Programming

23

repeat this process until we reach a leaf node; if we reach a leaf with this process, we
know that rank( ) = .
In Fig. 1 the execution of rank3( 14) is depicted with solid lines. We map index
14 down the tree using either mapLeft or mapRight depending on the m value
of every node in the path. We first map 14 to 8 (to the left), then 8 to 5 (to the right) and
finally 5 to 3 (to the left), reaching a leaf node. Thus, the answer to rank3( 14) is 3.
Rank is computed by performing (log) calls to (either) mapLeft or mapRight,
thus the time complexity is ( log) where is the time needed to compute the
map functions. Also notice that a rank operation that counts the occurrences of between indexes and can be computed by rank( ) rank( 1), and thus the
time complexity is also ( log).

2.2. Range Quantile

The range quantile operation is essentially Query 1 described in the introduction: given a
sequence = (1 ), quantile( ) is the value of the -th smallest element
in the sequence ( +1 ). For instance in Fig. 1 for the root sequence we have
that quantile6( 7 16) = 7 It was shown by Gagie etal. (2009) that wavelet trees
can efficiently solve this query.
To describe how the wavelet tree can solve quantile queries, lets begin with a simpler
version. Assume that = 1 and thus, we want to find the -th smallest element among
the first elements in . Then having a wavelet tree for , quantile( 1 ) can
be easily computed as follows. Let = mapLeft( ). Recall that mapLeft( )
counts how many elements of until index are mapped to the left-child of . Thus if
then we know for sure that the element that we are searching for is in the left subtree,
and can be computed as
quantile(Left() 1 mapLeft( ))
On the other hand, if then the element that we are searching for is in the right
subtree, but it will no longer be the -th smallest in Right() but the ( )-th smallest and thus can be computed as
quantile( )(Right() 1 mapRight( ))
This process can be repeated until a leaf node is reached, in which case the answer is
the (single) value stored in that leaf.
When answering quantile( ) the strategy above generalizes as follows. We
first compute = mapLeft( ) mapLeft( 1). Notice that is the number of
elements of from index to index (both inclusive) that are mapped to the left. Thus,
if then the element we are searching for is in the leftchild of between the indexes
mapLeft( 1) + 1 and mapLeft( ), and thus the answer is

24

R. Castro et al.

quantile(Left() mapLeft( 1) + 1 mapLeft( ))


If then the desired element is in the right and can be computed as
quantile( )(Right() mapLeft( 1) + 1 mapLeft( ))
As before, the process is repeated until a leaf node is reached, in which case the answer is the value stored in that leaf. In Fig. 1 the complete execution of quantile6(
7 16) is depicted with dashed boxes in every visited node.
As for the case of the rank operation, quantile can be computed in time ( log)
where is the time needed to compute the map functions.

2.3. Range Counting


The range counting query range[]( ) counts the number of elements with values
between and in positions from index to index . That is, if = (1 ) then
range[]( ) = jf 2 f g j gj
A sequence of size can be understood as the representation of a grid with points
such that no two points share the same row. A general set of points can be mapped to
such a grid by storing real coordinates somewhere and breaking ties somehow. For this
representation the range counting query corresponds to count the number of points in a
given subrectangle (Navarro, 2014).
To answer a range counting query over a wavelet tree we can use the following recursive strategy. Consider the interval [l() r()] of possible elements of a sequence
. If [l() r()] does not intersect [ ], then no element of the sequence is in [
] and the answer is 0. Another case occurs when [l() r()] is totally contained in
[ ]; in this case all the elements of the sequence between and are counted, so the
answer is j[ ]j = +1.
The last case (the recursive one) is when [l() r()] intersects [ ] (but is not
completely contained in [ ]); in that case the answer is the sum of the range counting
query evaluated in both children. The queries for children are called with the same [
] as in the parents call, but the indexes and are replaced by the mappings of these
indexes. That is, the answer is
range[](Left() mapLeft( ) mapLeft( )) +

range[](Right() mapRight( ) mapRight( ))

Note that if range is called on a leaf node , then l() = r() = , so the interval is either completely contained (if 2 [ ]) or completely outside (if 62 [ ]).
Both cases are already considered.

Wavelet Trees for Competitive Programming

25

It is not difficult to show that for a range counting query, we have to make at most
(log) recursive calls (Gagie et al. (2012) show detailed proof), and thus the time
complexity is, as for rank and quantile, ( log) where is the time needed to
compute the map functions.

3. Simple Update Queries


We now discuss some simple update queries over wavelet trees. The idea is to shed light
on the versatility of the structure to support less classical operations. We looked for
inspiration in typical operations found in competitive programming problems to design
update queries that preserve the global structure of the wavelet tree. We only describe
the high level idea on how these queries can be adopted by the wavelet tree, and we later
(in Section 4) discuss on how to efficiently implement them.

3.1. Swapping Contiguous Positions


Consider Query 2 in the introduction denoted by swap( ). That is, a call to swap( )
changes = (1 ) into a sequence (1 +1 ).
The operation swap( ) can be easily supported by the wavelet tree as follows.
Assume first that m(). Then we have two cases depending on the value of +1.
If +1 m(), we know that is mapped to the left subtree while +1 is mapped
to the right subtree. This means that swapping these two elements does not modify any
of the nodes of the tree that are descendants of . In order to modify , besides actually swapping the elements, we should update mapLeft( ) and mapRight( );
mapLeft( ) should be decremented by 1 and mapRight( ) should be incremented by 1 as the new element in position is now mapped to the right subtree. Notice
that these are the only two updates that need to be done to the map functions.
The other case is if +1 m(). Notice that both and +1 are mapped to
Left(), and moreover, they are mapped to contiguous positions in that sequence.
In this case, no update should be done to mapLeft( ) or mapRight( ). Thus,
besides actually swapping the elements in , we should only recursively perform the
operation swap(Left() mapLeft( )) The case in which m() is symmetrical. The complete process is repeated until a leaf node is reached, in which case
nothing should be done.
To perform the swap in the worst case we would need to traverse from top to bottom
of the wavelet tree. Moreover, notice that the map functions mapLeft and mapRight
are updated in at most one node. Thus the complexity of the process is ( log +
) where is the time needed to update mapLeft and mapRight, and is the time
needed to compute the map functions.

26

R. Castro et al.

3.2. Toggling Elements


Assume that every element in a sequence has two possible states, active or inactive,
and that an operation toggle( ) is used to change the state of element from active
to inactive, or from inactive to active depending on its current state. Given this setting,
we want to support all the queries mentioned in Section 2, but only considering active
elements. For example, assume that = (1 2 1 3 1 4) and only the non 1 elements
are active. Then a query quantile2( 1 6) would be 3.
A simple augmentation of the wavelet tree can be used to support this update. Besides
mapLeft and mapRight, we use two new mapping/counting functions activeLeft
and activeRight. For a node and an index , activeLeft( ) is the number
of active elements until index that are mapped to the left child of , and similarly
activeRight( ) is the number of active elements mapped to the right child. Besides this we can also have a count function for the leaves of the tree, activeLeaf(
), that counts the number of active elements in a leaf until position . We next show
how these new mapping functions should be updated when a toggle operation is performed. Then we describe how the queries in Section 2 should be adapted.
Upon an update operation toggle( ) we proceed as follows. If m() then
we should update the values of activeLeft( ) for all adding 1 to
activeLeft( ) if was previously inactive, or substracting 1 in case was previously active. Now, given that is mapped to the left child of , we proceed recursively with toggle(Left() mapLeft( )). If m(), we proceed symmetrically updating activeRight( ) for , and recursively calling
toggle(Right() mapRight( )). We repeat the process until a leaf is reached,
in which case activeLeaf should also be updated (similarly as for activeLeft).
The complexity of the toggle operation is then ((+)log), where is the time
needed to update activeLeft and activeRight in every level (plus activeLeaf
in the last level), and is the time needed to compute the map functions mapLeft
and mapRight.
Consider now the quantile( ) query. Recall that for this query we first computed a value representing the number of elements of from index to index that are
mapped to the left. If we proceeded searching for quantile in the left subtree,
and if we proceeded searching for quantile( ) in the right subtree (mapping
indexes and accordingly in both cases). In order to consider the active/inactive state
of each element, we only need to change how is computed; we need to consider now
how many active elements from index to index are mapped to the left, and thus is
computed as
= activeLeft( 1) activeLeft( )
Then, we proceed exactly as before: if we search for quantile in the left
subtree, otherwise, we search for quantile( ) in the right subtree. Notice that we
always assume that when executing quantile( ) the number of active elements

Wavelet Trees for Competitive Programming

27

between and in is not less than (which can be easily checked using activeLeft
and activeRight).
Queries rank and range[] are even simpler. In the case of rank we only need
to consider the active elements when we reach a leaf; in the last query rank( ) in a
leaf , we just answer activeLeaf( ). In the case of range[]( ), we almost
keep the recursive strategy as before but now when [l() r()] is totally contained
in [ ] we only have to consider the number of active elements between index and
index , which is computed as
(activeLeft( ) + activeRight( ))

(activeLeft( 1) + activeRight( 1))

In the case in which is a leaf, this value is computed as activeLeaf( )


activeLeaf( 1).
The complexity of these new queries is (( + ) log) where is the time
needed to compute the activeLeft and activeRight functions and is the time
needed to compute the map functions.

3.3. Adding and Deleting Elements from the Beginning or End of the Sequence
Consider the operations pushBack( ), popBack(), pushFront( ) and
popFront(), with their typical meaning of adding/deleting elements to/from the beginning or ending of sequence .
First notice that when adding or deleting elements we might be changing the alphabet of the tree. To cop with this, we assume that the underlying alphabet is fixed and
that the tree is constructed initially from a sequence mentioning all values in . Thus,
initially there is a leaf in the tree for every possible value. We also assume that in every
moment there is an active alphabet, which is a subset of , containing the values actually mentioned in the tree. To support this we just allow some sequences in the tree to
be empty; if there is some value of not present in the tree at some point, then the
sequence corresponding to the leaf node associated with is the empty sequence. It is
straightforward to adapt all the previous queries to this new setting.
Consider now pushBack( ) and assume that before the update we have jj =
. Then, besides adding to the end of sequence , we should update (or more precisely, create) mapLeft( +1) and mapRight( +1). If m() then we
let mapLeft( + 1) = mapLeft( ) + 1 and mapRight( + 1) =
mapRight( ), and then perform pushBack(Left() ). If m() then we let
mapLeft( + 1) = mapLeft( ) and mapRight( + 1) = mapRight(
)+1, and then perform pushBack(Right() ). Finally when we reach a leaf node,
we just add to the corresponding sequence.
The popBack() operation is similar. Assume that jj = , then besides deleting
the last element in , we should only delete that element from the corresponding sub-

28

R. Castro et al.

tree. Thus, if m() then we do popBack(Left()), and if m() we do


popBack(Right()). When we reach a leaf node we just delete any element from it.
Notice that in this case no mapLeft or mapRight needed to be updated.
The pushFront and popFront are a bit more complicated. When we do
pushFront() we should do a complete remapping: if m() then for every 2
f1 g we should do
mapLeft( + 1) = mapLeft( ) + 1
mapRight( + 1) = mapRight( )
and finally set mapLeft( 1) = 1 and mapRight( 1) = 0 and perform the call
pushFront(Left() ). If m() then we should do
mapLeft( + 1) = mapLeft( )
mapRight( + 1) = mapRight( ) + 1
and finally set mapLeft( 1) = 0 and mapRight( 1) = 1 and perform the call
pushFront(Right() ). When a leaf node is reached we just add at the beginning of the corresponding sequence. The popFront() operation is similar. Let jj =
. If 1 m() then we should update mapLeft ( ) to mapLeft ( +1)
1, and mapRight( ) to mapRight( +1) for all from 1 to 1, and then do
popFront(Left()). Symmetrically if 1 m() then we should update mapLeft(
) to mapLeft( +1), and mapRight( ) to mapRight( +1) 1 for all
from 1 to 1, and then do popFront(Right()). Upon reaching a leaf node, we just
delete the value from the front.
The complexity of all the operations above is ((+) log) where is the
time needed to update mapLeft or mapRight in every level, and is the time needed
to compute the map functions. Just notice that for the cases of the pushFront and popFront we have to update several values of mapLeft and mapRight per level.

4. Implementation
In this section we explain how to build a wavelet tree and how to construct the auxiliary
structures to support the mapping operations efficiently. Based on this construction we
also discuss how to implement queries explained in the previous section. Additionally,
we present an implementation strategy alternative to the direct pointer based one. We
implemented both approaches in C++ and the code is available in github1.

https://github.com/nilehmann/wavelet-tree

Wavelet Trees for Competitive Programming

29

4.1. Construction
A wavelet tree implementation represents an array [0 1] of integers in the interval
[0 1]. Our construction is based on a node structure and pointers between those
nodes. Every node will be identified by two elements and (which essentially
correspond to l() and r() in Section 2), and an associated sequence which is
the subsequence of formed by selecting elements in the range [ ]. As we will see,
values and and the sequence do not need to be explicitly stored and can be
computed when traversing the tree if needed.
The construction of a wavelet tree starts creating the root node associated to the
original array and the interval [0 1]. We then proceed recursively as follows. In
each node we found the middle of the interval = (+)2 (which corresponds
to the value m() described in Section 2). We create two new nodes and as leftchild and right-child of , respectively. Then, we perform a stable partition of the array
into two arrays and , such that contains all values less than or equal to
and those greater than . The construction continues recursively for the left
node with the array and the interval [], and for the right node with and
the interval [+1 ]. The base case is reached when the interval represented by the
node contains only one element, i.e., = . It is not necessary to store arrays corresponding to each node . They are only materialized at building time to construct the
auxiliary structures to support the mapping operations required to traverse the tree as
described below.
As previously discussed, the fundamental operations mapLeft and mapRight correspond to count how many symbols until position belong to the left and right node
respectively. To support these operations, when building a node we precompute for
every position how many elements in the array belong to the right node they are
greater than and store the results in an array . We could store a similar array 0
to store how many elements belong to the left node, but it is easy to note that values of
both arrays are related as follows: 0 [] = [] + 1.
To understand how is computed, it turns out useful to associate a bitvector
that marks with 0s elements less than or equal to and with 1s those greater than .
This bitvector must support the operation of counting how many bits are set to 1 until a
position , which is commonly referred as a rank operation. Our array is computed on
build time as the partial sum of by the recurrence [0] = [0] [] = [ 1]
+[], thus supporting the rank operation in constant time. The compression characteristics of the wavelet tree arise mainly because it is possible to represent these bitvectors
succinctly while maintaining constant-time rank queries (Clark, 1998; Okanohara and
Sadakane, 2007; Raman etal., 2002). However, in a competitive programming setting
memory constraints are less restrictive and our representation shows off to be sufficient.
In case the memory is an issue, a practical and succinct implementation is presented by
Gonzlez etal. (2005).

30

R. Castro et al.

4.2. Implementing Queries and Updates


We now briey discuss how every operation in Section 2 can be efficiently implemented.
mapLeft and mapRight. These two operations can be easily implemented with the array
; in a node the number of elements until position that go to the left is [] +
1. Since we are indexing from 0, position is mapped to the left to position [].
Analogously, a position is mapped to the right to position [] 1. Notice that both
mapping functions can thus be computed in constant time, which implies that rank,
quantile and range operations can be implemented in (log) time.
swap. The swap operation first map the position down the tree until we reach a node
where the update needs to be performed. At this point the (virtual) bitvector is such
that [] 6= [+1]. Swapping both bits can only change the count of 1s until position , and thus, only [] should be updated. If [] = 0 we do [] = []+1, and
if [] = 1 we do [] = [] 1. This shows that the map functions can be updated
in constant time after a swap operation, which implies that the complexity of swap is
also (log).
toggle. In this case we only need to implement activeLeft, activeRight and activeLeaf. To mark which positions are active we can use any data structure representing sequences of 0s and 1s that efficiently supports partial sums and point updates. For
example we can use a binary indexed tree (BIT) (Fenwick, 1994) which is a standard
data structure used in competitive programming that supports both operations in (log)
time. Thus with a BIT we are adding a logarithmic factor for each query and now rank,
quantile and range operations as well as toggle can be implemented in (log
log). In terms of construction, when using a BIT in every level we are only paying a
constant factor in the size of the wavelet tree.
pushBack and popBack. These operations only modify the array in some nodes.
Pushing an element at the end updates the (virtual) bitvector appending a new 0 or 1
(depending on the comparison between the new element and ), so being a partial
sum of of size only needs a [] = [ 1]+[ 1] update. Popping
an element from the end updates and doing the inverse operation, so if is of
size we only need to delete [ 1] from memory. Both operations can be done in
amortized constant time using a dynamic array, thus the complexity of all queries plus
pushBack and popBack is (log) time.
pushFront and popFront. These are similar to pushBack and popBack, but act at the
beginning of the bitvector . To prepend a bit to a bitvector we must prepend its
value to . If the value of is equal to 1 we must also increment by 1 every value in
. Because it is too slow to update every position of , we define a counter that
starts at 0 and is incremented by 1 every time a bit equal to 1 is prepended. We then just
prepend to , in which case the real count of ones until position is obtained
by []+. Popping an element is as easy as deleting the first element of from

Wavelet Trees for Competitive Programming

31

memory and decrementing by 1 if the value of [0]+ was equal to 1. If we want


to mix front and back operations, we could use a structure such as a dequeue (Knuth,
1997), which allows amortized constant time insertions at the beginning and end of an
array while maintaining constant random access time. Thus the complexity of all queries
is still (log) time.

4.3. Big Alphabets and the Wavelet Matrix


In a competitive programming setting the size of the array will depend on time restrictions, but typically it will not exceed 106. However the number of possible values that
can store could be without any problems around 109. Thus the number of values actually
appearing in is much smaller than the range of possible values. For this reason one
usually have to map the values that appear in the sequence to a range [0 1]. Commonly, this will require a fairly fast operation to translate from one alphabet to the other
with a typical implementation using, for example, a binary search tree or a sorted array
combined with binary search.
To avoid having this map operation, the wavelet tree could be constructed directly
over the range of all possible values allowing the subsequences of some nodes to be empty. A naive pointer-based construction will require () words which might be excessive
for = 109. Because many nodes will represent empty subsequences, one can save some
space explicitly tracking when some subsequences become empty in the tree.
There is an alternative implementation of the wavelet tree called wavelet matrix
(Claude etal., 2015) that was specifically proposed in the literature to account for big
alphabets. Given an alphabet its size can be extended to match the next power of two,
yielding a complete binary tree for the wavelet tree representation. For each level,
we could then concatenate the bitvectors of each node in that level and represent the
structure with a single bitvector by level. The border between each node is lost, but it
can be computed on the fly when traversing. This means extra queries yielding worse
performance. Instead, the wavelet matrix breaks the restriction that in each level siblings must be represented in contiguous positions in the bitvector. When partitioning
a node at some level the wavelet matrix sends all zeroes to the left section of level
+1 and all ones to the right. The left and the right child of some node at level do
not occupy contiguous positions in the bitvector at level +1, but the left (resp. right)
child is represented in contiguous positions in the left (resp. right) section of the level
+1. Additionally, a value is maintained at each level to mark how many elements
were mapped to the left.
With this structure the traversing operations can be directly implemented by performing rank operations on bitvectors at each level. Specifically, instead of maintaining
an array for every node, we maintain an array for each level. Array store the
cumulative number of 1s in level . Then, a position at level is mapped to the left
to position [] at level +1. The same position is mapped to the right to position
+[] 1.

32

R. Castro et al.

The wavelet matrix has the advantage of being implementable using only (log)
extra words of memory instead of the () used to store the tree structure in the pointer
based alternative while maintaining fast operations. This (log) words are insignificant even for = 109, which means that the structure could be constructed directly over
the original alphabet. On the other hand the wavelet matrix is somehow less adaptable,
because it does not support directly the pop and push updates. However, it can support
swap and toggle in a similar way as the one described for the wavelet tree.

5. Wavelet Trees in Current Competitive Programming


We conducted a social experiment uploading 3 different problems to the Sphere Online
Judge (SPOJ)2. All the problems can be solved with the techniques shown in the previous sections. We analyze the solutions to these problems submitted by SPOJ users. Our
analysis reveal two main conclusions: (1) experienced programmers do not consider the
use of wavelet trees, even in the case that its application is straightforward, and (2) for
the most complex cases when they succeed, they use fairly involved techniques producing solutions that are dangerously close to time and memory limits. We have found,
however, some incipient references of wavelet trees in the competitive programming
community3, as well as more detailed explanations in Japanese4, which obviously establish an idiomatic barrier for many programmers.
We identify the three mentioned problems as ILKQ1, ILKQ2 and ILKQ3 and they
are described as follows.
ILKQ1 considers a slightly modified version of the quantile query. The size of the initial
sequences is 105, the range of possible integer values in the sequence is [109 109], and
the number of queries is 105. The time limit is 1s.
Link: http://www.spoj.com/problems/ILKQUERY
ILKQ2 considers rank queries plus toggling the state of arbitrary elements. The size of
the initial sequence is 105, the range of possible values is [109 109], and the number of
rank plus toggle queries is 105. The time limit is 0.4s.
Link: http://www.spoj.com/problems/ILKQUERY2
ILKQ3 considers the quantile query of ILKQ1 plus swaps of arbitrary contiguous positions. The size of the initial sequences is 106, the range of possible values is [109 109],
and the number of quantile plus swap queries is 105. The time limit is 1s.
Link: http://www.spoj.com/problems/ILKQUERYIII/
Notice that ILKQ3 although involves the same query as ILKQ1, it is considerable
harder as it can mix updates (in the form of swaps) and the input sequence can be 10
times bigger than for ILKQ1. Table 1 shows an analysis of the submissions received5.
2

http://www.spoj.com/
http://codeforces.com/blog/entry/17787
4
http://d.hatena.ne.jp/sune2/20131216/1387197255
5
This data considers only until late March 2016.
3

33

Wavelet Trees for Competitive Programming


Table 1
General submission statistics
Submitted
ILKQ1
ILKQ2
ILKQ3

49
32
35

Accepted
9
6
2

Non-accepted
WA
TLE

RTE

19
15
12

3
3
6

18
8
15

5.1. Analysis of Users Submitting Solutions


We received submissions from several type of users, several of them can be considered
as experienced programmers. From them, even expert coders (rank 100 or better on
SPOJ) got lot of Wrong Answers (WA) or Time Limit Exceeded (TLE) verdicts which
shows the intrinsic difficulty of the problems. Considering the three problems, 5 out
of the 10 distinct users who got an Accepted (AC) veredict have rank of 60 or better
on SPOJ, and 8 are well-known ACM-ICPC World finalists. For problem ILKQ3 we
received only two AC. Both users solved the problem after several WA or TLE verdicts.
For ILKQ1 and ILKQ2 the best ranked submitter was the top 1 user in SPOJ who obtained AC in both problems. For ILKQ3, the best ranked submitter was among the top 5
in SPOJ and obtained only TLE veredicts.

5.2. Analysis of the Submitted Solutions


As we have told before, we received 0 submissions implementing a wavelet tree solution. We now briefly analyze the strategies of the submissions received. For the sake of
the space, we cannot deeply analyze every strategy but we provide some pointers for the
interested reader.
The most common approach for ILKQ1 was sorting queries (as the problem is offline) plus the use of a tree data structure. One of the mainly used in this case was
mergesort tree. In a mergesort tree, nodes represent sequences of contiguous elements
of the original array and contains a sorted version of those sequences. Leaves represent
one element of the array, and the tree is built recursively by merging pairs of nodes
starting from the leaves. The construction can be done in ( log) time and space.
Quantile queries can be answered by identifying the, at most (log), nodes that define
a query range, and then doing two (nested) binary searches, one for counting elements
less than or equal than a value , and the second over to find the -th minimum element. The total strategy gives (log3 ) time which can be optimized up to (log2 )
using fractional cascading. This was enough given the time constraints.

34

R. Castro et al.

For ILKQ2 and ILKQ3 sorting of queries or any offline approach is not directly
useful as queries are mixed with updates. For ILKQ2 we received some submissions
implementing a square root decomposition strategy, and run extremely close to the time
limit. The most successful strategy in both problems was the use of ideas coming from
persistent data structures, in particular persistent segment trees6. As in any persistent
structure, the main idea is to efficiently store different states of it. Exploiting the fact that
consecutive states do not differ in more than (log ) nodes, it is possible to keep different segment trees in ( log ) space. Persistent segment trees can be used to answer
quantile queries but need some more work to adapt them for updates like swaps as in
ILKQ3. The two correct solutions that we received for ILKQ3 make use of this structure.
Its relevant to notice that given the input size and the updates, implementing a persistent
segment tree for this problem can use a considerable amount of memory. In particular,
one of the AC submissions used 500MB and the other 980MB. Our wavelet tree solution
uses only 4MB of memory.

6. Performance Tests
Existing experimental analyses about wavelet trees focus mostly on compression characteristics (Claude et al., 2015). Moreover, they do not consider the time required to
build the structure because from the compression point of view the preprocessing time is
not the most relevant parameter. Thus, we conducted a series of experiments focusing on
a competitive-programming setting where the building time is important and restrictions
on the input are driven by typical tight time constraints. The idea is to shed some light on
how far the input size can be pushed. We expect these results to be useful for competitors
as well as for problem setters.
We performed experimental tests for our wavelet tree and wavelet matrix implementations comparing construction time and the performance of rank, quantile and range
counting queries. We consider only alphabets of size less than the size of the sequence.
To analyze the impact of the alphabet size, we performed tests over sequences of different profiles. A profile is characterized by the ratio between the size of the alphabet
and the size of the sequence. For example, a sequence of size 103 and profile 05 has an
alphabet of size 500.
Measurements. To measure construction time we generated random sequences of increasing size for different profiles. For each size and profile we generated 1,000 sequences and we report the average time. For queries rank, quantile and range counting,
we generated 100,000 queries uniformly distributed and averaged their execution time.
The machine used is an Intel Core i7-2600K running at 3.40GHz with 8GB of RAM
memory. The operating system is Arch-Linux running kernel 4.4.4. All our code are
single-threaded and implemented in C++. The compiler used is gcc version 5.3.0, with
optimization flag -O2 as customary in many programming contests.
6

bit.ly/persistent-segment-tree

35

Wavelet Trees for Competitive Programming

Results. No much variance was found in the performance between different profiles, but
as may be expected sequences of profile 1 i.e., permutations reported higher time in
construction and queries. Thus, we focus on the analysis of permutations to test performance on the most stressing setting. For the range of input tested we did not observe big
differences between the wavelet tree and the wavelet matrix, both for construction and
query time. Though there are little differences, they can be attributed to tiny implementation decision and not to the implementation strategy itself.
Regarding the size of the input (Fig. 2), construction time stays within the order
of 250 milliseconds for sequences of size less than or equal to 106, but scales up to
2 seconds for sequences of size 107, which can be prohibitive for typical time constraints. For the case of queries rank, quantile and range counting we report in Fig. 3
the number of queries that can be performed in 1 second for different sizes of the input
sequence. For rank and quantile, around 106 queries can be performed in 1 second for
an input of size 106. In contrast for range counting, only 105 queries can be performed
in the same setting (Fig. 3).
It would be interesting as future work to perform a deep comparison between the
wavelet tree and competing structures for similar purposes such as mergesort trees
and persistent segment trees, testing time and memory usage. From our simple analysis in the previous section one can infer that wavelet trees at least scales better in
terms of memory usage, but more experimentation should be done to draw stronger
conclusions.

 





 











 

 

Fig. 2. Construction time in milliseconds.






























  





   



 

 
















Fig. 3. Number of queries that can be performed in one second.


 



36

R. Castro et al.

7. Concluding Remarks
Problems involving advanced data structures are appearing increasingly often in worldwide programming competitions. In this scenario, competitive programmers often prefer
versatile structures that can be used for a wide range of problems without making a lot of
changes. Structures such as binary indexed trees or (persistent) segment trees, to name
a few, conform part of the lower bound for competitors, and must be in the toolbox of
any programmer. The wavelet tree has proven to be a really versatile structure but, as
we have evidenced, not widely used at the moment. However, we have noted that some
programmers have already perceived the virtues of the wavelet tree. We believe that the
wavelet tree, being quite easy to implement, and having such amount of applications, is
probably becoming a structure that every competitive programmer should learn. With
this paper we try to fill the gap and make wavelet trees widely available for the competitive programming community.

Acknowledgments
J. Prez is supported by the Millennium Nucleus Center for Semantic Web Research,
Grant NC120004, and Fondecyt grant 1140790.

References
Clark, D. (1998). Compact Pat Trees. PhD thesis, University of Waterloo.
Claude, F., Navarro, G., Ordez, A. (2015). The wavelet matrix: an efficient wavelet tree for large alphabets.
Inf. Syst., 47, 1532.
Fenwick, P. M. (1994). A new data structure for cumulative frequency tables. Software: Practice and Experience, 24(3), 327336.
Gagie, T., Navarro, G., and Puglisi, S.J. (2012). New algorithms on wavelet trees and applications to information retrieval. Theor. Comput. Sci., 426, 2541.
Gagie, T., Puglisi, S.J., Turpin, A. (2009). Range quantile queries: another virtue of wavelet trees. In: SPIRE.
16.
Gonzlez, R., Grabowski, S., Mkinen, V., Navarro, G. (2005). Practical implementation of rank and select
queries. In: WEA. 2738.
Grossi, R. (2015). Wavelet trees. In: Encyclopedia of Algorithms. Springer.
Grossi, R., Gupta, A., Vitter, J.S. (2003). High-order entropy-compressed text indexes. In: SODA03. 841850.
Knuth, D. (1997). The Art of Computer Programming, Volume 1: Fundamental Algorithms. Third Edition.
Addison-Wesley. 238243.
Navarro, G. (2014). Wavelet trees for all. J. Discrete Algorithms, 25, 220.
Okanohara, D., Sadakane, K. (2007). Practical entropy-compressed rank/select dictionary. In: ALENEX. 60
70.
Raman, R., Raman, V., Rao, S. (2002). Succinct indexable dictionaries with applications to encoding k-ary trees
and multisets. In: SODA. 233242.

Wavelet Trees for Competitive Programming

37

R. Castro is a computer engineering student at Department of Computer Science, Universidad de Chile, bronze medalist of IOI2013 in
Brisbane, and problem setter for OCI (Chilean Olympiad in Informatics).

N. Lehmann is masters student in computer science at Department


of Computer Science, Universidad de Chile. His research interests are
semantics, design and implementation of programming languages and
type systems. He is the Scientific Committee Director of OCI (Chilean
Olympiad in Informatics). Deputy Leader at IOI 2014 and 2015. Chilean Judge of ACM ICPC 2014 and 2015.
J. Prez is Associate Professor at the Department of Computer Science, Universidad de Chile, and an Associate Researcher of the Chilean Center for Semantic Web Research. His research interests are database theory, data exchange and integration, graph databases, and the
application of database technologies to the Semantic Web and the Web
of Data. He is one of the directors of OCI (Chilean Olympiad in Informatics), and the Chilean team leader at IOI since 2013.
B. Subercaseaux is an undergraduate student of computer science at
Department of Computer Science, Universidad de Chile, and problem
setter for OCI (Chilean Olympiad in Informatics).

Olympiads in Informatics, 2016, Vol. 10, 3960


2016 IOI, Vilnius University
DOI: 10.15388/ioi.2016.03

39

Learning Programming through


Games and Contests:
Overview, Characterisation and Discussion
Sbastien COMBFIS1,2, Gytautas BERESNEVIIUS3
Valentina DAGIEN3
Electronics and IT Unit, cole Centrale des Arts et Mtiers (ECAM)
Promenade de lAlma 50, 1200 Woluw-Saint-Lambert, Belgium
2
Computer Science and IT in Education ASBL, Belgium
3
Vilnius University Institute of Mathematics and Informatics
4 Akademijos Street, Vilnius LT-08663, Lithuania
E-mails: s.combefis@ecam.be; gytber@gmail.com; valentina.dagiene@mii.vu.lt
1

Abstract. Learning of programming and, more generally, of computer science concepts is now
reaching the public at large. It is not only reserved for people who studied informatics (computer
science) or programming anymore. Teaching programming to schoolchildren presents many
challenges: the big diversity in ability and aptitude levels; the big amount of different tools; the
time-consuming nature of programming; and of course the difficulty to motivate schoolchildren
to keep them busy with hard work. There are various platforms that offer to learn coding and
programming, in particular game-based platforms, which are more and more popular. These
latter exploits of the gamification process focused on increase in motivation and engagement
of the learners. This paper reviews the main kinds of online platforms to learn programming
and more general computer science concepts, and illustrates the review with concrete platforms
examples.
Keywords: game-based learning, gamification, learning programming, online programming platform, programming contest.

1. Introduction
Informatics (computer science or computing) as a science discipline, and in particular
programming as an important part of that, is gaining a lot of popularity these years in
education. As core subjects in a computer science (CS) major, programming subjects
play an important role in a successful CS education. One of the greatest challenges
faced by most students is the understanding of programming basics, especially for novices or for those who are in their first year of studies. Students develop algorithmic

40

S. Combfis, G. Beresneviius, V. Dagien

thinking or computational thinking at secondary and even at primary school. Using


simple programming languages such as Scratch became accessible to young children
(Maloney etal., 2004).
Games have been used for educational purposes for decades. The popularity of games
has led to the idea of using them in the learning of programming, taking advantage of
the engaging features of games. In a very broad sense, two different approaches are used
when using games or game-like elements in educational contexts: 1) gamification and
2) serious games. The term gamification is commonly defined as the use of game design
elements in non-game contexts (Deterding etal., 2011). Serious games are associated
with a standalone game or platform, as well as indicated as a computer game (Djaout
etal., 2011). In this paper, we are going to use the general term to refer to game-based
learning with main focus on teaching programming.
Game-based learning is concerned with using games not for entertainment, but for
educational purposes. Those who work within the field of gamification focus on identifying the context and conditions that support the integration of digital games within
informal and formal learning environments. Educational scientists have pointed up
several features of games that allow them to be used as learning tools. For example,
games are engaging (Dickey, 2005) and motivating (Prensky, 2003). They also provide
a lot of experiences (Arena and Schwartz, 2013) and an excellent feedback on performances (Shute, 2011). Finally, games support very well the learner centred education
(Gee, 2005).
A contest can be seen as a part of game-based learning. Contests make the teaching
of programming more attractive for students. Furthermore, programming with computer
is one of the appropriate and effective ways to develop problem solving skills and computational thinking. During contests, students have the possibility to compare their abilities and learn from others. There have been many contests in programming throughout
all over the world; most of them focus on algorithmic problem solving.
Many teaching environments already contain game-like elements such as points, instant feedback, and goals. However, there are engaging aspects in games that could be
used in educational settings more widely. In well-designed games, even a failure can be
a reward and triggers positive emotions (Ravaja etal., 2005). There is no off-the-shelf
formula for designing successful games, nor is there one perfect learning environment.
However, by deepening our understanding of the effects of games and game-like environments in educational settings, we can design and support more effective learning
activities, and ultimately improve the learning of computer science.
The move from classical learning platforms to online contests and games can be
explained as a way to ensure the best motivation as possible for their users. The online
platforms can provide tools such as rankings, duels, discussion rooms, etc. to motivate
their users to participate regularly. Finally, research on gamification in all its forms has
proven that educational games improve the engagement of learners if the game is designed properly (Barata etal., 2013; Nah etal., 2014). Online platforms where students
can learn programming are being developed all over the world, ranging from simple direct learning platforms to platforms of games that indirectly teach programming (Combfis and Wautelet, 2014).

Learning Programming through Games and Contests: Overview, ...

41

This paper reviews literature of the last decade on programming education for school
students (high, secondary and primary levels) using games and online platforms that
support games and contests which goal is to teach programming. The literature review
of programming games and an overview of programming learning platforms were structured to accomplish the following three research objectives:
1. To overview the last decade literature on programming education using games.
2. To identify the important online platforms for learning programming through
games and contests.
3. To identify suitable tools for programming novices.
The goal of the paper is twofold: from one side, to provide an overview of the work
that has been done in this area, and from the other side, to discuss the important tools
(online platforms and contests) and to improve programming education. After this introductory part, Section2 makes a short presentation of the understanding of gamification
and overviews the literature on teaching programming using games. Section 3 presents three kinds of online platforms, which allow students to learn programming. Then
Section 4 tours several existing contest platforms. Finally, the last section concludes
the paper with some thoughts about what could be the future evolution of these online
platforms and contests and makes some suggestions for teaching programming by educational games or by other ways.

2. Short Overview of Literature


The application of game design elements of non-game scenarios is known as gamification. Some authors stated that gamification uses elements of experiences (Deterding
etal., 2011). It must also impart some rules or structure to the experience to influence
participants action. Gamification adds game design elements as well as promoting the
psychological benefits and motivational ability of games but in different contexts.
Programming games are an important part of educational games. A programming
game is a computer game where the player has little or no direct influence on the
course of the game. Instead, a computer program or script is written in some domainspecific programming language in order to control the actions of the characters or
other entities.
There are several definitions of serious games. For example, Alvarez and Michaud
(2008) state that a serious game must include a genuine entertainment element combined
seemingly with a practical dimension. Some researchers argue that all games have a
serious purpose, such as gambling. That is why a majority of simulators would be considered as serious games (Sawyer and Rejeski, 2002).
Game design may be defined as the action of making sense of things related to a
game (Mora etal., 2015, p. 3). Another description is the act of deciding what a game
should be (Schell, 2008, p.xxxviii). Game design is related to enjoyment, while gamification points towards a business objective. Similarity of game design and gamification
design is that both rely on the principles of game design theory.

42

S. Combfis, G. Beresneviius, V. Dagien

2.1. Related Works


The ACM and IEEE computer society state that computer science is becoming one of
the core disciplines of a 21st century university education, that is, something that any
educated individual must possess some level some level of proficiency and understanding of proficiency and understanding (ACM/IEEE, 2013, p. 48). However, there
are a lot of students who are becoming less interested in computer science. Colleges
and universities routinely report that almost half of those students who initially choose
computer science study soon decide to abandon it. There are high dropout rates as well
as high failure rates of high school students in programming courses. Decades of effort
have been put into decreasing these rates.
There were several approaches to motivate students to learn programming. Programming fundamentals may be hard skills to learn for students, especially for novices. In
order to help students, there are several attempts to teach programming by using educational or serious games.
Programming courses are an important part in computer science subjects. Objectoriented programming is difficult for students, especially first year students. The embedding of gamification in programming courses could maximize student participation and
have a positive impact on learning (Azmi etal., 2015). The gamified social activity is designed to promote interaction among students and they may assist and give feedback to
each other online. Online collaborative learning and the participation of students should
be emphasised as well. Moreover, aesthetics is also a very important part in a game,
because it makes it fun, which contributes to engage students in the learning process.
The embedding of gamification in programming courses were analysed and showed that
gamification in online collaborative learning can enhance participation among first year
programming students. The participation is an important part in each computer science
study due to motivation and lower dropout rates.
Vihavainen et al. (2014) present another approach in a literature overview. Their
paper reports about 60 pre-interventions and post-interventions and analyses their influence on students pass rates in programming courses. Statistically, pass rates after these
interventions increased nearly by one third compared to traditional teaching. A more
detailed discussion is presented about seven courses on gamification intervention after
which pass rates increased by 10.8% on average.
Tillmannetal. (2013) deals with an alternative platform called Pex4Fun. On this
platform, grading of traditional MOOCs (Massive Open Online Course) assignments
has been changed to an automated grading assignment system based on the symbolic
execution, designed for students and teachers. This platform is a game-based learning
and teaching environment, where teachers may create interactive games for students.
Students can learn programming by playing programming games in Pex4Fun as well
as having programming duels between each other.
There are several important components of game elements. As Hunicke etal. (2004)
have discovered the game mechanics represents data and algorithms. Game dynamics
is the lifecycle of the mechanics that act to engage a players input and others output.
Also, game aesthetics plays important role in the emotional part of the player in order to
keep them engaged with the game.

Learning Programming through Games and Contests: Overview, ...

43

Several researchers worked on more detailed classification of games. For example,


Azmietal. (2015) classified game elements into three categories 1) game mechanics
(badges, leaderboard, points, levels...), 2)dynamics (personal dynamics desire for reward, personal promotion; social dynamics altruism; achievements, peer collaboration), and 3) aesthetics (challenges). The gamified design needs to embed collaborative
elements for collaboration among the students. Aesthetics is recommended element in
educational games, because it makes the game fun and engages with the learning
process. Online educational game should have the online support as well as collaborative learning.
While there is still scepticism that something called a game could be anything more
than a leisure activity, serious organizations are getting serious results with serious games.
Serious games may be defined as an application with three main components: experience, entertainment, and multimedia (Laamartiet al., 2014). Especially entertainment
dimension in serious games has the potential to enhance the users experience through
multimodal interaction. Additionally, digital serious games contain different media.
The paper of Laamartietal. (2014) overviews studies on serious games in different
application areas including education, well-being, advertisement, cultural heritage, interpersonal communication, and health care. Also, many platforms were analysed and discussed, what the necessary components of the game to be successful are. A survey on digital serious games in general is conducted and a taxonomy of serious games is created.
Several components of serious games were distinguished and categories of criteria
were suggested (Laamartietal.,2014). These criteria may be useful for any programming games as well. So, providing guidance to players within the game is important.
This will provide them with the necessary knowledge and prevents them from feeling
lost or disturbed. Another thing is avoiding negative consequences in the game, because otherwise it may result in the players low performance. Music element makes
players play the game longer, because of more motivation and engagement will be as an
effect of this. Multiplayer collaborative exercise games are more motivating and engaging than single-player appropriate games. Collaborative environment increases players
motivation. It is significantly important to offer challenges in the game for children, but
the challenges must be at the right level (neither too high, nor too low). It is the key in
keeping the players interest in the game. Educational games need to take into consideration sound instructional models to be successful.
More detailed recommendations are provided for educational games designed for
using in a classroom. School teachers are concerned about the curriculum and they also
have limited time resources. It is recommended that educational games would be based
on the curriculum due to the acceptance of many teachers and integration in the class.
Additional recommendations for necessary components of the games to be successfully used can be as follows (Laamartietal.,2014):
a. User-centred software engineering: an important element is the perspective that
the designers contribute to the development teams and the experience that the
player will obtain.
b. Multimodal games: multiple modalities should be incorporated (e. g. visual, auditory and haptic combination).

44

S. Combfis, G. Beresneviius, V. Dagien

c. Social well-being: stimulating a feeling of virtual presence or connectedness of


social well-being in real life.
d. Adaptive gaming: a serious game should adapt or personalize a particular players capabilities, needs, and interests.
e. Standardization of evaluation: heuristic evaluation standards must turn into a
reality. That is useful for acquiring higher credibility.
f. Sensory-based simulations: serious games can be created based on real world
sensory data so that real world scene would be accurately reconstructed.
Many commercial games demonstrate the properties of sound instructional design,
even in games not intended for educational purposes (Becker, 2008). The author has
recommended the following success factors for educational games: 1) Gain attention; 2)
Inform learners of the objective; 3) Stimulate recall of prior learning; 4) Present stimulus material; 5) Provide learning guidance; 6) Elicit performance; 7)Provide feedback;
8) Assess performance; 9) Enhance retention and transfer. These factors were based on
well-known learning and instructional theories.
One suggestion for recreating games is to modify an existing non-educational games
into programming games (Muratetetal., 2010). The authors have used existing online
non-educational games ideas to develop their own serious games. For example, there
is a game Kernel Panic, having following features: it has no resource management
except for time and space; all units are free to create; it has a small technology improvement tree with less than ten units; and it uses low-end vectorial graphics, which match
the universe. In this game a player gives orders to the units to carry out operations (i.e.
moving, building, and so forth). So the authors (Muratetetal., 2010) changed the game
design that the player has to write a program code in order to make the actions of his
units and play. The authors modified some games into serious games and students, e.g.
players may play these games using different programming languages: C, C++, Java,
OCaml, Ada and an interpreted language called Compalgo.
Another paper (Cuba-Ricardo etal., 2015) describes some characteristics and regularities from the behaviour of three students as they solved a programming problem as
well as reveals the methodology stages using several methods, techniques and tools.
The paper is limited by the time of contestants, who have between 60 and 90 minutes in
contest of final states.
Successful computer programmers must have several cognitive skills as listed by
Surakka and Malmi (2004). Contestants opinions must be taken into account in order
to have full view of their outputs. So, it was decided to use computer programs that take
screenshots in short periods of time. The methodology of characterizing the cognitive
process of solving programming problems was organized into five stages:
a. Preparation of the process.
b. Recording the process of exercise application.
c. Analysis, processing and assessing of the partial reports (observation of pictures).
d. An interview session.
e. Final assessment.

Learning Programming through Games and Contests: Overview, ...

45

The implementation of the methodology revealed that programmers took notes in


the worksheets and the reasoning followed when determining the solution algorithm.
So, monitoring programming students actions is a useful method to discover not only
final outputs, but intermediate results of the learning process as well. We think it may
be one of the essential issues to be taken into consideration of teaching programming
curriculum, especially for novices. Monitoring process could be done by computer automated programs and be used as a general method (e.g. it may be a live survey after your
programming contest).
Researchers focus on investigating successful components of educational games that
could help to reduce dropout rates of students in computer science. The embedding of
gamification in programming courses can be one of solutions for that: it can help to
maximize student participation and learning, motivate and reduce dropout rates, especially for novices in programming (Azmietal., 2015). Some platforms, e.g. Prog&Play
may help even to recruit students in computer science (Muratetetal., 2010). Intervention of educational games in programming courses raises pass rates by 10.8% on average
(Vihavainen etal., 2014).
A feedback is an important and necessary part in education and educational games
(Azmietal., 2015; Cuba-Ricardo etal., 2015; Tillmann etal., 2013). Good feedback can
be implemented by providing guidance to players within the game so that they do not feel
lost (Becker, 2008) or by avoiding negative consequences in the game. Another solution is to make the game a multiplayer one to motivate players to play the game longer.
The most successful factors are multiple modalities of games, players collaboration,
adaptive or personalized game components based on real world sensory data (Laamartietal., 2014). Non-educational games may be gamified and used for teaching programming courses as well (Muratet etal., 2010). Contests and duels in programming games
are engaging and may be used to raise programming skills (Cuba-Ricardo etal., 2015).
All the authors that are mentioned in this section have stated that educational games
motivate students to learn. In general, you may use all these researched factors when
your own create programming games.

2.2. Taxonomy of Educational Games


As there is growth of researches in the educational games field and it is a necessity to
improve the value of teaching or learning programming by educational game, we were
working on the taxonomy of educational games. We adapted the framework of serious
games taxonomy based on the paper (Laamarti etal., 2014). Firstly, we will provide a
short introduction to the mentioned taxonomy. After that we will discuss our novelties
and provide a classification of several online programming games.
Five categories for serious games classification are presented by (Laamarti et al.,
2014, p. 6):
1. Application Area refers to different application domains (education, well-being,
training, advertisement, interpersonal communication, health care, others).

46

S. Combfis, G. Beresneviius, V. Dagien

2. Activity. It depends on the activity of a player to play a game (physical exertion,


psychological, mental).
3. Modality. Here it is the channel by which information is sent from the computer to
the human(s) participating in the game (visual, auditory, haptic, smell, others).
4. Interaction Style. The interaction style defines whether the interaction of the
player with the game is done using keyboard, mouse, or Joystick or using some
intelligent interfaces, e. g. a brain interface, eye gaze, movement tracking, and tangible interfaces. The research showed that choosing the right interface may have an
impact on the success of the game.
5. Environment. This criterion defines the environment of the digital game (social
presence, mixed reality, virtual environment, 2D/3D, local awareness, mobility and
online).
We investigated the classification and found limitations, especially when applying
for programming education by using games. For educational online programming games
an extension and adaptation of the proposed taxonomy are needed (Fig. 1).
Application area. So, an application area of programming games is only one education to program educational games. A field of the programming educational games
activity usually is a mental process. We will have in mind that application area of educational programming games is education, activity field is mental and we will omit these
fields as a result.
Modality. Usual modality fields of educational programming games are visual and
auditory, but sometimes it may be haptic.

Fig.1. The classification of the educational programming games (adapted and extended schema of Laamarti etal., 2014).

Learning Programming through Games and Contests: Overview, ...

47

Interaction style. Interaction style in our taxonomy is keyboard/mouse, tangible


interface, brain interface and joystick, because educational games usually may be classified just in these fields. But we remain open to discussion about this question.
Environment. As environments of programming games may be any of Laamarti
etal. suggested environments, we include all of the areas: social presence, mixed reality,
virtual environment, 2D/3D, local awareness, mobility and online.
Learning approach. We include this new field to classification of educational games.
This is because analysed research papers on educational games pays a lot of attention
to successful methods of teaching or learning. We propose that the learning approach of
educational games may be classified into single player, multi player, mixed players (part
of the game may be single-player game and part of the game may be multi-player game),
peers (it is important to pay attention to communication between peers), collaboration
(some educational games may teach team work), support of teachers (students easier
learn while they are playing with a help of teachers/lecturers).

3. Online Platforms for Learning Programming


Several different kinds of online platforms to learn programming do exist. The most
classical platforms are able to automatically execute code and provide feedback. They
provide lessons that the learner can follow and propose interactive coding exercises with
immediate correction. Combfis and le Clment de Saint-Marcq (2012) proposes a short
review of such platforms. Swacha and Baszuro (2013) propose such a classic platform,
but they included game elements in it. For example, the courses in their platform are
characterised by the set of completed areas, the number of earned points and the attained
level. Moreover, it is possible to challenge other students and take part in contests.
In addition to the specific platforms to learn coding and programming, online courses
are also proposed in the form of MOOCs (Combfis etal., 2014). Another example is
Khan Academy, which provides interactive lessons and videos with coding exercises
(Morrison and DiSalvo, 2014). Both these kinds of platforms propose a full course with
videos for the theory and then practical coding exercises with more or less detailed direct
automated feedback. They are designed with the learning process as the main objective.
This section presents three main categories of online game platforms with different
goals: learn to code, learn algorithmic thinking and learn to create games. Proposed examples are discussed according to the background presented in the previous section, for
the particular case of learning computer science skills. The last subsection, then discusses
how and what game elements can be added to an online platform in order to gamify it.

3.1. Learn to Code


The first category of game platforms contains those whose goal is to make their users
learning and training to code. Coding games require the learner to understand and to be

48

S. Combfis, G. Beresneviius, V. Dagien

able to write code to solve challenges. Different coding activities are possible, the main
ones being:
Bugfix: the user is given a program that contains a bug to be fixed.
Recovery: the user is given a program where some parts are missing that have to
be filled.
Code writing: the user has to write an instruction, a function or a program from
scratch.
Agent: the user has to write a program that represents the behaviour of an intelligent agent.
To help the learner to identify the bug, additional information is provided in the statement of the challenge. For example, a precise specification of the program or the results
of the execution of test sets can be provided. Once the learner has written/fixed the
code, he submits it and then gets a feedback. As summarised by Combfis and Wautelet
(2014), feedback is very important for the learning process. Those feedbacks can take
several forms such as:
A simple succeeded/failed status.
The result of the execution of test sets.
A textual feedback providing hints regarding the failure.
Codecademy is an example of an online game platform to learn how to code (Fig.2).
The left part of the window provides the explanations of the new concept to learn. Instructions about the exercise are then provided at the very bottom of this left pane. The
learner can directly code in the editor located in the right part and then submit his/her
code for correction. If the code is wrong, a simple feedback trying to explain why is
provided and if it is right the learner earns a badge, increases his/her progress and can
go to the next lesson.

Fig. 2. Codecademy proposes a course composed of lessons in which you have to write code
and for which you will earn badges and make progress whenever you succeed.

Learning Programming through Games and Contests: Overview, ...

49

3.2. Learn Algorithmic Thinking


Coding is not the only field of computer science that can be taught through online platforms. As described by Combfisetal. (2013), it is also possible to grow algorithmic
thinking through interactive problems, in particular to learn programming concepts.
For example, LightBot (https://lightbot.com) is used to learn the notion of programming and in particular recursion through a simple game where the user has to solve
puzzles. Each puzzle requires the learner to write a program composed of visual blocks
to drive a robot to a goal. Fig. 3 shows the main window of the game where the robot
and its environment are shown on the left and the program representing the behaviour
of the robot is shown on the right. LightBot is not a platform to learn how to code, but to
teach programming concepts. In the more advanced levels, the notions of function and
therefore recursion are introduced.
Another example is Initial Conditions (https://reheated.org/games/initial), shown in Fig. 4, where the player has to find a solution to a search problem. In
this game, the player faces to a grid with rivers and has to place a certain number of
villages so that a river passes through them and so that no two cities are adjacent (horizontally or vertically).

Fig. 3. In LightBot, the player has to find a correct sequence of actions to perform so that the
robot reaches the blue cell and lighten it.

Fig. 4. In Initial Conditions, the player has to place cities on a map so that a river is passing
through them and so that two cities cannot be adjacent. This particular map has one river and
the player has to place five cities.

50

S. Combfis, G. Beresneviius, V. Dagien

This problem is a typical an artificial intelligence (AI) search problem that could for
example be solved using any exploration algorithms, or with a constraint programming
solver, for example. Again, it is not explicitly explained to the learner who just sees a
game with puzzles to solve. Playing the game will challenge the learner and should develop algorithmic thinking in learners mind.
Again, if the purpose is educational, the provided feedback is very important. For
LightBot, the feedback is visual since the learners can visualise the execution of their
programs and therefore visually debug them if the robot failed to reach the goal. For
Initial Conditions, the only feedback is a success/failed status indicating which cities are
violating the constraints or which river is missing villages.

3.3. Learn to Create Games


Finally, another kind of online programming learning platforms offers the possibility for
the users to create their own games. On these platforms, the learner has to program a
game, typically with a visual programming language. For example, Scratch (https://
scratch.mit.edu) uses a visual block programming language to program the behaviour of sprites.
The main window of the application where the game is shown on the left part and the
code is shown on the right (Fig. 5). The behaviour of each sprite can be programmed and
they can also communicate together.
Another similar platform is Flowlab (http://flowlab.io) where the game is represented by flowchart diagrams (Fig. 6). As in Scratch, the game is built with sprites
whose individual behaviours can be programmed.

Fig. 5. The main window of the Scratch program is split into two parts: the left part shows
the sprites of the game and the right part shows the programs representing the behaviour of
the different sprites.

Learning Programming through Games and Contests: Overview, ...

51

Fig. 6. In Flowlab, the user programs the game using flowchart diagrams representing the
behaviours of the different sprites it included in the game.

This last category requires the learner to be able to program, but not necessarily to
write code. The focus is put on the creativity and on the skills needed to design and architecture an application.

3.4. Gamification of an Online Learning Platform


Proposing an online platform is useful to make the material available to every learner.
But only relying on the online aspect is not enough to motivate them to learn. As detailed
in the second section, gamification can help to foster learners to make progress, increasing their engagement and motivation. Several kinds of elements can be introduced to
build online game platforms:
Points and rankings amongst players.
Levels, grades, badges that are related to the progression.
Live fights/contests between players or against bots.
One other important element that can be taken into account is the contextualisation
of the statements of the challenges and exercises. There are indeed two main strategies that can be used to gamify an online platform to learn programming. Either game
elements can be added to an already existing platform (points, rankings, badges) or
the platform can be rethought and redesigned so that to transform it completely into

52

S. Combfis, G. Beresneviius, V. Dagien

a game. As highlighted by Morrison and DiSalvo (2014) who relate the gamification
of the Khan Academy, one critical motivational element to have is to place the user
at the centre by adding elements of pure play, to make the gaming more playful.
Examples of such approaches include CodeSpells (Esper etal., 2013) and Gidget (Lee
etal., 2013).
Ibez et al. (2014) made an experiment to explore the impact of gamification
techniques on the engagement and learning about the C programming language. The
authors conclude that the gamification they performed has a positive impact on the
students engagement. Most students continued to work even after having earned the
maximum amount of points. ODonovan etal. (2013) present a case study where they
used gamification in a university-level course about game development. In their paper, the authors provide insights about gamification mechanics and explain how the
design of their game has been created and which game elements have been used. Their
research allows them to conclude that the gamification they performed in a university
setting was effective, increasing the engagement and understanding of the students.
Again, it is a situation where the platform has been thought as a game from the starting point.

4. Online Programming Contests


This section presents several online game platforms, so that to cover the different tendencies that exist today and the characteristics presented in the previous section. The
focus has been put on platforms that available for free (at least a standard version).

4.1. Leek Wars


Leek Wars (http://leekwars.com/) is a game where the player has to program the
behaviour of a leek. The goal of the leek is to defeat another leek during a fight that takes
place in a garden. Depending on the level of the player, his/her leek can be equipped with
more weapons, health-recovering objects, etc.
The leeks are programmed in JavaScript and an API provides functions to manipulate the leak and to get information about the environment. This API is very well documented, which also trains learners to manipulate such documentation.
The platform offers the possibility to develop several AIs and to choose which one
to use at any time. The player can experiment his/her AIs against bots, before jumping
into the garden to fight with other real players. To motivate the player, a level system has
been put in place. For each fight that is won, the player gains experience points, which
allow him/her to level up. A higher level grants access to more objects such as weapons,
magic spells, etc. It also improves the ranking of the player.
The game also proposes a cooperative mode where teams composed of leeks belonging to different players can fight against other teams. Such cooperative mode is another
technique used in games to foster people to play regularly.

Learning Programming through Games and Contests: Overview, ...

53

Fig. 7. Two leeks are fighting in a war, playing alternatively one after the other. The garden is
divided into cells between which the leeks are moving and has some impassable obstacles.

4.2. CodinGame
CodinGame (https://www.codingame.com) proposes coding challenges to solve.
Basically, the user is asked to code agents that have to interact in a given environment
in order to achieve a given goal. In the example shown in Fig. 8, the user has to code the
spaceship so that to destroy all the targets on the ground. The spaceship is moving from

Fig. 8. In this mission, the agent is a spaceship that must destroy targets on the ground. These
targets have different heights so that the spaceship must destroy them in the right order if it
does not want to enter in collision with any of them.

54

S. Combfis, G. Beresneviius, V. Dagien

left to right then back from right to left while descending when it reaches the rightmost
part of the world. The difficulty is that targets have different heights and the spaceship
must avoid entering in a collision with any of them.
Several test sets are provided and to succeed, the code of the player must pass them
all (some being public and others being hidden). The execution of the code also results
in an animation, which makes it possible for the learner to directly visualise the behaviour he/she wrote. This latter point helps to increase the motivation and engagement of
the learner, better than a simple textual test execution report. Finally, the platform offers the possibility to code the agents with a lot of different programming languages.
Several challenges/missions are available for the user to tackle. They are organised
into categories such as tutoring, advanced, etc. The users can follow their progress and
that motivates to solve more challenges.

4.3. Code Hunt


CodeHunt (https://www.codehunt.com) is developed by Microsoft Research and
propose coding challenges driven by tests. The goal of the game is to guess what the
code must do, and then fix it until it passes all the tests. Fig. 9 shows the main view of
Code Hunt where the code is on the left and the results of test execution are shown on
the right. Pressing the Capture code button triggers the execution of a bunch of tests,
shown on the right.
When the user solves a yet unsolved puzzle, he/she gains points so that to increase
his/her position in the ranking. Moreover, some puzzles are initially locked and will only
unlock when the user has solved enough puzzles. This possibility to unlock puzzles is an
incentive for the user that motivates him/her to progress.

Fig. 9. The main window of Code Hunt is split into two parts: the left part shows the code
being run and the right part shows the result of the execution of the public tests.

Learning Programming through Games and Contests: Overview, ...

55

4.4. Code Fights


Code Fights (https://codefights.com) is a platform where users can participate
in fights against bots or other real players. A fight typically consists in three puzzles to
solve. One fight typically consists of three challenges. As shown in Fig. 10, the main
window shows the statement of the challenge on the right and the code with the results
of public tests on the right.
The learner can train him/herself by fighting bots or can defy any other player for a
fight. There are two kinds of bots: simple ones and others developed by companies. If
you manage to beat a company bot, you got a chance to be contacted by the company
to possibly get a job. Another interesting feature proposed by the platform is tourney,
where you compete with several other real players on the same challenges. To win the
tourney you have to solve all the challenges as fast as possible.

4.5. Discussion and Comparison


The presented online platforms have some common points and differences. First of all,
they are all in the learn algorithmic thinking category described in the previous section. Then, the level of gamification of the different platforms is quite different. A platform that has been completely designed with games in mind is one that completely
agrees with the definition of gamification, as detailed in the previous section. The first
one, namely Leek Wars, is a full online game with cooperative aspects where the ultimate goal is for the player to level up to become the best leek, the one with the most

Fig. 10. The main window of Code Fights is split into two parts: the left part shows the statement of the challenge and the right part shows the code and the result of the execution of the
public tests.

56

S. Combfis, G. Beresneviius, V. Dagien

intelligent behaviours. The three other platforms do contain some game element, but
they are not designed completely as full games. Table 1 summarises the game elements
that appear in the presented platforms.
All the platforms presented in this paper can also be classified according to the
adapted and extended schema we proposed to classify educational programming games.
Table2 shows how that classification can be done. All the games presented in this paper
Table 1
The four presented online game platforms to learn different skills of coding training and
contains different game elements
Platform

Trained skills

Game elements

Leek Wars

Coding agents AI
Inventing algorithms

CodinGame

Understanding specifications
Coding objects behaviours

Code Hunt

Points and rankings


Challenges against bots and other players
Cooperative mode
Points, trophies, badges, rankings
Levels and achievements
Matches against other players
Points and rankings
Levels with challenges to unlock

Fixing bugs
Code recovery
Understanding tests sets results
Understanding specifications
Points, levels and rankings
Coding algorithms
Matches against other players or bots
Fixing bugs
Code recovery

Code Fights

Table2
Classification of the platforms

Game

Modality

Interaction style

Environment

Learning approach

Codecademy

Visual

Keyboard/Mouse

Single Player

Code Fights

Visual

Keyboard/Mouse

Code Hunt

Visual

Keyboard/Mouse

CodinGame

Visual

Keyboard/Mouse

Initial Conditions Visual

Keyboard/Mouse

Leek Wars

Visual

Keyboard/Mouse

LightBot

Visual

Keyboard/Mouse

Social Presence
2D
Online
Social Presence
2D
Online
2D
Online
Social Presence
2D
Online
2D
Online
2D
Online
2D
Online

Mixed Player
Single Player
Single Player
Single Player
Mixed Player
Collaboration
Single Player

Learning Programming through Games and Contests: Overview, ...

57

are visual ones with which the players interact with the keyboard and mouse. Concerning the environment, all the games are of course online ones. They are also all 2D games
and some of them will require social presence, in particular for those where duels are
available. Finally, the learning approaches of those selected games can be either single
or mixed player. One of the game, namely Leek Wars, supports collaboration through the
creation of teams of Leeks.

5. Recommendations and Conclusions


To conclude this paper, the learning of programming is accessible not only to higher
education students, but it is accessible to others as well. A lot of online platforms have
been developed and made accessible on the Internet. In addition to the classical learning platform or MOOCs, a broad range of game-based online platforms have emerged.
The main advantage of such platforms is that they foster their users to learn and keep
progressing, making programming fun.
Tasks and challenges proposed by these games-based platforms could inspire tasks
proposed in the IOI for two main reasons. First, contestants to the IOI are probably using
those platforms so that they may be expecting similar tasks at the IOI. Second, the motivational aspect of those tasks could be transferred to the IOI contest, also the making it
more motivational and interesting for its contestants.
We referred and analysed papers on gamification: contests; online platforms; online,
educational, programming and serious games. These are our main findings from these
papers for educational or serious programming games to be successful, motivating to
learn programming and so on:
a. Feedback and assessment is very important in any educational games. Assessment
may be automated or not, but it raises efforts of students. Feedback provides information about the learning process.
b. Games must have aesthetics game must be fun to engage and improve intrinsic
motivation to learn computer science or programming.
c. Collaborative educational games raise the participation of students.
d. Participation is necessary for motivation to learn as well as for reducing high
dropout rates of programming students.
e. Multiplayer collaborative games are more motivating and engaging than singleplayer appropriate games.
f. Guidance in educational game helps players not to feel confused while they are
playing.
g. Aesthetics make any educational game fun. It involves players into the game.
h. Avoid negative consequences, because otherwise players may perform low.
i. Involve music in game design and the players will probably play the game longer.
j. The level of challenge neither ought to be not too low nor too high (it keeps the
interest of players).
k. Games with multiple modalities, adaptive or personalized, based on real world
sensory data may be more successful.

58

S. Combfis, G. Beresneviius, V. Dagien

l. Contests and duels in programming games may be used to improve the programming skills.
We proposed taxonomy of the programming educational games and classified several
online programming games / platforms. All of these games are visual; interactive with
keyboard/mouse, 2D and online. The majority of them are designed for a single player,
however, two of them are designed for mixed players (game may be played as single
player or multiplayer) and one of them involves collaboration aspect. As we already
mentioned, multiplayer and collaborating games are more motivating. 3D-games sometimes have more advantages than 2D, but it depends more on a combination of many
other mentioned or not mentioned factors.
Our findings may be useful in creating educational programming games on your
own, or recreating non-educational games and gamifying them to teach programming, it
is especially useful for novices in programming. This research does not propose to use
all these factors, because some of them may be successful in one kind of games, but may
not be successful for other type of games. However, it is recommended to use at least
some of these factors due to our research analyse.

References
ACM/IEEE Computer Society (2013). Computer Science Curricula 2013.Curriculum Guidelines for Undergraduate Degree Programs in Computer Science. ACM Press, New York, N. Y. USA. Available on the
internet: https://www.acm.org/education/CS2013-final-report.pdf
Alvarez, J., Michaud, L. (2008). Serious games: advergaming, edugaming, training, and more, IDATE, BP 4167,
34092 Montpellier Cedex 5. France, 36, 1112.
Arena, D.A., Schwartz, D.L. (2013). Experience and explanation: using videogames to prepare students for
formal instruction in statistics. Journal of Science Education and Technology, 111.
Azmi, S., Iahad,N.A., Ahmad, N. (2015). Gamification in online collaborative learning for programming courses: a literature review. ARPN Journal of Engineering and Applied Sciences, 10(23), 13.
Barata, G., Gama, S., Jorge, J., Goncalves, D. (2013). Engaging engineering students with gamification. In:
Proceedings of the 5th International Conference on Games and Virtual Worlds for Serious Applications
(VS-GAMES 2013). 18.
Becker, K. (2008). Video game pedagogy: good games = good pedagogy. In: T.C. Miller (Ed.), Dames: Purpose
and Potential in Education. Springer, NewYork, NY, 73125.
Bishop, J., Horspool, R., Xie, T., Tillmann, N., de Halleux, J. (2015). Code hunt: experience with coding contests at scale. In: Proceedings of the 37th International Conference on Software Engineering (ICSE 2015).
398407.
Combfis, S., Bibal, A., Van Roy, P. (2014). Recasting a traditional course into a MOOC by means of a SPOC.
In: Proceedings of the European MOOCs Stakeholders Summit 2014 (EMOOCs 2014). 205208.
Combfis, S., Saint-Marcq, D. (2012). Teaching programming and algorithm design with Pythia, a web-based
learning platform. Olympiads in Informatics, 6, 3143.
Combfis, S., Van den Schrieck, V., Nootens, A. (2013). Growing algorithmic thinking through interactive
problems to encourage learning programming. Olympiads in Informatics, 7, 313.
Combfis, S., Wautelet, J. (2014). Programming trainings and informatics teaching through online contest.
Olympiads in Informatics, 8, 2134.
Cuba-Ricardo, G., Serrano-Rodrguez, M.T.,Leyva-Figueredo, P.A., Medoza-Tauler, L.L. (2015). Methodology
for characterization of cognitive activities when solving programming problems of an algorithmic nature.
Olympiads in Informatics, 9, 2730.
Deterding, S., Dixon, D., Khaled, R., Nacke, L. (2011). From game design elements to gamefulness: Defining
gamification. MindTrek, 2.
Dickey, M.D. (2005). Engaging by design: how engagement strategies in popular computer and video games
can inform instructional design. Educational Technology Research and Development, 53(2), 6783.

Learning Programming through Games and Contests: Overview, ...

59

ODonovan, S., Gain, J., Marais, P. (2013). A case study in the gamification of a university-level games development course. In: Proceedings of the South African Institute for Computer Scientists and Information
Technologists Conference (SAICSIT 2013). 242251.
Esper, S., Foster, S., Griswold, W. (2013). CodeSpells: embodying the metaphor of wizardry for programming.
In: Proceedings of the 18th ACM Conference on Innovation and Technology in Computer Science Education
(ITiCSE 2013). 249254.
Gee, J.P. (2003). What video games have to teach us about learning and literacy. Computers in Entertainment
(CIE), 1(1), 20.
Gee, J.P. (2005). Good video games and good learning. Phi Kappa Phi Forum, 85(2), 3337.
Hunicke, R., Leblanc, M. Zubek, R. (2004). MDA: A formal approach to game design and game research. In
Proc. AAAI workshop on Challenges in Game. AAAI Press, 15.
Ibez, M.-B., Di-Serio, ., Delgado-Kloos, C. (2014). Gamification for engaging computer science students in
learning activities: a case study. IEEE Transactions on Learning Technologies, 7(3), 291301.
Laamarti, F., Eid, M., El Saddik, A. (2014). An overview of serious games. International Journal of Computer
Games Technology. Article ID 358152, vol. 2014, 115. Available on the internet:
http://dx.doi.org/10.1155/2014/358152
Lee, M., Ko, A., Kwan, I. (2013). In-game assessments increase novice programmers engagement and level
completion speed. In: Proceedings of the 9th Annual International ACM Conference on International Computing Education Research (ICER 2013). 153160.
Maloney, J., Burd, L., Kafai, Y., Rusk, N., Silverman, B., Resnick, M. (2004). Scratch: a sneak review. In: Proceedings of the 5th International Conference on Informatics in Schools: Situation, Evolution and Perspectives (ISSEP 2011). 155164.
Mora, A., Riera, D., Gonzlez, C, Arnedo-Moreno, J. (2015). A literature review of gamification design frameworks. In: 7th International Conference on Games and Virtual Worlds for Serious Applications (VS-Games),
At Skvde. IEEE, 18.
Morrison, B., DiSalvo, B. (2014). Khan Academy Gamifies Computer Science. In: Proceedings of the 45th
Technical Symposium on Computer Science Education (SIGCSE 2014). 3944.
Muratet, M., Torguet, P., Viallet, F., Jessel, J.-P. (2010). Experimental feedback on Prog&Play: a serious game
for programming practice. In: L. Kjelldahl and G. Baronosk (Eds.), EUROGRAPHICS. 18.
Nah, F., Zeng, Q., Telaprolu, V., Ayyappa, A., Eschenbrenner, B. (2014). Gamification of education: a review of
literature. In: Proceedings of the First International Conference on HCI in Business (HCIB 2014). 401409.
Prensky, M. (2003). Digital game-based learning. Computers in Entertainment (CIE), 1(1), 21.
Ravaja, N., Saari, T., Laarni, J., Kallinen, K., Salminen, M., Holopainen, J., Jrvinen, A. (2005). The psychophysiology of video gaming: phasic emotional responses to game events. In: Proceedings of DiGRA
2005 Conference: Changing Views Worlds in Play. Vancouver, Canada, 3, 113.
Sawyer, B., Rejeski, D. (2002). Serious Games: Improving Public Policy through Game-Based Learning and
Simulation. Woodrow Wilson International Center for Scholars, Washington, DC, USA.
Schell, J. (2008). The art of Game Design: A Book of Lenses. Carnegie Mellon University and Schell Games,
Pittsburgh, Pennsylvania, USA.
Shute, V.J. (2011). Stealth assessment in computer-based games to support learning. In: S. Tobias and D. Fletcher (Eds.).Computer Games and Instruction. Information Age: Charlotte N. C., 503524.
Squire, K. (2008). Open-ended video games: a model for developing learning for the interactive age. In: K.
Salen (Ed.), The John D. and Catherine T. MacArthur Foundation Series on Digital Media and Learning.
MA: The MIT Press, Cambridge, 167198.
Surakka, S., Malmi, L. (2004). Cognitive skills of experienced software developer: Delphi study. In: Korhonen
A., Malmi, L. (Eds), Kolin KolistelutKoli Calling 2004. In: Proceedings of the Fourth Finnish/Baltic Sea
Conference on Computer Science Education. Finland, Koli, 3746.
Swacha, J., Baszuro, P. (2013). Gamification-based e-learning platform for computer programming education.
In: Proceedings of the X World Conference on Computers in Education (WCCE 2015). 122130.
Tillmann, N., de Halleux, J., Xie, T., Bishop, J. (2014). Code hunt: gamifying teaching and learning of computer science at scale. In: Proceedings of the First ACM Conference on Learning @ Scale Conference (L@S
2014). 221222.
Tillmann, N., De Halleux, J., Xie, T., SumitGulwani, Bishop, J. (2013). Teaching and learning programming and
software engineering via interactive gaming. In: 35th International Conference on Software Engineering
(ICSE). IEEE, San Francisco, CA, 11171126.
Vihavainen, A., Airaksinen, J., Watson, Ch. (2014). A systematic review of approaches for teaching introductory
programming and their influence on success. In: ICER 14Proceedings of the tenth annual conference on
International computing education research. ACM, New York, NY, 1926.

60

S. Combfis, G. Beresneviius, V. Dagien

S. Combfis obtained his PhD in engineering in November 2013 from


the Universit catholique de Louvain in Belgium. He is currently working as a lecturer at the cole Centrale des Arts et Mtiers (ECAM),
where he is mainly teaching informatics. He also got an advanced
master in pedagogy in higher education in June 2014. He founded the
Belgian Olympiad in Informatics (be-OI) with Damien Leroy in 2010.
In 2012, he introduced the Bebras contest in Belgium and at the same
time he founded the CSITEd non-profit organisation that aims at promoting computer science in secondary schools.
G. Beresneviius is a doctoral student of informatics engineering at
the Institute of Mathematics and Informatics of Vilnius University. He
obtained his master degree in Mathematics and Informatics Didactics
with Cum Laude diploma in Vilnius University. His research focuses
on teaching informatics, especially programming through games, as
well as the theories of serious games and gamification. He participated
in several international conferences and presented his research. He
likes programming websites using HTML, CSS, JavaScript, PHP and
MySQL languages.
V. Dagien is head of the Informatics Methodology Department at the
Institute of Mathematics and Informatics of Vilnius University. Her
current research is in Computer Science Education, focusing on cognitive aspects of algorithmic thinking as well as computational thinking. She has published over 200 scientific papers and methodological
works, has written more than 50 textbooks in the field of informatics and information technology for primary and secondary education.
She works with various expert groups all over the world. In 2004, she
established the Bebras Challenge on Informatics and Computational
Thinking, which is successfully implemented in more than 50 countries. She has participated in several EU-funded R&D projects, as well
as in a number of national research studies connected with technology
and education.

Olympiads in Informatics, 2016, Vol. 10, 6172


2016 IOI, Vilnius University
DOI: 10.15388/ioi.2016.04

61

The Place of the Dynamic Programming Concept


in the Progression of Contestants Thinking
gnes Erdsn Nmeth1,2, Lszl ZSAK3
Batthyny High School, Nagykanizsa, Hungary
Doctoral School, Faculty of Informatics, Etvs Lornd University, Budapest, Hungary
3
Faculty of Informatics, Etvs Lornd University, Budapest, Hungary
e-mail: erdosne@blg.hu, zsako@caesar.elte.hu
1
2

Abstract. The special problem-solving strategies have been receiving a lot of attention lately,
whether it is teaching computational thinking for all or computer science for competitors. A didactically interesting question is how problem solving can be developed in childrens minds, what
steps and tasks lead through from understanding the idea to its professional usage. In this paper
we present and explain how and in what forms the given problem-solving strategies, especially
the dynamic programming concept, appear in childrens informatics studies: from CS unplugged
activities through Bebras tasks and national CS competitions to efficient coding at the IOI.
Keywords: dynamic programming concept, teaching informatics in primary and secondary
schools, preparing for contests.

1. Overview
There are a lot of problem-solving strategies which every contestant has to be familiar
with. In this paper, we want to focus on one of the most important ones, specifically dynamic programming, because [Until] you understand dynamic programming, it seems
like magic (Skiena, 2008).
The dynamic programming name came from Bellmann in the 1950s (Dreyfus,
2002). He wanted to find a name for the multistage decision making process, in which
the general case is very hard to solve thus one must use the divide & conquer concept. It
leads back to special cases, when the solution is expressed more easily not in terms of
the unknown function, but in terms of an action or decision.
If we want to speak about dynamic programming, we also have to examine other corresponding concepts, like recursion, memoization and divide & conquer.
The concept of recursion consists of a recursive function and a recursive implementation; it is a top-down approach. Usually the runtime of the algorithm is exponential
and this technique usually fails already in a small sample size. The memoization is a
top-down approach as well, it is more effective than recursion. The core idea is the

62

. Erdsn Nmeth, L. Zsak

same: recursive function and recursive implementation, but storing the calculated results, thus without calling the recursive step again when the actual state previously
appeared.
When we are experienced enough to implement a recursive approach correctly,
there is a special technique for dramatically reducing the runtimes of certain algorithms from exponential to polynomial or from factorial to exponential, at the expense
of higher memory usage. This is done by solving sub-problems and storing the results
using a dynamic programming concept. The concept is about a recursive function, but
the implementation is to build the values from bottom up without calling the recursive
step repeatedly.
The simplest type of dynamic programming is when an array is filled namely a
table cell-by-cell in a predetermined order, implementing the recursive function from
bottom up. We will call it a basic DP.
Some people use the term dynamic programming only for those recursive problems,
which involve optimization, but the technique of completing a table to solve any other
type of problem is almost the same when it comes to implementing the solution. We will
call it classic DP.
The dynamic programming as problem-solving strategy is the implementation of the
following five steps (Horvth, 2004):
1. Analysing the (optimal) solutions structure.
2. Dividing it into subproblems and components:
a. Dependence of components must be acyclic.
b. Every subproblem (optimal) solution should be a (recursive) expression of
components (optimal) solution.
3. Expressing each subproblems (optimal) solution as a (recursive) function of components (optimal) solution.
These three steps are the planning of recursive algorithm. DP comes from the next
two steps:
4. Calculating subproblems (optimal) solutions from bottom up (completing a table).
5. Calculating an (optimal) solution from the previously calculated and stored information.
If you are familiar with the basic DP techniques then you could continue with some
advanced techniques (Steinhardt, 2008).
The first advanced type is to keep track of all possible transition states. In this case
DP means filling out a table row-by-row, with the values depending on the row number
and values in the previous row.
Second advanced type is the dynamic greedy type.
The third advanced type is a steady state convergence, only for more experienced
students. In this case the recursive equation must be repeatedly applied, then values will
converge exponentially to the correct values.
All of the DP types have a place in different stages and in different ages of contestants studies.

The Place of the Dynamic Programming Concept in the Progression ...

63

2. Place of Dynamic Programming in Algorithms Textbooks


There are a lot of textbooks about algorithms. They discuss all algorithms sequentially
and directly as they are written for university students. The structure of these books and
the place of dynamic programming in them is different.
In the textbook of Skiena (2008) the DP takes place after data structures, sorting and
selecting algorithms, graphs, combinatorics, backtrack and parallel programming. In the
chapter of dynamic programming, he compares algorithms using cache vs. computation at first. After this, he discusses the problem of string matching, longest increasing subsequence and partition problem. The limitation of DP is presented via travelling
salespersons problem and there are some words about correctness and efficiency of DP.
Just after the DP concept comes the recursion and memoization, the concepts of the topdown structures.
In the textbook of Kleinberg and Tardos (2006) there are basic algorithms, graphs and
greedy algorithms first. To process sets which can be divided into independent parts they
recommend divide & conquer concept. Just after this method, they speak about DP: the
recursion, the memoization and iteration over sub-problems are the parts of this chapter.
In the textbook of Dasgupta et al. (2006), dynamic programming is presented after arithmetics, primes, cryptography, hashing, divide & conquer, graphs and greedy algorithms via
examples: travelling salesmans problem, longest increasing subsequence and knapsack.
In the textbook of Sedgewick and Wayne (2011) there is no chapter dedicated to DP,
but the concept appears in some points of the book.
In the textbook of Gupta (2009) DP comes after introduction to algorithms, divide &
conquer method and greedy method.
Bebis (2007) has lot of chapters about sorting and searching methods, DP comes
after that.
There are not two textbooks, in which the place of DP is the same in the sequence
of algorithms. Sometimes it comes before graphs (Gupta, 2009), often it comes after
graphs. Occasionally it is before recursion (Kleinberg and Tardos, 2006), but in the most
common order its place is after recursion and memoization. Sometimes it is placed before the greedy algorithms, sometimes after. Textbooks do not usually stress the differences between dynamic programming and greedy approach, nor warn they about the
danger of accidentally using one instead of the other.
These textbooks are almost useless for primary and secondary school pupils because
of their advanced mathematics and informatics contents. Some parts of them may be
useful in upper secondary, just for contestants preparing for IOI.

3. New Way for Contestants Learning DP in Upper Secondary School


Last year there was a paper in IOIJournal about the critical analysis of textbooks and
new way of teaching DP (Foriek, 2015) for upper secondary school students preparing
for national olympiads and IOI. He started with the Fibonacci sequence something is

64

. Erdsn Nmeth, L. Zsak

well-known by children from math studies implementing it with a recursive function


and making this function more efficient with memoization. He compares iterative and
dynamic solution, then introduces DP bottom-up. He demonstrates that the exponential
solution longest common subsequence problem with a top-down approach turns polynomial (o(n2)) with a bottom-up approach. It is a very good structure if students want to
prepare for olympiads all at once.
There is a book about competitive programming, which was written for contestants
preparing for ACM ICPC and IOI (Halim and Halim, 2014). It is not a real textbook, it
teaches the effective type detection of tasks and the correct, error-free coding, not the
concepts behind the algorithms. According to it contestants main goal should be to
honing [their] ability to recognize a problem as DP, finding the recursive formula for
such a problem, coding the problem, and doing all of this quickly.
After data structures and problem-solving strategies like searching iterative & recursive divide & conquer concept and greedy algorithms comes dynamic programming through an example: UVA 11450 wedding shopping. The chapter begins with the
repetition of recursion, backtrack, optimization and counting problems. It shows, that
this tasks solution: greedy method failed with wrong answer (WA), divide & conquer
method failed with WA (because of non-independent parts), complete search failed
with time limit exceeded (TLE). The dynamic programming method with top-down
(memoization) and with bottom-up approach is working. After this very detailed analysis he gives six more example with analysis and many task recommendation to become
familiar with this method.
We think these methods work effectively for students in upper-secondary-school-age
(grade 1113) preparing purposefully for national and international olympiads.

4. Teaching Dynamic Programming in Primary and Secondary School


If the students know structured programming concept (Floyd), they are familiar with
the top-down concept too, because of stepwise refinement; and they are familiar with
the concept of bottom-up, because concrete objects and functions. So the pupils knows
top-down and bottom-up paradigms as soon as they begin to implement a computer
program.
We think teaching dynamic programming ideally begins in upper primary school in
mathematics and informatics lessons. Implementation of DP on computers is possible
when children are familiar with the basic data structures (integer, boolean, array), basic
algorithms (sequence, iteration, selection, searching, procedures and functions) and the
concept of recursion.

4.1. CSUnlugged
There is not any activity yet that covers dynamic programming in the CSUnplugged repository, but there is an intention to make a good one from the change-making problem.

The Place of the Dynamic Programming Concept in the Progression ...

65

4.2. BEBRAS
In the Bebras competitions there are tasks about DP every year. There are other tasks,
in which the recursion is the best solution. There are many in which the greedy gives
wrong answer and the dynamic programming concept must be used for the right solution.
On Bebras competitions the DP problems appear in a wide range of age groups and
difficulties also. It proves that the concept of DP comes much earlier than at the end of
secondary school and it is understandable for everybody, not only for contestants: it is
part of computational thinking skills.
The easiest task of DP is from 2013 for grade 58: the Pairs without Crossing (Kreuzungsfreie Prchen). The brute force algorithm is working, but takes long time to try
every possible connection pairs, the dynamic concept make it easy. In 2011 the problem
Earn coins (Mnzen verdienen) is a special case of the classic knapsack problem. This
one was one of the hard problems for the grade 56, middle for grade 78 and easy for
grade 910. In 2014 another classic DP problem appeared, the Expensive Bridges (Teure
Brcken) which one was hard problem for the grade 78, middle for grade 910 and easy
for grade 1113.
There are more problems connected to DP for secondary-school-age students: the
Jumping Puddles (Ptzenspringen), the game ROOK, in 2010 the task Pinecone (Tannenzapfen), in 2014 the Best translation (Beste bersetzung) and in 2015 the Fireworks2
(das Feuerwerk2).

4.3. Tasks for Contestants of Upper-Primary-School-Age


In the grade 56 we could start with LOGO programming. It provides a strong foundation in the basic programming structures, like sequence, iteration and selection.
Through the drawings, it also visualizes the concept of recursion well. They can imagine and implement binary tree (Fig. 1), the Sierpinski-triangle (Fig. 2), the Koch-curve
(Fig. 3).

Fig. 1. Binary tree.

Fig. 2. Sierpinski-triangle.

Fig. 3. Koch-curve.

66

. Erdsn Nmeth, L. Zsak

In Hungary and many other countries, they meet table filling and the thought of
recursion in mathematics. They calculate total number of possible paths in a grid of
characters, from the top-left corner to the right-bottom corner to spell a given word
(Fig. 4). They calculate total number of possible paths, even if there are empty squares
in the grid (Fig. 5).

Fig. 4. Spelling a given word.

Fig. 5. Spelling a given word with a pit.

Pupils of grade 78 meet simple recursive sequences and functions, like the Fibonacci sequence. In mathematics lessons, they meet combinatorial problems (permutation, variation and combination without repetition) without naming them. They come
across problems, like longest/shortest path in a directed/undirected graphs and coloring
problems on very small graphs, coin changing problem for small numbers, shaking
hands/sitting in a row/around a table, they calculate extreme values in Diophantine
problems. These problems are solved with table filling or with recursive expressions.

The formulas, like n! or are not formulated.


They can solve problems like these:

How many different, 10cm high towers can build from 2 cm high blue, 2 cm high
yellow and 1 cm high red building blocks?

Fig. 6. a1 = 1, a2 = 3, a3 = 5, a4 = 11 Counting with drawing systematically.

If they draw it systematically (seeing the blocks from bottom), they can guess the
recursive expression an = an 1 + 2*an 2 and they check it empirically. The solutions are: 1, 3, 5, 11, 21, 43, 85, 171, 341, 683.
How many different covering exist on a 2*8 table with 1*2 size dominos?

Fig. 7. a1 = 1, a 2 = 2, a 3 = 3, a 4 = 5 Counting with drawing systematically.

The Place of the Dynamic Programming Concept in the Progression ...

67

If they draw it systematically (seeing the blocks from the right), they can guess the
recursive expressionan=an1+an2 and they check it empirically. The solutions are:1,
2, 3, 5, 8, 13, 21, 34. The solution can be built for any given N with a table filling.
In primary schools the children meet problems with large numbers also, like 1000
points, 2016 numbered cards, 10000 people. In such cases, the obvious idea is instead
of the original task to examine a simplest problem. What happens if the number of
points is 2, 3, 4, ..., the number of cards is 5, 6, 7,, the number of people is 2, 3, 4,?
If any regularity is noticed, they try to verify it empirically and apply it on the original
problem with large numbers. On primary-school-level, formulating and using the hypotheses is enough to solve such problems.
On the other hand, these problems can be implemented on the computer, as a recursive expression or with table filling for larger numbers. The next classical problems are
the first appearance of dynamic programming approach for them:
Robot A robot starts from the top left corner (1,1) of a MxN grid. At each step
the robot can make one of the two choices: move one cell to the right or move one
cell down. How many possible paths are there for the robot to reach the rightbottom corner of the grid?
The robot problem can occur in many variations at grade 7 and 8:
The question is the same, but there are cells in a grid, on which the robot cant
step on (traps).
The question is the same, but there are cells in a grid, on which the robot have
to step on (mandatory fields).
In every cell there are given number of pearls and the question is, what is the
maximum number of pearls the robot can collect on its way.
Mix of traps and pearls.
Staircase You are standing in front of a staircase, which has N stairs. Your goal
is to reach the top. If you are standing on the ith step, you can hop to (i+1)st or
(i+2)nd or (i+3)rd step. Given N, calculate the count of total possible paths for you
to reach Nth stair!
Coin Change You want to make change for given N cents and you have infinite
supply of each of S1, S2, .. , Sm valued coins. How many ways can you make the
change?
Subset sum Detect, if any of the subset from a given set of N non-negative integers sums up to a given value S!
Dice Throw Problem Given N dice, each with m faces, numbered from 1 to m.
Find the number of ways to get sum X! (X is the summation of values shown by
the dices.)
Flooring How many different coverings exist on a 1*N floor with 1*1 and 1*2
parquet pieces? How many different covering exist on 2*N floor with 1*2 parquet
pieces?

68

. Erdsn Nmeth, L. Zsak

Towers How many different, N meters high towers can be built from 2 meters
high blue, 2 meters high yellow and 1 meter high red blocks?
The previous dynamic programming problems should be solved at the primaryschool-level as the analogous math problems: children formulate and use the hypothetical recursive expressions and implement them with table filling, without extensive
argumentation. Mostly they cannot calculate directly the answer, but they can give a
recursive formula and the direction of filling the table, and this way they can solve the
problem. They can solve basic DP problems, without optimization.
On informatics contest the children use basic data structures (integer, boolean, one
and two-dimensional array of integers, simple strings) and basic algorithms can be applied for various problems in various wording. Choosing, selecting, counting, searching, summarizing, selecting maximum/minimum, sorting, separating into two groups,
prime testing are these basic algorithms. Stages of solving tasks are understanding the
problem, choosing the right data structure, selecting right algorithm, implementing and
testing it. In addition to the conservative tasks there are ad-hoc problems where children
can apply basic algorithms creatively. The basic DP problems appear in the regional and
national rounds of competitions.

4.4. Tasks in Lower-Secondary-School-Age


In Hungary and many other countries the children continue to learn combinatorial problems in grades 910 in mathematics lessons, they group and formalise these problems.
During these years, they also meet the idea of mathematical induction, so they can prove
the previously discovered recursive formulae. They learn about sequences and sometimes they give the explicit formulae for recursive expressions. They know the formula

of n! and , they also learn Pascal-triangle. But they do not necessarily know the
relationship between the binomial coeffitients and the Pascal-triangle.
They can discover and solve more complex recursive expressions, sometimes these
functions call each other, like:
How many different covering exist on a 2*N table with 1*2 and 1*1 size dominos?

Fig. 8. a1 = 2, a2 = 7, a3 = 22, a4 = 71 Counting with drawing systematically.

Drawing it systematically is not enough to formulate the recursive expression.


One must analyze possible cases. The result comes with two expressions in simultaneous recursion: dn = an1 + fn1, fn = an1 + dn1, an = 2*an1 + an2 + fn1 + dn1.
After simplification: an = 3*an1 + an2 an3.

The Place of the Dynamic Programming Concept in the Progression ...

69

In this age they learn the basics of graph theory in mathematics, they learn types
of graphs (trees, binary trees, relational matrix), storage of graphs (vertex matrix, edge
matrix, edge list) and algorithms of graphs (breadth first traversal, depth first traversal,
relations) in informatics. They meet recursion again, divide and conquer, backtrack, and
greedy algorithms too, on basic level.
They learn all classic dynamic programming problems, as follows:
Partition problem Divide the set of numbers into two groups, where sum of
each group is same!
Longest Increasing Subsequence Find the length of the longest subsequence
of a given sequence, such that all the elements are sorted in increasing order.
Knapsack Problem A thief robbing a store can carry a maximal weight of W
in his knapsack. There are N items and ith item weighs wi and is worth vi dollars.
What items should the thief take?
Contiguous subsequence with maximum value Find the contiguous array
with the maximum sum in a given an array, containing both positive and negative
integers!
Minimal number of coins for change What is the minimal number of coins, to
make change for a given amount T only coins of values v1, v2, , vn can be used?
These examples can be solved by using recursion with optimization, the right order
of filling the table must be given usually it is not evident. There are a number of variations of these problems, sometimes the difference is merely wording.
Next type of DP problems is game strategy in various formats, like:
Optimal Strategy Consider a row of N coins of values v1, ..., vN, where N is
even. We play a game against an opponent by alternating turns. In each turn, a
player removes either the first or last coin from the row and receives the value
of the coin. Determine the maximum possible amount of money we can definitely
win if we move first?
Basic data structures may be supplemented with string and real. There are a number
of dynamic programming problems with strings, too:
Longest Common Subsequence Find the longest common subsequence of two
strings, where the elements are letters from the two strings and they should be in
the same order!
Longest Common Substring Find the longest common substring of two
strings!
Edit Distance Given two strings and a set of operations Change (C), insert (I)
and delete (D). Find minimum number of operations required to transform one
string into another!
On informatics contest classic dynamic tasks can be in every round, so the contestants
have to be ready to solve it.

70

. Erdsn Nmeth, L. Zsak

4.5. National Olympiads


In grades 1112 contestants prepare for national Olympiads. They know a lot of algorithms, in these years they learn to use advanced data structures, like set, priority queue,
stack, and they implement previously learned algorithms with these data types. While in
previous years they were asked for the existence of the solution or the number of steps
in the solution, now they also have to decrypt the entire path traversal in dynamic programming problems.
Sometimes there are strict memory limits and there is no space for the whole table. In
this case, only the values of those cells have to be stored in memory, which are essential
to the calculation of the next row. During the decryption process the rebuilding of the
table may be as hard and interesting to implement as the original problem.
They learn about combinatorial and geometrical problems.
Within the concept of divide and conquer, recursion or dynamic programming more
complicated expressions should be optimized.
There are advanced DP problems: all possible transitions and dynamic greedy type.
Example of complicated problems:
Balanced Partition There is a set of N integers each in the range 0 ... K. Partition these integers into two subsets such that you minimize |S1 S2|, where S1
and S2 denote the sums of the elements in each of the two subsets!
The dynamic programming concept among strings also leads complicated problems,
like:
Shortest Palindrome Form a shortest palindrome by appending characters at
the start of the given string.
Palindrome Min Cut Find the minimum number of cuts required to separate
the given string into a set of palindromes.
Longest Palindromic Substring Find the longest palindromic substring of a
given string!
Longest Palindromic Subsequence Find the longest palindromic subsequence
of a given string!
The contestants in the upper secondary age want to be computer scientists or engineers, they do not only know the basic algorithms but they can cope with complex tasks.

4.6. Regional and International Olympiads


When you want to prepare for Regional or International Olympiads you have to know
everything about dynamic programming which is included in the textbooks. You have
to solve a huge number of tasks. On Olympiads the solution of tasks are some kind of
creative mixture of known algorithms.
Some examples:
Interval-Scheduling Problem (Greedy and DP Approach) N k-tuples processes
are given with start & end times. Select as many processes as possible such that

The Place of the Dynamic Programming Concept in the Progression ...

71

(I) no two selected processes intersect and (II) at most one process is selected
from each k-tuple!
intersec Complete all tasks given the deadline, so that no task overlap!
Box Stacking You are given a set of N types of rectangular 3-D boxes, where
the i^th box has height h(i), width w(i) and depth d(i). You want to create a stack
of boxes which is as tall as possible, but you can only stack a box on top of another box if the dimensions of the 2-D base of the lower box are each strictly
larger than those of the 2-D base of the higher box. You can rotate a box, any of
the side can be its base. It is also allowable to use multiple instances of the same
type of box.
Counting Boolean Parenthesizations You are given a boolean expression consisting of a string of the symbols true, false, and, or and xor. Count the
number of ways to parenthesize the expression such that it will evaluate to true.
For example, there are 2 ways to parenthesize true and false xor true such that
it evaluates to true. The order is defined only by parentheses.
There are many tasks for practice on the online preparing and contest sites, like
usaco.org, codeforces.com, codechef.com, uva.onlinejudge.org, spoj.pl. If you have met
each type of concept detailed above, the textbook of Halim is a good choice for preparing for IOI.

5. Conclusions
Some antecedents of the dynamic programming concept for example the concept of recursion, might come up in earlier mathematics and informatics studies. If you are aware
of this, introducing DP as a new problem-solving strategy is much easier.
We think, if you want to teach the technique of DP you have to start from a simple
recursion then through memoization and table filling you could end with a real DP for
optimization problems. You could start the whole process in the primary school age and
circularly, returning to it in higher and higher levels your students would be familiar with
this hard concept.
In the upper primary school, the basic DP comes up: a recursive expression implemented with table filling. At the beginning of secondary school, the classic DP programs
continue the sequence: recursive expressions with optimization and at implementation
the right order of table filling need to be thought of. In upper secondary school, the
children can be familiar used with advanced types of DP: all of the previous problems
with the retrieval of the way, how the optimal solution is built up, dynamic greedy type
and the type, when you have to keep track of all possible transition states. Preparing for
Olympiads, the students need everything from textbooks and the combination of other
types of approaches.
Finally, it would not be magic for the contestants, just a useful problem-solving
strategy.

72

. Erdsn Nmeth, L. Zsak

References
BebrasInternational Contest on Informatics and Computer Fluency (20072015). http://bebras.org
http://www.beaver-comp.org.uk/; http://informatik-biber.de/archiv/
Bebis, G. (2007). CS477/677 Analysis of Algorithms.
http://www.cse.unr.edu/~bebis/CS477/
Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C. (2001). Introduction to Algorithms. MIT Press, 2nd edition.
Dagien, V., Stupurien, G. (2016). Bebras a sustainable community building model for the concept based
learning of informatics and computational thinking. Informatics in Education, 15(1), 2544.
Dasgupta, S., Papadimitriou, C.H., Vazirani, U.V. (2006). Algorithms. McGraw-Hill.
Dreyfus, S. (2002). Richard Bellman on the birth of dynamic programming. Operations Research, INFORM.
50(1), 4851.
Erds, G. (2010). A rekurzv mdszer. In: Magas Szint Matematikai Tehetsggondozs Konferencia, ZALAMAT. 2032.
Foriek, M. (2015). Towards a better way to teach dynamic programming. Olympiads in Informatics, 9, 4555.
Gupta, N. (2009). Introduction to Algorithms.
http://www.curriki.org/oer/Introduction-to-Algorithms/
Halim, S., Halim, F. (2014). Competitive Programming 3. The New Lower Bound of Programming Contests.
http://cpbook.net/
Horvth, Gy. (2004). A programozsi versenyek szerepe az oktatsban. In: INFORA Konferencia.
http://www.infoera.hu/infoera2004/eaok/horvathgyula.pdf
Kleinberg, J., Tardos, . (2006). Algorithm Design. Addison-Wesley.
Sedgewick, R., Wayne, K. (2011). Algorithms, Fourth Edition. Addison-Wesley.
Skiena, S.S. (2008). The Algorithm Design Manual. Springer-Verlag, 2nd edition.
Steinhardt, J. (2008). Advanced Dynamic Programming Techniques.
https://activities.tjhsst.edu/sct/lectures/0708/dpadvanced.pdf

. Erdsn Nmeth teaches mathematics and informatics at Batthyny


Lajos High School in Nagykanizsa. A lot of her students are in the final
rounds of the national programming competitions, some on CEOI and
IOI. She is a Ph.D. student in the Doctoral School of Faculty of Informatics, Etvs Lornd University in Hungary. Her current research
interest is teaching computer science for talented pupils in primary and
secondary school.
L. Zsak Dr. is a professor at Department of Media & Educational
Informatics, Faculty of Informatics, Etvs Lornd University in Hungary. Since 1990 he has been involved in organizing of programming
competitions in Hungary, including the CEOI. He has been a deputy
leader for the Hungarian team at International Olympiads in Informatics since 1989. His research interest includes teaching algorithms and
data structures; didactics of informatics; methodology of programming
in education; teaching programming languages; talent management.
He has authored more than 68 vocational and textbooks, some 200
technical papers and conference presentations.

Olympiads in Informatics, 2016, Vol. 10, 7385


2016 IOI, Vilnius University
DOI: 10.15388/ioi.2016.05

73

Watch them Fight! Creativity Task Tournaments


of the Swiss Olympiad in Informatics
Samuel GRTTER, Daniel GRAF, Benjamin SCHMID
Swiss Olympiad in Informatics

e-mail: {samuel,daniel,benjamin}@soi.ch
Abstract. As part of the qualification process for the Swiss Olympiad in Informatics, the contestants are each year confronted with one Creativity Task. Unlike typical problems in programming competitions, creativity tasks usually do not have an optimal solution, and are often
adaptations of popular board or computer games. After receiving all submissions, a tournament is
organized, where the students can watch how their programs play interactively against each other,
and points are awarded to the authors according to the tournament ranking.
We present and discuss this task format in general, as well as the specific creativity tasks of
the past 10 years, accompanied by an online archive of the task descriptions, sample solutions and
game servers.
Moreover, we describe our task selection process and criteria, the task creation process, and
the experience gained and best practices established in the past years.
Finally, we present the many advantages of this task format, showing why we think it is a
refreshing alternative to the common IOI-style tasks given in most national selection rounds.
Keywords: creativity tasks, interactive tasks, heuristics, programming competition, board games,
artificial intelligence contest, tournaments, task visualization.

1. Introduction
During the first round of the Swiss Olympiad in Informatics (SOI), the students have
two months to solve a set of tasks at home and submit them on the SOI website. There
are practical and theoretical tasks, and one creativity task. This paper is about the creativity tasks.
Contrary to typical tasks in programming competitions, the creativity tasks are usually designed in such a way that there is no optimal solution, or that the optimal solutions are not efficient enough. The creativity tasks are often adaptations of popular
board or computer games, and the game can be played with two or more players. The
participants task is to write a program able to play the game. We will refer to such
programs as bots.
An interesting aspect of this task format is that the participants bots can play and
compete against each other.

74

S. Grtter, D. Graf, B. Schmid

At the start of each years first round, the following material for the creativity task is
published on the SOI website:
The task description, describing the rules of the game and its parameters. Depending on the game, these could include, for instance, width and height of the
playing field, or a map of the playing field, the number of players, the initial
amount of money/food of each player, etc. The task description also specifies
the communication protocol between the bots and the game server (see below),
which defines how the bots have to communicate their actions and how they are
informed about the other bots actions. All communication is done via standard
input/output.
A game server, a program written by the task authors, which launches the bots,
communicates with them according to the protocol and keeps track of the game
state. It informs the bots about all the relevant changes and prints a log of each
action and state change. The server also acts as a judge that can terminate bots
that drop out of the game or take too long to answer. If the interaction protocol is
easy to read, the game server can also allow for human players that type in their
commands interactively. This way, the participants can play against their own
bots by hand.
Some sample bots in various programming languages. These bots follow all the
rules of the protocol, but they just pick a random move in every step. The participants can base their solutions on these sample bots to quickly learn how to
implement the protocol and input/output. Moreover, they can evaluate their bots
by letting them play against the sample bots.
A visualization, which reads the log produced by the game server, and displays a
graphical animation of the game. For some of our tasks, the game server already
provides a rudimentary text-based visualization of the game.
After the end of the first round of the SOI, the organizers let the submitted bots
compete against each other in a large number of games covering many different configurations, to make sure that the obtained results are representative and random decisions
average out well enough. The results of all these games are then aggregated into a final
score for each participant.
Between the first and the second round of the SOI, all participants are invited to an
event called SOI-Day consisting of task discussions, talks and presentations. At this
event, a shortened version of the the creativity task tournament is presented as if it was
a live tournament, and the participants can thrill while watching their bots compete
against the others.

2. Ten Years of Creativity Tasks


In this section, we give a brief presentation of each creativity task of the past ten years.
We omit details such as the communication protocols, and refer the reader to the online
task archive (http://creativity.soi.ch) for the full task descriptions.

Watch them Fight! Creativity Task Tournaments of the Swiss Olympiad in Informatics

75

2.1. Connect Five (2007)


Task description On a 20 20 grid, two players (black and white) alternate in placing a
stone of their color on an empty square. As soon as a player succeeds in placing 5 stones
in a row (horizontally, vertically or diagonally), he wins.
Note that unlike the game sold under the name Connect Four, the stones do not
fall down in their column, but stay exactly where they were placed.
Discussion This variant of the game is also known under the name Gomoku, and appeared at the International Computer Games Associations Computer Olympiad in 1989,
1990, 1991 and 1992.1

2.2. Fight of the Ant Populations (2008)


Task description On a grid with obstacles, multiple ant colonies are fighting against
each other. Each player controls all ants of a colony. In every turn, the player sees the
7 7 neighborhood of each of his ants and can move them individually to an adjacent
tile. Some tiles contain food, others contain ants or the hill of the enemy. Collecting food
and carrying it back to the own hill allows the colony to grow. If an ant attacks another
ant both die. If an ant reaches an adversarial hill, three random ants of that colony die.
Which colony survives the longest?
Discussion This game allows for a huge variety in strategies. Some submissions assigned different jobs to the ants, for instance: explorers that go to unknown territory,
workers that collect the closest food, guards that stay near the hill and warriors that try
to reach the hill of the enemy.

2.3. Grand Theft Cake (Portal Maze) (2009)


Task description The players are searching for a big cake in an unknown, polygonal
maze with walls all around them. They have a handheld portal device that allows them
to teleport from A to B instantly. They can walk around with a speed of 1 meter per
second. In 0.1 seconds, they can look in a direction to learn how far away the wall is.
It takes 5 seconds to shoot a portal in a direction (either of type A or B). The cake is a
circle of one meter diameter. The goal is to find the cake and return to the starting position as quickly as possible.
Discussion The submitted solutions made creative use of the portal. Some just used it
to return to the start quickly, others repeatedly used it as a shortcut throughout the entire
search for the cake.
1

http://www.game-ai-forum.org/icga-tournaments/game.php?id=30

76

S. Grtter, D. Graf, B. Schmid

2.4. Tanks (2010)


Task description Each player controls a tank, which can move on a line and fire one
missile per round. The tanks can use different weapons, which are specified by their
range, their impact radius, and their damage points. The tanks have an unlimited number
of missiles of each weapon. When a missile hits a position, the damage points of all
tanks within the impact radius increases by the number of damage points of the weapon,
and tanks reaching a predefined number of damage points die. Moving around costs fuel,
and the fuel is limited. The last surviving tank wins.
Discussion Most submissions implemented some simple ad hoc heuristics. The winning
solution was 285 lines long and in each round, it chose the weapon and target position
which would cause the highest total damage to all opponents, supposing that they would
not move. If there was a tie between several possibilities, the one with the biggest impact
radius was chosen.

2.5. Multisnake (2011)


Task description Multisnake is a multi-player version of the popular computer game
called snake (Fig. 1). It is played on a rectangular grid which contains some obstacles.
Each player controls a snake, and in each turn, all snakes move simultaneously by one
step. When a snake moves onto a field occupied by an obstacle or by a snake, it dies.
The winner is the last surviving snake. Some tiles contain a black or white ball. When a
snake eats a white ball, it grows by one, and when it eats a black ball, it shrinks by one.
To enforce termination of the game, all snakes grow by one each T turns, where T is a
small positive integer.
Discussion The winning solution was 1005 lines long, implemented a complex scoring
function for possible states, and explored them recursively.

Fig. 1. Multisnake.

contestants are immediately fighting against each other.


Finally, we believe that creativity tasks are also a way to train for the newer, les
standard IOI tasks where heuristical solutions are required. Examples of such c
IOI tasks include Languages and Maze from IOI 2010, Odometer from IOI 201
Watch them Fight!
TaskIOI
Tournaments
Art Creativity
Class from
2013. of the Swiss Olympiad in Informatics 77
4.4. Disadvantages of this Task Format
2.6. Find the Anthill (2012)
It often proved challenging to find tasks that beginners can easily get started wi
still leave a lot of options for the creativity of more advanced students. This hig
Task description In
this second
task,small
the story
was more
peaceful:
each ant for many of th
initial
hurdleant-themed
lead to fairly
numbers
of serious
submissions
just has to find the presented
way back to
its
own
ant
hill
(Fig.
2).
The
big
difference
is
that this
tasks. From an organizer's point of view, creativity
tasks take signific
time each ant is controlled
by
a
separate
instance
of
the
participants
submission.
So the
more time to prepare and grade than regular tasks.

program controlling5.a Conclusion


single ant does not know where the other ants of its colony are,
unless they are in its
view.
7 field ofcreativity
In7summary,
tasks proved to be a beneficial addition to the types of
Like in nature, there is a distributed way of communication though: scents. The ants can
algorithmic challenges given in the first national round of the Swiss Olympiad
place one out of 256 different scents on their current tile and they can sense the scents
Informatics.
that other ants (of their own or of other colonies) put there. So if one ant sees the hill, it
We provide the full description and supplementary material for the presented ta
can leave hints for its colleagues.

online at http://creativity.soi.ch and we want to encourage other deleg

Discussion Successful
submissions
use of
thelook
scentforward
hints to to
share
knowl-about their exper
experiment
withmade
suchcreative
task types
and
learning
edge between the ants.
Some
even
tried
to
learn
and
imitate
the
marking
patterns
of the
Acknowledgments
opponents to mess We
withwould
it and cause
confusion.
like to thank all the volunteers of the Swiss Olympiad in Informatics

created, prepared and graded these tasks over the years.

References

2.7. Who wants to be a billionaire (2013)


Aigner, M., Fromme, M. (1984). A game of cops and robbers. Discrete Applied
Mathematics, 8(1), 112.
Task description The
task B.
is (2008).
to write Breaking
a bot which
interactively
multiple Informatics Oly
Burton,
thecan
routine:
events answer
to complement
choice questions with
four
possible
answers,
using
Wikipedia
articles
as
a
knowledge
training. Olympiads in Informatics, 2, 515.
base. For each question,
theM.
bot(2013).
is allowed
to consult
up to 25 articles
on the English
Foriek,
Pushing
the boundary
of programming
contests. Olympiads
Wikipedia. To do so,
the
bot
has
to
provide
a
query
string
to
the
game
server,
and the
Informatics, 7, 2335.
game server will look
up the article
on Wikipedia
(or inand
its cache),
and feed
a plain
text
Gardner,
M. (1973)
Sim, Chomp
Race Track:
new
game
for the intelligent
version to the bot. just for Lady Luck). Scientific American, 228(1), 108115.
Verhoeff,
T.based
(2009).
years search
of IOIcombined
competition
Olympiads in Informati
Discussion Most solutions
were
on 20
keyword
withtasks.
some strategy
149166.
to avoid frequent words
which do not carry any meaning. The submitted bots would not
have become billionaires, but the best was still twice as good as a random bot (which
would have scored 14 of the points).

Fig. 2. Find the Anthill.

78

S. Grtter, D. Graf, B. Schmid

There were 11 submissions, and for the tournament, they were fed a total of 547
questions. Table 1 shows the ranking and their percentage of correct answers. Note that
the primary ranking criterion was whether they were compilable and never crashed, and
the number of correct answers was only the secondary criterion.

2.8. Cops and Robbers (Scotland Yard) (2014)


Task description Some cops are hunting a robber in a city whose streets and junctions
are given as an undirected connected graph (Fig. 3). Initially, the cops and robbers are
positioned on distinct junctions (nodes in the graph), and in each round, the robber and
all cops move along an edge of the graph. As soon as a cop moves onto the same node
as the robber, the cops win, and if this never happens during a predefined number of
rounds, the robber wins.
One bot controls the robber, and another bot controls all cops. Every bot must be
able to play both roles. At any time, the bots know the entire graph and the positions of
all agents.
Discussion This is a classic problem in graph theory and we refer to Aigner and Fromme
for a nice introduction (Aigner and Fromme, 1984).
The participants mostly implemented sophisticated scoring functions that would for
instance weigh the distance between the cops and the robbers against the number of possible escape routes.
Table 1
The ranking and their percentage of correct answers
rank

% correct
behavior

50% 37% 35%


never crashed

45% 36% 28%


sometimes crashed

10

27%

2%

0%

N/A N/A
did not compile

Fig. 3. Cops and Robbers.

10

Watch them Fight! Creativity Task Tournaments of the Swiss Olympiad in Informatics

79

2.9. Diamond Auction (2015)


Task description The players are at an auction bidding for diamonds. Each player starts
with the same amount of gold and for each diamond everyone can bid an amount of his
choosing. The highest bid gets the diamond, but all offered gold has to be paid. The goal
is to maximize the number of bought diamonds using only the given amount of gold. To
allow for more interesting strategies, there are several games played with the same players without restarting the participants programs. This way, they can learn and exploit
each others strategies.
Discussion Being a very simple game with a simple protocol, we had many submissions
for this task. Many of them implemented a random strategy sometimes even worse than
our sample bots. Most of the more successful solutions tried to imitate the opponent or
to predict the next move. The following graph (Fig. 4) shows the last game of the final,
the lines showing the bids of the two players for the different rounds. Although the bids
seem random the players are able to predict each others bid and bid just a little bit more.
This results in a very clever use of the available gold.

2.10. Vector Car Racing (2016)


Task description Each player controls a car and in each round he can change his velocity vector by at most one in both directions. The game is played on a grid (i.e. a graph
paper) with a start, a goal, some checkpoints and some walls enclosing a racetrack. The
goal is to visit each checkpoint at least once and be the first to reach the goal. Should a
player drive into the wall (e.g. if he didnt slow down early enough in a turn) he will be
reset to the last visited checkpoint. To allow for some interaction, we added two items
that can manipulate the velocity vector of other players.
Discussion This game is a well known pen and paper game and goes back to Jrg Nievergelt. It became widely known by an article in Martin Gardners column in the Scientific American (Gardner, 1973).

Fig. 4. Diamond Auction (the graph shows the last game of the final).

80

S. Grtter, D. Graf, B. Schmid

The submissions fell into one of two categories: sophisticated algorithms beating
human players easily (3 submissions) or being barely able to play the game (4 submissions). One example from the second category used DFS to determine the shortest
path resulting in some of the longest possible paths.
The winning submission consists of 1741 lines of code using a wide range of algorithms. On small maps it uses a four dimensional BFS (location and velocity) to find
the optimal solution. On bigger maps, a heuristic is used to improve the runtime of this
algorithm and only paths between two checkpoints are calculated. To find the best order
of checkpoints it uses some more heuristics to find a good approximations for the traveling salesman problem.

2.11. Statistics
Table 2 shows our observed participation rates in the last ten years. Given the bonus-like
character of the creativity tasks, participation rates in the past years fluctuated heavily.
Usually, only students with enough time (and interest) left after solving the five classical
problems tackled the creativity task. Tasks with a very simple interface (like the diamond auction in 2015) seem to have drawn additional interest, probably because writing
a first solution was easily possible within an hour, also for beginners.
(4 submissions). One example from the second category used DFS to determine
the shortest path resulting in some of the longest possible paths.
The winning submission
3. Implementation
Details consists of 1741 lines of code using a wide range of
algorithms. On small maps it uses a four dimensional BFS (location and velocity)
to nd the optimal solution. On bigger maps, a heuristic is used to improve the
runtime
thisSelection
algorithm
and
only paths
between two checkpoints are calculated.
3.1.
Our of
Task
and
Creation
Process
To nd the best order of checkpoints it uses some more heuristics to nd a good
approximations for the traveling salesman problem.
The SOI is organized by a team of approximately twenty people, most of whom are
former participants and now university students. Each year when the preparations of the
2.11round
Statistics
first
of the SOI start, they discuss a few proposals for the creativity task on their
internal mailing list. Once the task is chosen, two to three organizers are selected to
write
the detailed
description
and implement
the game
server
and last
the visualization.
The table
belowtask
shows
our observed
participation
rates
in the
ten years.
A
few more
organizers character
proofread the
taskcreativity
description
and write
sample bots
in as
Given
the bonus-like
of the
tasks,
participation
rates
in many
the
languages
possible. heavily. Usually, only students with enough time (and
past yearsas uctuated
interest) left after solving the ve classical problems tackled the creativity task.
Tasks with a very simple interface (like the diamond auction in 2015) seem to
have drawn additional interest, probably
Table 2because writing a rst solution was
easily possible within an hour,
also
for
Participation ratesbeginners.
in the last ten years
year

2008 2009 2010 2011


2012 2013 2014 2015 2016
year 20072007
2008 2009 2010 2011 2012
2013 2014 2015 2016
c5
maze tanks
tanks snake
snake ants
ants quiz
racerace
tasktask
c5
antsantsmaze
quiz c&r
c&r
creativity
17
N/A 4 4 6 6 2 2 1010 1111
25
77
creativity
17
N/A
99
25
total
21
31
35
40
48
29
29
28
52
72
total
21
31
35
40
48
29
29
28
52
72

3
3.1

Implementation Details
Our Task Selection and Creation Process

Watch them Fight! Creativity Task Tournaments of the Swiss Olympiad in Informatics

81

The organizers of the creativity task are usually people who have successfully taken
part in the creativity task a few years before when they were participants, and they are
supported by older organizers who prepared the creativity task a few times before. This
ensures a good knowledge transfer, which leads to good creativity tasks, even though
this task format is more challenging for task creators than ordinary tasks and even though
every year, many organizers join and leave the team.

3.2. Evaluating the Submissions


After the end of the first round of the SOI, the organizers review and compile all submissions for the creativity task, and then run a large number of games, covering a representative selection of different game parameter and player combinations. The results of all
these games are then aggregated into a final score for each participant, and points for the
creativity task are awarded as follows:
A bot that follows the protocol and is capable of playing the game without violating
any rules is awarded a predefined percentage p of the points, usually between 30%
and 50%, depending on how difficult the task is. We also look at the source code to
see if it witnesses more effort than just copying one of the provided sample bots.
The rest of the points are awarded according to the aggregated score described
above, in such a way that the participant ranked last gets p points, and the participant ranked first gets full score.
If the bot contains minor bugs, such that it can still play in most games, but sometimes crashes, runs into an infinite loop, or violates the rules, some points are deducted.
This grading scheme ensures that every effort to write a program for this task is rewarded, even if it ranks last, which hopefully encourages beginners to tackle this task.

3.3. Technical Considerations


Ease of running the game server and the visualization It is crucial that all participants
are able to run the game server on their own computers.2 However, the game server
needs to be able to invoke other programs (the bots) and read from their standard output
and write to their standard input, a feature which is hard to get operating system independent. And even if the game server works on all major operating systems, the instructions
on how to install the dependencies, compile and run it might look so long and complicated that beginners are quickly scared off. For the visualization, it can even get worse,
if specific graphics libraries have to be installed and linked.
2

We cannot provide an online game server instead, because in the first round of the SOI, no participants
should be disadvantaged because they cannot use their favorite programming language. This would mean
that we would have to support a very large number of programming languages, and moreover, it would
require a big effort for the sandboxing.

82

S. Grtter, D. Graf, B. Schmid

In our experience, implementing the game server in Java, which is available on all
platforms, seems to be the best solution. But even getting a Java game server to run was
a bit challenging for some participants, because some could only install Java 6 (instead
of newer versions) on their system, while others did not know how to specify the paths
to the bots as command line arguments, etc. But we could always help them by email
support or through our forum. What we do not know, however, is how many people did
not succeed in getting the server to run, but did not ask for help.
For the visualization, the two best solutions seem to be either to integrate the visualization in the Java game server, or to implement it as an HTML5/JavaScript page,
where one can paste the log of the game server, and then watch the visualization. An
advantage of the latter is that it only requires a web browser, which is available on every
computer, so we can provide some sample game logs, so that the participants can watch
some games before even starting to implement their own solution and to bother getting
the game server to run.
Fraud Detection The grading of the creativity task is not fully automated on purpose.
The submissions are compiled manually to check for compatibility issues and the source
code is read to get an idea of the participants solution and to check that all the rules are
followed. Given the small number of participants, this is feasible and also eliminates the
need for a separate fraud detection or sandboxing of the submitted programs.

4. Discussion
4.1. Task Selection Criteria
We now present our criteria for the selection of the creativity task. This is more a collection of useful arguments that came up in past discussions rather than an ultimate list.
Interactivity: It should be interactive, and interaction should not only happen between the game server and the bots, but also between the bots, i.e. the possible
moves of a player should depend on the actions that the other players took before.
This is mostly to make the task more fun and different from the standard tasks, but
it is not strictly necessary. For instance, the Grand Theft Cake task (section 2.3),
or the Who wants to be a billionare? task (section 2.7) do not have any interaction
between the players, and still were successful creativity tasks. In the case of the
Vector Car Racing task (section 2.10), however, some special effects were added
to the traditional game to make it interactive, and to increase the size of the search
space that optimal solutions would have to explore.
Hardness: There should be no optimal solution, or optimal solutions should be too
expensive to calculate.
Flat learning curve: The task should be simple, with few, easy to understand
rules, so that it is suitable for beginners, but it should also offer many interesting
options for advanced participants.

Watch them Fight! Creativity Task Tournaments of the Swiss Olympiad in Informatics

83

Novelty: The task should not be too standard to make sure one cannot just copy
and adapt a standard solution found on the internet. For instance, chess or Nine
Mens Morris were proposed in the past years, but not chosen for this reason.
Continuous Complexity Curve: There should be a continuous spectrum of imagineable solutions between straightforward random bots and very sophisticated solutions.
Plethora of solutions: There should be many different solutions that could work
reasonably well and are feasible to implement. For instance, for some proposed
tasks, it was feared that applying a standard minimax algorithm would be almost
the only reasonable solution, and these tasks were thus not chosen.
Manual playing: It is a plus if the game can be played by hand, such as Multisnake
(section 2.5) or Vector Car Racing (section 2.10), so that the participants can compare their bots to their own intuitive playing style.
Visualizability: A good task should allow for an appealing way of watching the
interaction between the bots and giving a dramatic view on the progress of the
game.

4.2. Similar Task and Contest Types


The IOI and other programming contest are always experimenting with new, less algorithmic task types. We refer to Verhoeff (Verhoeff, 2009) for an overview of classical,
algorithmic IOI tasks. Foriek (Foriek, 2013) gives an overview of the programming
contest landscape. He also presents some tasks from the IPSC and Slovak national competitions whose goal is different from just finding the fastest algorithm. Some contests
entirely focus on hard optimization problems like Topcoders Marathon matches and
Googles Hash Code and other contests feature tournaments of competing bots for interactive problems like the AI Challenge or the Computer Olympiad.
Creativity-like tasks are also mentioned as game-playing events by Burton in (Burton, 2008), where many interesting suggestions for out-of-the-ordinary activities in
Olympiad training camps are proposed.

4.3. Advantages of this Task Format


In our opinion, creativity tasks offer a number of unique possibilities. These nonstandard
tasks can keep the participants busy for many weeks. They can try out all kinds of crazy
algorithms and even the best ones are never really done. But also students with limited
time can participate with some quick extension of the provided random bot.
The visualization of these tasks are ideal to be shown on a large screen during an
award ceremony as parents, friends and teachers can really see what the contestants
were doing. As related board and computer games are well-known, an audience that is
not familiar with specifics of the algorithmic challenge can also appreciate the results.

84

S. Grtter, D. Graf, B. Schmid

The tournaments are fun to watch as the interaction between the bots suggests that the
contestants are immediately fighting against each other.
Finally, we believe that creativity tasks are also a way to train for the newer, lessstandard IOI tasks where heuristical solutions are required. Examples of such creative
IOI tasks include Languages and Maze from IOI 2010, Odometer from IOI 2012 and Art
Class from IOI 2013.

4.4. Disadvantages of this Task Format


It often proved challenging to find tasks that beginners can easily get started with but
still leave a lot of options for the creativity of more advanced students. This higher initial
hurdle lead to fairly small numbers of serious submissions for many of the presented
tasks. From an organizers point of view, creativity tasks take significantly more time to
prepare and grade than regular tasks.

5. Conclusion
In summary, creativity tasks proved to be a beneficial addition to the types of algorithmic
challenges given in the first national round of the Swiss Olympiad in Informatics.
We provide the full description and supplementary material for the presented tasks
online at http://creativity.soi.ch and we want to encourage other delegations
to experiment with such task types and look forward to learning about their experiences.

Acknowledgments
We would like to thank all the volunteers of the Swiss Olympiad in Informatics who created, prepared and graded these tasks over the years.

References
Aigner, M., Fromme, M. (1984). A game of cops and robbers. Discrete Applied Mathematics, 8(1), 112.
Burton, B. (2008). Breaking the routine: events to complement Informatics Olympiad training. Olympiads in
Informatics, 2, 515.
Foriek, M. (2013). Pushing the boundary of programming contests. Olympiads in Informatics, 7, 2335.
Gardner, M. (1973) Sim, Chomp and Race Track: new game for the intelligent (and not just for Lady Luck).
Scientific American, 228(1), 108115.
Verhoeff, T. (2009). 20 years of IOI competition tasks. Olympiads in Informatics, 3, 149166.

Watch them Fight! Creativity Task Tournaments of the Swiss Olympiad in Informatics

85

S. Grtter was a participant at CEOI 2009 and IOI 2010, and has
helped with the organization of the Swiss Olympiad in Informatics
since 2011. He was deputy leader of the Swiss team at IOI 2013.
He holds a BSc in Computer Science from Ecole Polytechnique
Fdrale de Lausanne (EPFL), where he is currently pursuing his MSc
and working at the Scala Lab under the supervision of Prof Martin
Odersky.
His research interests are logic, formal languages, type systems and
compilers.
D. Graf participated at CEOI 2009 and IOI 2009 (bronze) and returned
to IOI as the delegation leader of the Swiss team in 2012, 2014 and
2015. He volunteers for the Swiss Olympiad in Informatics since 2010
and is its president since 2011.
He holds a MSc in Computer Science from the Swiss Federal Institute of Technology in Zurich (ETHZ), where he is currently pursuing
his PhD in the group for Algorithms, Data Structures, and Applications
of Prof. Peter Widmayer.
B. Schmid participated at IOI 2013, IOI 2014 (bronze) and CEOI 2013
(bronze). Since 2015 he helps organizing the Swiss Olympiad in Informatics.
He is currently pursuing a BSc in Computer Science from ETH
Zurich.

Olympiads in Informatics, 2016, Vol. 10, 8798


2016 IOI, Vilnius University
DOI: 10.15388/ioi.2016.06

87

Understanding Unsolvable Problem


Jonathan Irvin GUNAWAN
Undergraduate Student
School of Computing, National University of Singapore
Computing 1, 13 Computing Drive, Singapore 117417
e-mail: jonathan.irvin@yahoo.com
Abstract. In recent IOIs, there are several problems that seem unsolvable, until we realise that
there is a special case to the problem that makes it tractable. In IOI 2014, the problem Friend
appears to be a standard NP-hard Maximum Independent Set problem. However, the graph is generated in a very special way, hence there is a way to solve the problem in polynomial time. There
were several contestants who didnt identify the special case in this problem, and hence were stuck
at the problem. In this paper, we will study a well-known technique called reduction to show that
a problem we are currently tackling is intractable. In addition, we introduce techniques to identify
special cases such that contestants will be prepared to tackle these problems.
Keywords: special case, unsolvable, NP-hard.

1. Introduction
The problem Friend in IOI 2014 required contestants to find a set of vertices with maximum total weight, such that no two vertices in the set are sharing a common edge. This
is a classical Weighted Maximum Independent Set problem. We can show that Weighted Maximum Independent Set problem is NP-hard by reduction from 3-SAT (Cormen
etal., 2009). Since the formulation of NP-completeness 4 decades ago, no one has been
able to propose a solution to any NP-hard problem in polynomial time. Clearly, it is not
expected that a high school student can solve the problem in 5 hours. None of the Indonesian IOI 2014 team solved this problem during the contest. After returning from the
competition, I asked the Indonesian team about this problem. None of the team members
were aware of the fact that Maximum Independent Set is an NP-hard problem, and thus
were stuck trying to solve a general Maximum Independent Set problem.
A similar problem also occurred in IOI 2008. The problem Island required contestants to find a longest path in a graph with 1,000,000 vertices. The longest path problem
is a classic NP-hard problem which can be reduced from the Hamiltonian path problem.
If a contestant is not aware that the longest path problem is difficult to solve, the contestant may spend a lot of his/her time just to tackle the general longest path problem,
without realising that there is a special case to the given graph.

88

J.I. Gunawan

Generally, some contestants spend too much thinking time trying to solve something
that is believed to be unsolvable. If only they realise that their attempt is intractable,
they may try a different approach and find a special case of this problem. In section 2
of this paper, we will introduce a classic reduction technique often used in theoretical
computer science research. In the context of competitive programming, we may find out
that a problem which we are attempting is unlikely to be solvable. After realizing that
a problem is intractable, we are going to discuss how to proceed to solve the problem
in section 3. Finally, in section 4 we will take a look at some common special cases in
competitive programming that can be used to solve these kind of problems.

Fig. 1. The result of Indonesian team in IOI 2014, taken from http://stats.ioinformatics.org. The red squared column highlights the Friend problem.

Fig. 2. IOI 2014 tasks statistics, taken from http://stats.ioinformatics.org. Friend


problem is the second least accepted problem in IOI 2014. It may be because some contestants (at least all the Indonesians) were stuck at trying to solve a general case of Maximum
Independent Set.

Fig. 3. The result of Indonesian team in IOI 2008, taken from http://stats.ioinformatics.org. The red squared column highlights the Island problem.

Understanding Unsolvable Problem

89

2. Identifying Intractability of a Problem through Reduction

22 Identifying
Identifying
Intractability
Intractability
of
aaRedu
Pro
Pro
22 Identifying
of
aaProblem
through
Reduc
IdentifyingIntractability
Intractability
of
Problem
through
2 Identifying
Intractability
of aof
Problem
2
Identifying
Intractability
ofR
entifying
Intractability
of
a
Problem
through
Reduction
2
2
Identifying
Identifying
Intractability
Intractability
of
of
a
a
Problem
Problem
through
through
We
would
like
to
know
that
the
problem
that
we
are
attempting
is
unlikely
to
have
an
m
through
Reduction
actability
of
a
Problem
through
Reduction
ifying
Intractability
of
a Problem
through
Reduction
2 through
Identifying
Intractability
ofthe
aproblem
Problem
through
R
Intractability
of
a
Problem
through
Reduction
of
a
Problem
Reduction
We
We
would
would
like
like
to
to
know
know
that
that
the
problem
that
that
we
we
are
are
attempting
attempting
isis u
immediate
solution.
The
most
way
toare
apply
athe
well-known
technique
called
rough Reduction
solut
We
would
totoknow
that
the
problem
that
attempting
is
unlikely
to
have
an
immediate
soluti
We
wouldlike
like
know
that
thecommon
problem
that
we
are
attempting
is
unlikely
to
have
an
immediate
solu
We
would
like
toiswe
know
that
problem
that
we
are
attempting
is
unlikely
We that
would
like
to
thatisisthe
problem
thatcalled
we
are
att
actability
of
awould
Problem
doto
like
to
know
that
the
problem
that
we
are
attempting
is Reduction
unlikely
to
have
anknow
immediate
solution.
We
We
would
would
like
like
to
know
know
that
that
the
problem
problem
that
we
are
are
attempting
attempting
unlikely
unlikely
to
toThe
have
have
an
an
immedi
immed
have
anwe
immediate
The
oblem
that
areproblem
attempting
is
unlikely
tothrough
an
immediate
solution.
The
most
most
common
common
way
way
iswe
iscalled
to
to
apply
apply
aa and
well-known
well-known
technique
technique
called
redu
reduction.
Suppose
we
know
that
problem
X
is
impossible
to
solve,
we
also
know
know
that
the
that
we
attempting
isthe
unlikely
to
have
an
immediate
solution.
The
most
common
way
is
toto
apply
ahave
technique
reduction.
Suppose
we
know
that
prob
We solution.
like
know
that
the
problem
that
are
is
unlikely
to
have
an
immedia
most
common
way
isare
to
apply
awell-known
well-known
technique
called
reduction.
Suppose
we
know
thatreduc
pro
most
common
way
is
to we
apply
aattempting
well-known
technique
called
reduction.

at
the
problem
that
we
are
attempting
isSuppose
unlikely
to have
have
an
immediate
solution.
The
tanthe
problem
that
we
attempting
is
unlikely
to
an
immediate
solution.
The
most
common
isknow
apply
a well-known
technique
attempting
is
unlikely
to
have
anproblem
immediate
solution.
1 to
mmon
isknow
to
aare
well-known
technique
called
reduction.
Suppose
we
know
problem
X isproblem
immediate
solution.
The
most
most
common
common
way
way
is
is
to
to
apply
apply
aknow
aThe
well-known
well-known
technique
technique
called
called
reduction.
reduction.
we
we know
know
Suppose
we
that
problem
X
is
well-known
technique
called
reduction.
we
that
problem
Xway
isX
impossible
impossible
to
to
solve,
solve,
and
we
we
also
also
that
that
we
we
can
solve
solve
problem
XX
b.tI
11 1by
that
we
can
solve
X
by
using
problem
Y
asand
a black-box
If
we
can
solve
way
isaway
to
apply
aapply
well-known
technique
called
reduction.
Suppose
we
know
problem
Xcan
isSuppose
impossible
toto
solve,
and
we
know
that
we
can
solve
problem
by
using
problem
YSuppose
asasawe
.th
most
common
way
isto
tohave
apply
ato
well-known
technique
called
reduction.
Suppose
we
impossible
solve,
and
wealso
also
know
that
we
can
solve
problem
Xthat
by.X
using
problem
Y
ablack-box
black-box
impossible
solve,
and
we
also
know
that
we
can
solve
problem
X know
bysolve
using
apply
well-known
technique
called
reduction.
Suppose
we
know
that
problem
X
is
pply
a
well-known
technique
called
reduction.
Suppose
we
know
that
problem
is
impossible
to
solve,
and
we
also
know
that
can
p
1
blem
that
we
are
attempting
is
unlikely
an
immediate
solution.
The
e
called
reduction.
Suppose
we
know
that
problem
X
is
1
1
elve,
tothat
solve,
and
we
also
know
that
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
If
we
can
we
know
that
problem
X
is
impossible
impossible
to
to
solve,
solve,
and
and
we
we
also
also
know
know
that
that
we
we
can
can
solve
solve
problem
problem
X
X
by
by
using
using
problem
problem
Y
Y
as
as
a
a
blac
bla
1Y
problem
Y
as
a
black-box
.
If
we
can
ow
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
If
we
can
solve
solve
problem
problem
Y,
Y,
then
then
we
we
can
can
solve
solve
problem
problem
X
X
as
as
well.
well.
Therefore,
Therefore,
pro
pr
problem
Y,
then
we
can
solve
problem
X
as
well.
Therefore,
problem
is
also
imand
we that
also
know
that
we
can
solve
problem
X
by
using
problem
Ysolve
as
a11 .problem
black-box
we
can
solve
problem
Y,
then
we
can
solve
problem
XY
as
well.
Therefore,
problem
YIf
also
impossible
to
impossible
toassolve,
and
we1problem
also
know
that
we
can
Xcan
using
problem
Y as
as
asolve.
black
solve
problem
Y,
then
we
can
solve
problem
X
as
well.
Therefore,
problem
Yis
is
also
impossible
to
solve
solve
Y,
then
we
can
solve
problem
X.by
as
well.
Therefore,
problem
eeY
also
know
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
If
we
can
also
know
that
we
can
solve
problem
X
by
using
problem
as
a
black-box
.
If
we
can
solve
problem
Y,
then
we
solve
problem
X
well.
T
ell-known
technique
called
reduction.
Suppose
we
know
that
problem
X
is
1
problem
X
by
using
problem
Y
a
black-box
.
If
we
can
2
Identifying
Intractability
of
Problem
through
Reduc
blem
Y,
then
can
solve
problem
X
Therefore,
Y as
is a
also
impossible
toproblem
solve.
a we
black-box
. Ifto
we
can
solve
problem
Y,
Y,as
then
then
we
can
can
solve
solve problem
problem
XX
as
well.
well.
Therefore,
Therefore,
problem
YY isis also
also impossible
impossible
possible
to
solve.
isasalso
impossible
solve.
Xcan
aswe
well.
Therefore,
problem
Ywell.
iswe
also
impossible
,Yproblem
then
solve
problem
X
as
well.
Therefore,
problem
Ytoissolve.
also
to solve.
solve
problem
Y,
then
we
canY
solve
problem
X1 .asIfimpossible
well.
Therefore,
problem Y is also impossible t
can
solve
problem
X
as
well.
Therefore,
problem
Y
is
also
impossible
to
solve.
an
solve
problem
X
as
well.
Therefore,
problem
is
also
impossible
to
solve.
w
that
we
can
solve
problem
X
by
using
problem
as
a
black-box
we
can
Therefore,
problem
Y
is
also
impossible
to
solve.
We are using NP-hard problems forWe
illustration.
Recall that
NP-hard
problems
have
impossible to solve.
We
are
are using
using
NP-hard
NP-hard
problems
problems
for
for
illustration.
illustration.
Recall
Recall
that
that
NP-hard
NP-har
We
using
problems
for
illustration.
Recall
that
NP-hard
problems
to
bebe
solved
ininpopt
Weare
arelike
using
NP-hard
problems
for
illustration.
Recall
that
NP-hard
problems
have
yet
toNP-hard
solved
We
are
using
problems
for
Recall
that
proble
Weyet
would
toNP-hard
know
that
problem
thatNP-hard
we
are
attempting
isillustration.
unlikely
to have
have
an
immediate
soluti
We
are
using
NP-hard
problems
foryet
illustration.
Recall
problem
X as
well.
Therefore,
problem
Ythe
is also
impossible
toproblems
solve.
to
be
solved
in
polynomial
time
for
more
than
4
decades.
MIN-VERTEX-COVER
eNP-hard
using
NP-hard
problems
for
illustration.
Recall
that
NP-hard
have
yet
to
be
solved
in
polynomial
We
We
are
are
using
using
NP-hard
NP-hard
problems
problems
for
for
illustration.
illustration.
Recall
Recall
that
that
NP-hard
NP-hard
problems
problems
have
have
yet
yet
to
to be
be
so
so
ms
have
yet
to
be
solved
in
polynomial
or
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in
polynomial
time
time
for
for
more
more
than
than
4
4
decades.
decades.
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
is
a
a
graph
graph
prob
pro
2
Identifying
Intractability
of
a
Problem
through
Reductio
2
Identifying
Intractability
of
a
Problem
through
Redu
problems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in
polynomial
minimu
time
for
more
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves
nding
a
minimum
We
are
using
NP-hard
problems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solv
time
for
more
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves
nding
a
minim
time
for
more
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
most
common
way
isthat
tobeinvolves
apply
ainfinding
well-known
technique
called
reduction.
Suppose
we
know that
prob
roblems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in
polynomial
roblems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in
polynomial
time
for
more
than
4graph
decades.
MIN-VERTEX-COVER
isth
ll
that
NP-hard
problems
have
yet
to
solved
polynomial
2
Identifying
Intractability
of
a
Problem
throu
2
2
Identifying
Identifying
Intractability
Intractability
of
of
2
a
a
Problem
Identifying
Problem
through
through
Intractability
Reduction
Reduction
of
is
a
graph
problem
a
minimum
subset
of
nodes
such
that
for
every
more
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves
nding
a
minimum
subset
yet
to
be
solved
in
polynomial
time
time
for
for
more
more
than
than
4
4
decades.
decades.
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
is
a
a
graph
problem
problem
that
that
involves
involves
nding
nding
hat
involves
nding
a
minimum
subset
-VERTEX-COVER
is
a
graph
problem
that
involves
nding
a
minimum
subset
of
of
nodes
nodes
such
such
that
that
for
for
every
every
edge,
edge,
at
at
least
least
one
one
of
of
its
its
endpoint
endpoint
is
is
in
in
ta
tifying
Intractability
a atProblem
through
Reduction
han
4MIN-VERTEX-COVER
decades.
MIN-VERTEX-COVER
isof
aof
graph
that
involves
nding
aby
minimum
1sub
MAX-INDEPENDENTof
nodes
such
that
for
every
edge,
least
one
ofnding
its
endpoint
the
subset.
MAX-INDEPENDENT-S
time
for
more
than
4also
decades.
MIN-VERTEX-COVER
isisat
aXingraph
problem
that
involves
nding
ofRecall
nodes
such
that
for
every
edge,
atproblem
least
one
ofnodes
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT
nodes
such
that
for
every
edge,
least
one
ofsubset
its
endpoint
is in
the
impossible
tolike
solve,
and
we
know
that
we
can
solve
problem
using
problem
Yleast
as immediate
aone
black-box
.aT
I
des.
is
a
graph
problem
that
involves
nding
a
minimum
subset
des.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves
a
minimum
subset
of
such
that
for
every
edge,
at
of
its
end
or
illustration.
that
NP-hard
problems
have
yet
to
be
solved
in
polynomial
is
a
graph
problem
that
involves
nding
a
minimum
subset
Intractability
of
a
Problem
through
Reduction
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
is
a
graph
We
would
like
to
know
that
the
problem
that
we
are
attempting
is
unlikely
to
have
an
immediate
solution.
We
would
like
to
know
that
the
problem
that
we
are
attempting
is
unlikely
to
have
an
immediate
solution.
We
would
to
know
that
the
problem
that
we
are
attempting
is
unlikely
to
have
an
solu
such
that
for
every
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
is
a
es
a graph
minimum
subset
of
of
nodes
nodes
such
such
that
for
for every
every
edge,
edge,
at
at
least
least
one
one
of
of its
its
endpoint
isissubset
in
in the
theat
subset.
subset.
MAX-INDEPE
MAX-INDEPE
set.nding
MAX-INDEPENDENT-SET
isthat
athat
at
least
one
of
its problem
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
afor
graph
graph
problem
problem
of
of
nding
nding
athat
aisendpoint
maximum
maximum
subset
of
of
nodes
nodes
such
such
that
that
for
for eT
hat
for
every
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
is
a
endp
of
nding
a
maximum
subset
of
nodes
such
that
every
edge,
most
one
of
its
endpo
of
nodes
such
for
every
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPEN
graph
problem
of
nding
a
maximum
subset
of
nodes
such
for
every
edge,
at
most
one
of
its
endp
graph
problem
of
nding
a
maximum
subset
of
nodes
such
for
every
e
2
Identifying
Intractability
of
a
Problem
through
Redu
We
would
like
to
know
that
the
problem
that
we
are
attempting
is
unlikely
to
have
an
We
We
would
would
like
like
to
to
know
know
that
that
the
the
problem
problem
that
that
we
we
are
are
attempting
attempting
We
would
is
is
like
unlikely
unlikely
to
know
to
to
have
have
that
an
an
the
immediate
immediate
problem
that
solution.
solution.
we
are
The
The
att
solve
problem
Y,
then
we
can
solve
problem
X
as
well.
Therefore,
problem
Y
is
also
impossible
to
solve.
ry
edge,
at
least
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
isof
athat
ry
at
least
its
endpoint
is
the
subset.
MAX-INDEPENDENT-SET
is
aat
graph
problem
ofsuch
nding
maximum
subset
of
nodes
su
VERTEX-COVER
iscommon
aof
graph
problem
involves
nding
aSuppose
minimum
subset
ndpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
isfor
aof
problem
of
finding
ais
maximum
subset
of
nodes
such
that
for
every
edge,
most
one
of
toedge,
know
that
theone
problem
that
are
attempting
is
unlikely
tocalled
have
an
immediate
solution.
The
most
common
way
is
to
apply
anodes
well-known
technique
called
reduction.
Suppose
we
know
that
problem
X
most
common
way
is
to
apply
ain
well-known
technique
reduction.
Suppose
we
know
problem
most
way
to
apply
aat
technique
called
reduction.
Suppose
weisthat
know
that
pro
oblem
nding
aone
maximum
subset
such
that
every
edge,
at
one
its
endpoint
in most
X-INDEPENDENT-SET
is
aproblem
graph
graph
problem
of
ofthat
nding
nding
aawell-known
maximum
maximum
subset
subset
of
of
nodes
nodes
such
that
for
for
every
every
edge,
edge,
at
at
most
one
one
dge,
atof
most
one
of
its
endpoint
in
um
subset
nodes
such
that
forwe
every
edge,
most
one
its
endpoint
ismost
in
the
the
subset.
subset.
Suppose
we
we
already
already
know
know
that
MIN-VERTEX-COVER
MIN-VERTEX-COVER
isof
isoX
of
nding
aofsubset
maximum
subset
of
nodes
such
that
for
every
edge,
at
most
one
of
its
endpoint
is
in
the
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
is
athat
NP-hard
problem.
we
ci
graph
problem
of
nding
a maximum
subset
of
nodes
such
that
for
every
edge,
atTherefore,
most
one
of
the
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
is
ato
NP-hard
problem.
Therefore,
we
the
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
is
aX
NP-h
at
the
problem
that
we
are
attempting
is
unlikely
to
have
an
immediate
solution.
The
most
common
way
is
to
apply
a
well-known
technique
called
reduction.
Suppose
we
most
most
common
common
way
way
is
is
to
to
apply
apply
a
a
well-known
well-known
technique
technique
most
called
called
common
reduction.
reduction.
way
Suppose
Suppose
is
apply
we
we
know
a
know
well-known
that
that
problem
problem
technique
X
is
1
1
maximum
of
nodes
such
that
for
every
edge,
at
most
one
of
its
endpoint
is
in
1is
maximum
subset
of
nodes
such
that
for
every
edge,
at
most
one
of
its
endpoint
is
in
the
subset.
Suppose
we
already
know
MIN-VERTEX
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
is
a
such
that
for
every
edge,
at
most
one
of
its
endpoint
is
in
its
endpoint
is
in
the
subset.
Suppose
we
already
know
that
MIN-VERTEXCOVER
is
way
isimpossible
to
apply
ato
well-known
technique
called
reduction.
Suppose
we
know
that
problem
Xcan
is
impossible
to
solve,
and
we
also
know
that
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
If
we
solve,
and
we
also
know
that
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
If
we
impossible
to
solve,
and
we
also
know
that
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
t.
Suppose
we
already
know
that
MIN-VERTEX-COVER
is
a
NP-hard
problem.
Therefore,
we
show
most
one
of
its
endpoint
is
in
the
the
subset.
subset.
Suppose
Suppose
we
we
already
already
know
know
that
that
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
is
a
a
NP-hard
NP-hard
problem.
problem.
There
There
hard
problem.
Therefore,
we
can
show
ow
that
MIN-VERTEX-COVER
is
a
NP-hard
problem.
Therefore,
we
can
show
that
that
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
is
is
also
also
a
a
NP-hard
NP-hard
problem
problem
by
by
reduc
reduc
We
would
likewe
toalso
know
that
the
problem
that
we
are
attempting
is aproblems
unlikely
to
have
an
immediate
solu
1problem
1reducing
pose
we
already
know
that
MIN-VERTEX-COVER
isknow
asolve
NP-hard
problem.
Therefore,
can
show
1.solved
that
MAX-INDEPENDENT-SET
iswe
also
awe
NP-hard
problem
by
awe
proble
the
subset.
Suppose
already
that
MIN-VERTEX-COVER
is
aas
NP-hard
problem.
Therefo
that
MAX-INDEPENDENT-SET
ismost
also
asolve
NP-hard
problem
by
reducing
MIN-VERTEX-COVER
probl
that
MAX-INDEPENDENT-SET
isreducing
also
apo
apply
a well-known
technique
called
reduction.
Suppose
we
know
that
problem
XNP-hard
isaMIN-VERTEX-COVER
impossible
to
solve,
and
also
know
that
we
can
solve
problem
X
by
using
Y
apM
impossible
impossible
to
solve,
solve,
and
and
we
also
know
know
that
that
we
can
can
problem
problem
impossible
X
X
by
to
by
using
solve,
using
problem
problem
and
Y
as
know
aproblem
aalso
black-box
black-box
that
we
.can
IfIf we
we
solve
can
can
are
using
NP-hard
problems
for
illustration.
Recall
NP-hard
have
yet
to
be
in
1also
eady
know
that
MIN-VERTEX-COVER
NP-hard
problem.
Therefore,
we
can
show
eady
know
MIN-VERTEX-COVER
isiswe
aaproblem
NP-hard
problem.
Therefore,
we
can
show
that
MAX-INDEPENDENT-SET
is
also
a by
NP-hard
m
subset
of
such
that
for
every
edge,
at
one
of
its
endpoint
is
in
ato
NP-hard
problem.
Therefore,
we
can
that
MAX-INDEPENDENT-SET
ainto
EX-COVER
isnodes
a We
NP-hard
problem.
Therefore,
we
can
show
olve,
wethat
also
know
that
we
solve
problem
Xby
by
using
Y
as
aproblem.
black-box
.YYIf
we
can
solve
problem
Y,
then
we
can
solve
problem
Xshow
as
well.
Therefore,
problem
Ywe
isreducing
also
impossible
to
solve.
solve
problem
Y,
then
we
can
solve
X
as
well.
Therefore,
Y
is
also
impossible
to
solve
problem
Y,
then
we
can
solve
problem
X
asaproblem
well.
Therefore,
problem
isis
also
impossible
to proble
solve
X-INDEPENDENT-SET
is
also
acan
NP-hard
reducing
aNP-hard
MIN-VERTEX-COVER
problem
a solve.
lem.
Therefore,
we
can
show
that
that
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
is
is
also
also
a
NP-hard
problem
problem
by
by
reducing
a
a
MIN-VERTEX-COVE
MIN-VERTEX-COV
MIN-VERTEX-COVER
problem
into
a
also
aand
NP-hard
problem
by
reducing
a
MIN-VERTEX-COVER
problem
into
a
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
problem.
1
most
common
way
is
to
apply
a
well-known
technique
called
reduction.
Suppose
we
know
that
pro
EPENDENT-SET
is
also
a
NP-hard
problem
by
reducing
a
MIN-VERTEX-COVER
problem
into
a
MAX-INDEPENDENT-SET
problem.
that
MAX-INDEPENDENT-SET
is
also
a
NP-hard
problem
by
reducing
a
MIN-VERTEX-COVER
MAX-INDEPENDENT-SET
problem.
MAX-INDEPENDENT-SET
problem.
e
also
know
that
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
If
we
can
solve
problem
Y,
then
we
can
solve
problem
X
as
well.
Therefore,
problem
Y
is
also
imp
solve
solve
problem
problem
Y,
Y,
then
then
we
we
can
can
solve
solve
problem
problem
X
X
as
as
well.
well.
Therefore,
Therefore,
solve
problem
problem
problem
Y,
then
Y
Y
is
is
we
also
also
can
impossible
impossible
solve
problem
to
to
solve.
solve.
X
as
well.
T
time
for
more
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves
nding
a
minimum
T-SET
also
NP-hard
problem
byNP-hard
reducing
a MIN-VERTEX-COVER
MIN-VERTEX-COVER
problem
into
problem
reducing
a aMIN-VERTEX-COVER
problem
aaaMAX-INDET-SET
also
aaNP-hard
NP-hard
problem
reducing
problem
into
problem.
w
that
MIN-VERTEX-COVER
aby
problem.
Therefore,
show into
blem
byisis
reducing
a problem.
MIN-VERTEX-COVER
problem
into
a MAX-INDEPENDENT-SET
Y,
then
we
can
solve
problem
Xisby
as
well.
Therefore,
problem
Y iswe
alsocan
impossible
to solve.
DEPENDENT-SET
TEX-COVER
problem
into
asolve,
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
problem.
problem.
m.
impossible
tothat
and
weproblem
also know
weimpossible
canitssolve
problem
X the
by using
problem
Y as a black-box1 .
NDENT-SET
problem.
ability
of
a
Problem
through
Reduction
problem.
can
solve
problem
XMAX-INDEPENDENT-SET
as
well.
Therefore,
Yleast
isthat
also
to
solve.
of
nodes
such
for
every
edge,
at
one
of
endpoint
is
in
subset.
MAX-INDEPENDENTPENDENT-SET
problem.
T
problem.
T
problem.
also
a NP-hard
problem
by
reducing
a
MIN-VERTEX-COVER
problem
into
a
Wesolve
areWe
using
NP-hard
problems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in polynom
polynom
We
are
using
NP-hard
problems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in
are
using
NP-hard
problems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to be solved
in p
We
We
will
will
rst
rst
prove
prove
the
the
following
following
two
two
lemmas.
lemmas.
problem
Y,
then
we
can
solve
problem
Xthat
asfor
well.
Therefore,
problem
Y
isatbe
also
impossible
solve
We
will
rst
prove
following
lemmas.
We
will
rst
prove
the
following
two
lemmas.
Wetwo
will
rst
prove
the
following
two
lemmas.
Wethe
are
using
NP-hard
problems
illustration.
Recall
that
NP-hard
problems
have
yet
We
We
are
are
using
using
NP-hard
NP-hard
problems
problems
for
for
illustration.
illustration.
Recall
Recall
that
NP-hard
NP-hard
are
using
problems
problems
NP-hard
have
have
problems
yet
yet
to
to
be
for
solved
solved
illustration.
in
in
polynomial
polynomial
Recall
t
graph
problem
of
nding
aMIN-VERTEX-COVER
maximum
subset
of
nodes
such
that
for
every
edge,
most
one
of
itsto
endpo
We
will
first
prove
the
following
two
lemmas.
We
will
rst
prove
the
following
two
lemmas.
2
Identifying
Intractability
of
a
Problem
through
m.
2
Identifying
Intractability
of
a
Problem
through
Red
gill
NP-hard
problems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in
polynomial
time
for
more
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves
nding
a
minimum
sub
time
for
more
than
4
decades.
is
a
graph
problem
that
involves
nding
a
minimum
sub
time
for
more
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves
nding
a
minimu
rst
prove
the
following
two
lemmas.
We
We
will
will
rst
rst
prove
prove
the
the
following
following
two
two
lemmas.
lemmas.
two
lemmas.
that we
are
attempting
is unlikely
to
havethe
anfollowing
immediate
solution.
The Intractability of a Pro
prove
the
following
two
lemmas.
2
Identifying
We
will
rst
prove
two
lemmas.
roblems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in
polynomial
time
for
more
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves

time
time
for
more
more
than
than
4
4
decades.
decades.
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
is
time
a
a
graph
graph
for
problem
more
problem
than
that
that
4
decades.
involves
involves
nding
MIN-VERTEX-COVER
nding
a
a
minimum
minimum
subset
subset
is
the
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
is
a
NP-hard
problem.
Therefore,
we
c
for
Lemma
Lemma
1.
1.
If
If
S
S

V
V
is
is
an
an
INDEPENDENT-SET
INDEPENDENT-SET
of
of
graph
graph
G(V,
G(V,
E)
E)
2
Identifying
Intractability
of
a
Problem
through
Reduction
following
two
lemmas.
Problem
through
Reduction
following
lemmas.
than
4technique
decades.
MIN-VERTEX-COVER
isLemma
a we
graph
problem
that
involves
nding
a,the
minimum
subset
of two
nodes
such
that
for
every
edge,
at
least
one
ofSone
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
of
nodes
such
that
edge,
at
least
one
of
its
endpoint
is
the
subset.
MAX-INDEPENDENT-SET
of
nodes
such
that
every
edge,
at
least
of of
its
endpoint
isE),
in
subset.
MAX-INDEPENDENT
Lemma
1.
Ifusing
S
Vfor
anan
INDEPENDENT-SET
graph
G(V,
then
VV
Shave
Lemma
1.
If
is
is
an
INDEPENDENT-SET
then
is
isisaayet
Lemma
1.
Iffor
Severy

VisSuppose
INDEPENDENT-SET
ofgraph
graph
G(V,
E),
then
S
aVERTEX-COVE
VERTEX-COV
1.
Ifthat
problem
V
is
an
INDEPENDENT-SET
of
graph
G(V,
E),ofthen
nown
called
reduction.
know
X
isIfin
We
are
NP-hard
problems
for
illustration.
Recall
that
NP-hard
problems
to
be
inaas
Lemma
1.
S

V
is
an
INDEPENDENT-SET
gra
We
would
like
to
know
that
the
problem
that
we
are
attempting
is is
unlikely
to
have
imme
We
would
like
to
know
that
the
problem
that
we
are
attempting
is
unlikely
to
have
an
immediate
des.
is
a
graph
problem
involves
nding
a
minimum
subset
of
nodes
such
that
for
every
edge,
at
least
one
of
its
endpoint
in
the
subset.
MAX-IN
of
nodes
such
such
that
that
for
for
every
every
edge,
edge,
at
at
least
least
one
one
of
of
its
its
endpoint
endpoint
of
nodes
is
is
in
such
in
the
the
that
subset.
subset.
for
every
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
edge,
at
least
one
of
its
isisend
that
MAX-INDEPENDENT-SET
is
also
a
NP-hard
problem
by
reducing
a
MIN-VERTEX-COVER
proble
1.
IfVMIN-VERTEX-COVER
Snodes

V
is
an
INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
VERTEX-COVER
of
the
Lemma
Lemma
1.
1.
If
If
S
S

V
V
is
is
an
an
INDEPENDENT-SET
INDEPENDENT-SET
of
of
graph
graph
G(V,
G(V,
E),
E),
then
then
V
V

S
Sits
is
isendpoint
asolved
aan
VERTE
VERTE
Vof

S
is
a
VERTEX-COVER
of
the
ENDENT-SET
of
graph
G(V,
E),
then

S
is
a
VERTEX-COVER
of
the
graph
graph
G(V,
G(V,
E)
E)
two
lemmas.
1
that
for
every
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
is
a
is
an
INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
VERTEX-COVER
of
the
graph
problem
of
nding
a
maximum
subset
of
nodes
such
that
for
every
edge,
at
most
one
of
its
endpoint
graph
problem
of
nding
a
maximum
subset
of
nodes
such
that
for
every
edge,
at
most
one
of
iui
VERTEX-COVER
of
the
graph
graph
problem
of
nding
a
maximum
subset
of
nodes
such
that
for
every
edge,
at
most
one
of
its
endp
graph
G(V,
E)
Lemma
1.
If
S

V
is
an
INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
VERTEX
G(V,
E)
graph
G(V,
E)
ability
of
a
Problem
through
Reduction
.
at
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
If
we
can
We
would
like
to
know
that
the
problem
that
we
are
attempting
is
nsing
of
graph
G(V,
E),
then
Vare

Sthe
issuch
VERTEX-COVER
of
the
time
fornding
more
than
4E)
decades.
MIN-VERTEX-COVER
is
aevery
graph
problem
that
involves
nding
aat
minim
ngraph
INDEPENDENT-SET
of
G(V,
E),
then

S
is
aagraph
VERTEX-COVER
of
the
G(V,
E)
G(V,
E),
then
V

Sgraph
away
VERTEX-COVER
ofaMAX-INDEPENDENT-SET
We
like
to
know
that
problem
that
we
attempting
is
unlikely
to
have
immediate
solution.
The
iswould
unlikely
to
have
an
immediate
The
most
common
way
is
to
apply
amaximum
well-known
technique
called
reduction.
Suppose
we
most
common
issolution.
to
apply
aV
well-known
technique
called
Suppose
we
know
that
ry
edge,
at
one
of
its
endpoint
in
the
subset.
is
amost
graph
problem
of
nding
subset
of
such
that
for
every
edge,
most
graph
graph
problem
problem
of
of
nding
ais
athe
maximum
maximum
subset
subset
of
of
nodes
nodes
such
graph
that
that
problem
for
for
every
ofaanodes
edge,
nding
edge,
at
atendpoint
aan
most
maximum
one
one
ofsubset
its
its
endpoint
endpoint
of
nodes
isknow
is in
su
in
MAX-INDEPENDENT-SET
problem.
V,
E)
aINDEPENDENT-SET
VERTEX-COVER
of
the
graph
graph
G(V,
G(V,
E)
of
nding
aleast
maximum
subset
of
nodes
such
that
for
every
edge,
at
most
one
ofaisreduction.
its
is of
in
thewell.
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
is
NP-hard
problem.
Therefore,
we
can
sh
the
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
is
NP-hard
problem.
Therefore,
we
can
sh
the
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
a
NP-hard
problem.
Therefore,
we
graph
G(V,
E)
ing
Intractability
of
a
Problem
through
Reduction
em
X
as
Therefore,
problem
Y
is
also
impossible
to
solve.
most
common
way
is
to
apply
well-known
technique
called
reduc
Proof.
Proof.
Let
us
us
assume
assume
that
that
VSuppose
Vis

in
SSXthe
is
is
not
not
aaby
VERTEX-COVER.
VERTEX-COVER.
Ther
Ther
of
nodes
such
that
for
every
edge,
at
least
one
of
itsthat
endpoint
subset.
MAX-INDEPENDENT
of
graph
G(V,
E),
then
Vthat

SMIN-VERTEX-COVER
is
anot
VERTEX-COVER
of
the
Proof.
Let
us
assume
that
is
aaat
VERTEX-COVER.
Therefore,
there
are
two
common
way
is
to
apply
athat
well-known
called
reduction.
we
know
that
problem
XA,
is
dmost
reduction.
Suppose
we
know
problem
Xis
isnot
impossible
to
solve,
and
we
also
know
that
we
can
solve
problem
X
using
problem
Y
as
aBb
impossible
to
solve,
and
we
also
know
that
we
can
solve
using
problem
Y
as
acan
black-bo
aENDENT-SET
maximum
subset
of
nodes
such
that
for
every
edge,
most
one
of
endpoint
is
in
the
subset.
we
already
know
MIN-VERTEX-COVER
is
atwo
NP-hard
problem.
the
thewe
subset.
subset.
Suppose
Suppose
we
we
already
already
know
know
that
MIN-VERTEX-COVER
the
subset.
is
Suppose
a
aproblem
NP-hard
NP-hard
we
problem.
problem.
already
know
Therefore,
that
MIN-VERTEX
we
we
can
show
show
Proof.
Let
us
that
VSuppose

S
VERTEX-COVER.
Therefore,
there
are
B
/
Proof.
Let
us
assume
that
V

Stechnique
is
not
aLet
VERTEX-COVER.
there
are
two
vertices
A,
Let
us
assume
that
Visits
STherefore,
isTherefore,
not
aby
VERTEX-COVER.
Therefore,
that
are
attempting
isassume
unlikely
to
have
an
solution.
The
ppose
we
already
know
that
MIN-VERTEX-COVER
is
NP-hard
problem.
can
show
that
MAX-INDEPENDENT-SET
isProof.
also
aand
NP-hard
problem
by
reducing
MIN-VERTEX-COVER
problem
int
Proof.
Let
us
assume
that
VMIN-VERTEX-COVER

STherefore,
is
not
a1vertices
VERTEX-CO
that
MAX-INDEPENDENT-SET
is
also
NP-hard
problem
by
reducing
aaknow
MIN-VERTEX-COVER
problem
int
that
MAX-INDEPENDENT-SET
isaimmediate
also
aSaS
NP-hard
problem
by
reducing
awe
probl
impossible
to
solve,
and
we
also
that
we
can
solve
problem
Xend
by
1
et
us
assume
that
V

S
is
not
a
VERTEX-COVER.
Therefore,
there
are
two
vertices
A,
B

/
V

S
Proof.
Proof.
Let
Let
us
us
assume
assume
that
that
V
V

is
is
not
not
a
a
VERTEX-COVER.
VERTEX-COVER.
Therefore,
Therefore,
there
there
are
are
two
two
vertic
vertic
there
are
two
vertices
A,
B

/
V

S
is
not
a
VERTEX-COVER.
Therefore,
there
are
two
vertices
A,
B

/
V

S
and
there
there
is
is
an
an
edge
edge
connecting
connecting
A
A
and
and
B.
B.
Since
Since
A,
A,
B
B

/
V
V

S,
S,
we
we
graph
problem
of
nding
a
maximum
subset
of
nodes
such
that
for
every
edge,
at
most
one
of
its
vertices

and
there
is
an
edge
connecting

and
.
Since
impossible
to
solve,
and
we
also
know
that
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
If
we
can
m
X
by
using
problem
Y
as
a
black-box
.
If
we
can
solve
problem
Y,
then
we
can
solve
problem
X
as
well.
Therefore,
problem
Y
is
also
impossib
ssume
that
V

S
is
not
a
VERTEX-COVER.
Therefore,
there
are
two
vertices
A,
B

/
V

S
solve
problem
Y,
then
we
can
solve
problem
X
as
well.
Therefore,
problem
Y
is
also
impossible
to
so
ready
know
that
MIN-VERTEX-COVER
is
a
NP-hard
problem.
Therefore,
we
can
show
that
MAX-INDEPENDENT-SET
is
also
a
NP-hard
problem
by
reducing
a
MIN-VERTEX
that
that
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
is
is
also
also
a
a
NP-hard
NP-hard
problem
problem
that
by
by
MAX-INDEPENDENT-SET
reducing
reducing
a
a
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
also
a
problem
problem
NP-hard
into
into
proble
a
a
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

/
V

S,
we
have
A,
B

S.
As
A
and
B
are
co
We
will
rst
prove
the
following
two
lemmas.
Proof.
Let
us
assume
that
V

S
is
not
a
VERTEX-COVER.
Therefore,
there
are
two
vertice
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

/
V

S,
we
have
A,
B

S.
As
A
and
B
are
c
and
is
an
edge
connecting
A
and
B.
A,A
Band

/a VB.Since
S, weA,
have
ow
that
the
problem
that
we
are
attempting
isB
unlikely
to
have
an
immediate
solution.
The
nown
technique
called
reduction.
Suppose
wethere
know
that
problem
XBis
isA,
DEPENDENT-SET
is
also
athere
NP-hard
problem
by
reducing
atwo
MIN-VERTEX-COVER
problem
into

is
not
VERTEX-COVER.
Therefore,
there
are
two
vertices
A,
B
/is

SSince
VV

SSMAX-INDEPENDENT-SET
is
not
aathat
VERTEX-COVER.
Therefore,
there
are
A,
B
//
VVA

S
MAX-INDEPENDENT-SET
problem.
and
there
anS.
edge
connecting
B

/A
problem.
Therefore,
there
are
two
vertices
A,

/be
V

S
MAX-INDEPENDENT-SET
problem.
stration.
Recall
NP-hard
problems
have
yet
solved
in
polynomial
solve
problem
Y,vertices
then
we
can
solve
problem
X
as
well.
Therefore,
pro
etCOVER.
isBMAX-INDEPENDENT-SET
an
edge
connecting
A
and
B.
Since
A,
B

/to

S,
we
have
A,

As
B
are
connected
two
vertices
A,
B
/and
Vimpossible

S
and
there
isproblem.
isto
an
an
edge
edge
connecting
connecting
A
A
and
and
B.
B.
Since
Since
A,
B
B

Vby
V

S,
S,
we
we
have
have
A,
A,
B
B Therefore
S.
S. As
As A
AThis
and
and
A,
B.
S.
As
A
and
B
are
connected
and
Since
A,
B

/and
Vwe

S,
we
have
A,
B

S.
As
A
B
are
connected
by
by
an
an
edge,
edge,
we
we
note
note
that
that
S
S
not
not
an
an
INDEPENDENT-SET.
INDEPENDENT-SET.
Thi
,note
we
have
.V
As
and
and
Since
are
connected
an
edge,
we
note
the
subset.
Suppose
we
already
that
MIN-VERTEX-COVER
isinto
aand
NP-hard
problem.
Therefore,
we
solve
problem
Y,
then
can
solve
problem
Xknow
as
well.
Therefore,
problem
Y
isis
also
impossible
to
solve.
ore,
problem
Y
isNP-hard
also
solve.
edge
connecting
A
B.
Since
A,
B

/
V

S,
we
have
A,

S.
As
A
and
B
are
connected
T-SET
is
also
a
problem
by
reducing
a
MIN-VERTEX-COVER
problem
a
MAX-INDEPENDENT-SET
problem.
MAX-INDEPENDENT-SET
problem.
MAX-INDEPENDENT-SET
problem.
1 B that
by
an
edge,
we
that
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction.
V

there
is
an
edge
connecting
A
and
B.
A,
B

/
V

S,
we
have
A,
B

S.
As
A
and
B
by
an
edge,
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction.
Therefore
V
by
an
edge,
we
note
S
is
not
an
INDEPENDENT-SET.
This
is
a
c
is
to
apply
a
well-known
technique
called
reduction.
Suppose
we
know
that
problem
X
is
at
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
If
we
can
NDENT-SET
problem.
ecting
Aand
and
B.
Since
A,
B
/This
VVINDEPENDENT-SET.

S,
we
have
A,
B

S.
As
A
and
BVSare
are
connected
tifying
Intractability
of
aare
Problem
Reduction
ecting
and
B.
A,

/
V

we
A,
B
S.
As
A
and
B
byaisINDEPENDENT-SET.
an
edge,
we
note
that
SVMIN-VERTEX-COVER
isisisnot
an
INDEPENDENT
stge,
not
aA
VERTEX-COVER.
Therefore,
there
two
vertices
A,
B

/
is
Sconnected

/As
Vwe
S,
we
have
VB
S.
As
A
and
Bhave
are
connected
TEX-COVER
is
aSince
graph
problem
that
nding
aanot
minimum
subset
Lemma
If
SWe

is
INDEPENDENT-SET
of
graph
G(V,
E),
then
is
aa VERTEX-COVE
note
that
SA,
is
not
an
This
athrough
contradiction.
Therefore
VSis
S
isyethave
a to be
A
B
are
connected
by
byB
an
an
edge,
edge,
we
we
note
note
that
that
S
S
isis
not
an
an
INDEPENDENT-SET.
This
This
aa
contradiction.
contradiction.
Ther
The
that
1.
is
not
an
INDEPENDENT-SET.
This
is
contradiction.
Therefore
is
contradiction.
Therefore

S
is
aan
an
INDEPENDENT-SET.
isS,
ainvolves
contradiction.
Therefore
V
areducing
VERTEX-COVER.
VERTEX-COVER.
that
MAX-INDEPENDENT-SET
is
also
NP-hard
problem
by
aproblems
prob
are
using
NP-hard
problems
for
illustration.
Recall
that
NP-hard
problems
yet
to
be
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction.
Therefore
V

S
a
We
are
using
NP-hard
problems
for
illustration.
Recall
that
NP-hard
have
solved
T
problem.
1 This
VERTEX-COVER.
by
an
edge,
we
note
that
S
is
not
an
INDEPENDENT-SET.
is
a
contradiction.
There
VERTEX-COVER.
VERTEX-COVER.
we
also
know
can
solve
problem
using
problem
Y connected
asisaablack-box
.is
we can
em
X
as
well.
Therefore,
problem
Ythe
isThis
also
impossible
is
not
an
INDEPENDENT-SET.
This
is
contradiction.
Therefore
SS for
isIfaaillustration.
SS one
is
an
INDEPENDENT-SET.
is
contradiction.
Therefore
VV
We
will
rst
prove
the
following
two
lemmas.
VERTEX-COVER.
and
B.not
Since
A,
Bathat

/contradiction.
VSiswe

S,
we
have
A,
Bproblem.
XaaS.
As
and
B are
We
will
rst
prove
the
following
two
lemmas.
NT-SET.
This
isWe
Therefore
Vby

SA
isto
asolve.
will
rst
prove
following
two
lemmas.
st
of
its
endpoint
in
subset.
MAX-INDEPENDENT-SET
We
are
using
NP-hard
problems
Recall
that NP-hard
VERTEX-COVER.
graph
G(V,
E)
-COVER.
tion.
Therefore
V

is
athe
VERTEX-COVER.
VERTEX-COVER.
MAX-INDEPENDENT-SET
Wecan
are
using
NP-hard
problems
illustration.
Recall
that
NP-hard
problems
have
yet
to
be solved
in involves
polynomial
NP-hard
problems
have
yet
to
be
solved
in
polynomial
time
for
more
than
4lemmas.
decades.
MIN-VERTEX-COVER
issolve.
a problem
graph
problem
that
ndin
ER.
time
for
more
than
4are
decades.
MIN-VERTEX-COVER
is
aimmediate
graph
that
involves
nding
min
We
will
rst
prove
the
following
two
lemmas.
We
We
will
will
rst
rst
prove
prove
the
the
following
following
two
two
lemmas.
We
will
rst
prove
the
following
two
lemmas.
VERTEX-COVER.
to
know
that
the
problem
that
weisfor
attempting
is unlikely
to
have
an
solution.
en
we
solve
problem
X
as
well.
Therefore,
problem
Y
is
also
impossible
to
Lemma
Lemma
2.
2.
If
If
S
S

V
V
is
is
a
a
VERTEX-COVER
VERTEX-COVER
of
ofThe
graph
graph
G(V,
G(V,
E),
E),a prob
then
the
t
prove
the
following
two
lemmas.
an
INDEPENDENT-SET.
This
a
contradiction.
Therefore
V

S
is
a
bset
of
nodes
such
that
for
every
edge,
at
most
one
of
its
endpoint
is
in
time
for
more
than
4
decades.
MIN-VERTEX-COVER
is
a graph
Lemma
2.
If
S

V
is
a
VERTEX-COVER
of
graph
G(V,
E),
then
V

S
is
an
INDEPENDENT-SE
Lemma
2.
If
S

V
is
a
VERTEX-COVER
of
graph
G(V,
E),
then
V

S
is
an
INDEPENDENT-S
Lemma
2.
If
S

V
is
a
VERTEX-COVER
of
graph
G(V,
E),
then
V of

time
for
more
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves
nding
a
minimum
subset
ph
problem
that
involves
nding
a
minimum
subset
of
nodes
such
that
for
every
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEP
Lemma
1.
If
S

V
is
an
INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
VERTEX-COVER
of
Lemma
2.
If
S

V
is
a
VERTEX-COVER
of
graph
G
of
nodes
such
that
for
every
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDE
following
two
lemmas.
Lemma
1.
If
S

V
is
an
INDEPENDENT-SET
of
G(V,
E),
then
V

S
is
a
VERTEX-COVER
Lemma
2.
If

is
a
VERTEX-COVER
graph
,
then

an
INLemma
1.
If
S

V
is
an
INDEPENDENT-SET
graph
G(V,
E),
then
V

S
is
a
VERTEX-COV
nX-COVER
way
to
apply
aLet
well-known
technique
called
reduction.
Suppose
we
know
that
problem
X SS
isofisisthe
Proof.
usE),
assume
that
VS
is
not
aG(V,
VERTEX-COVER.
Therefore,
there
two
vertices
A,
B
2.
IfVan
Sis

V
is
a SS
VERTEX-COVER
graph
E),
then
Vthat

Sof
is
an
INDEPENDENT-SET
Lemma
Lemma
2.
2.
IfIfthe
SSof

VV
is
isS
aaG(V,
VERTEX-COVER
VERTEX-COVER
of
graph
graph
G(V,
G(V,
E),
E),
then
then
VVare

an
anVINDEPEND
INDEPEND
stration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in
polynomial
S
isLemma
INDEPENDENT-SET
of
of
graph
G(V,
then
V

is
an
INDEPENDENT-SET
of
the
graph
graph
G(V,
E)
E)
at
MIN-VERTEX-COVER
a
NP-hard
problem.
Therefore,
we
can
show
of
nodes
such
for
every
edge,
at
least
one
of
its
endpoint
is
in
t

is
a
VERTEX-COVER
of
graph
G(V,
E),
then
V

S
is
an
INDEPENDENT-SET
of
the
Lemma
1.
If
S

V
is
an
INDEPENDENT-SET
of
graph
G(V,
E),
then

S
is
a
Lemma
1.
1.
Lemma
1.
If
If

V
V
is
is
an
an
INDEPENDENT-SET
INDEPENDENT-SET
of
of
graph
graph
G(V,
G(V,
E),
E),
If
then
then
S

V
V

is
S
S
an
is
is
INDEPENDENT-SET
a
a
VERTEX-COVER
VERTEX-COVER
of
of
of
the
the
gra
graph
G(V,
E)
Lemma
2.
If
S

V
is
a
VERTEX-COVER
of
graph
G(V,
E),
then
V

S
is
an
INDEPENDE
graph
G(V,
E)
V
graph
G(V,
E)
We
will
rst
prove
the
following
two
lemmas.
1
of
nodes
such
that
for
every
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
is
a
t-hard
is
in
the
subset.
MAX-INDEPENDENT-SET
is
a
S

V
is
an
INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
VERTEX-COVER
of
the
graph
problem
of
nding
a
maximum
subset
of
nodes
such
that
for
every
edge,
at
most
one
VERTEX-COVER
of
graph
G(V,
E),
then
V

S
is
an
INDEPENDENT-SET
of
the
VERTEX-COVER
of
graph
G(V,
E),
then
Vmaximum

Sproblems
isB.
an
INDEPENDENT-SET
ofhave
the
graph
G(V,
E)
DEPENDENT-SET
of
the
graph
graph
G(V,
E)
graph
problem
of
nding
aproblem
of
nodes
for
every
at
most
oneBofare
itscoeV
graph
G(V,
E)
G(V,
E),
then
Vathere

S
isthat
anG(V,
INDEPENDENT-SET
ofby
the
graph
G(V,
E)
.subset
solve,
and
we
also
know
we
can
solve
X
using
problem
Ysuch
as
athat
black-box
.B
Ifedge,
weS.can
and
is
an
edge
connecting
A
and
Since
A,
B

/
V

S,
we
A,

As
A
and
V,
E)
problems
for
illustration.
Recall
that
NP-hard
have
yet
to
be
solved
in
polynomial
NDEPENDENT-SET
of
the
graph
graph
G(V,
E)
E)
TEX-COVER
is
graph
problem
that
involves
nding
a
minimum
subset
a
NP-hard
problem
by
reducing
a
MIN-VERTEX-COVER
problem
into
a
graph
of is
nding
maximum
subset
nodes
such
that
for
e
ngraph
INDEPENDENT-SET
ofaG(V,
graph
G(V,
E),
then
V problem
SThe
is proof
agraph
VERTEX-COVER
of
the
graph
E)
graph
graph
G(V,
G(V,
E)
E)
G(V,
E)athe
graph
E)its
problem
of
nding
maximum
subset
ofis
nodes
such
that
for
every
edge,
atto
one
endpoint
is
for
every
edge,
at
most
one
endpoint
in
Proof.
Proof.
The
proof
is
actually
actually
similar
similar
to
to
the
the
previous
previous
lemma.
lemma.
Let
Let
us
usinassu
assu
the
subset.
we
already
know
that
MIN-VERTEX-COVER
is
aof
NP-hard
problem.
The
the
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
ismost
athat
NP-hard
problem.
Therefore,
X-COVER
ofMIN-VERTEX-COVER
graph
G(V,
E),
then
VSuppose
S
is
an
INDEPENDENT-SET
Y,decades.
then
can
solve
problem
X
as
well.
Therefore,
problem
Y
isof
also
impossible
solve.
Proof.
The
is
actually
similar
to
the
previous
lemma.
Let
us
assume
that
V
Sof
not
aVERTEX-COV
INDEPENDE
by
an
edge,
we
note
S
is
not
an
INDEPENDENT-SET.
This
is
athat
contradiction.
Therefore
V

4at
is
graph
problem
that
involves
nding
aus
minimum
subset
Proof.
The
proof
isof
actually
similar
to
the
previous
lemma.
Let
assume
Sisits
is
not
avertices
INDEPEND
st
one
ofwe
its
endpoint
is
in
subset.
MAX-INDEPENDENT-SET
issimilar
aof
Proof.
The
proof
isSuppose
actually
to
the
previous
lemma.
Let
us
assume
tha
Lemma
1.proof
If the
S

Vthat
isa
an
INDEPENDENT-SET
graph
G(V,
E),
then
VV

is
aprevious
Proof.
The
proof
is
actually
similar
to
the
previous
lemma.
Let
us
assume
is
the
subset.
we
already
know
that
MIN-VERTEX-COVER
is
Proof.
Let
us
assume
that
V

S
is
not
a
VERTEX-COVER.
Therefore,
there
are
two
vertices
A,
B

/
V

Proof.
The
proof
is
actually
similar
to
the
lemma.
Proof.
Let
us
assume
that
V

S
is
not
a
VERTEX-COVER.
Therefore,
there
are
two
vertices
A,
B

/
V

Proof.
Let
us
assume
that
V

S
is
not
a
VERTEX-COVER.
Therefore,
there
are
two
A,
B
proof
actually
similar
to
the
previous
lemma.
Let
usa assume
that
V

S
isproblem
not
aA,
INDEPENDENT-SET.
Proof.
Proof.
The
The
proof
proof
is
isus
actually
actually
similar
similar
to
to
the
the
previous
previous
lemma.
lemma.
Let
Let
us
us
assume
assume
that
V
V

SSthere
isisis
not
not
aa
IND
IND
the
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
isTherefore,
alemma.
NP-hard
problem.
we
can
show
VER
isSprevious
aisis
NP-hard
problem.
Therefore,
we
can
show
the
Visthe

not
aus
INDEPENDENT-SET.
to
lemma.
Let
us
assume
that
VLet
aA,
SA,
isassume
INDEPENDENT-SET.
Therefore,
Therefore,
there
there
are
two
two
vertices
vertices
A,
B
B
reducing
Vtwo
VaVisTherefore,

Sthat
SA
and
there
there
is
an
an
edge
edge
that
MAX-INDEPENDENT-SET
also
aare
NP-hard
by
aand
MIN-VERTEX-CO
that
MAX-INDEPENDENT-SET
isnot
also
aisthe
NP-hard
problem
by
reducing
MIN-VERTEX-COVER
pr
of
actually
similar
to
the
previous
lemma.
us
that
V

S
is
not
a
INDEPENDENT-SET.
Proof.
Let
assume
that
V

S
is
not
a
VERTEX-COVER.
Therefore,
are
two
Proof.
Proof.
Proof.
Let
Let
us
assume
assume
that
that
V
V

S
S
is
is
not
not
a
VERTEX-COVER.
VERTEX-COVER.
Therefore,
Let
us
assume
there
there
that
are
are
two

S
vertices
vertices
is
not
A,
A,
a
VERTEX-CO
B
B

/
V
V

S
S
Therefore,
there
are
two
vertices
B

S
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B
VERTEX-COVER.
for
every
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
a
Proof.
The
proof
is
actually
similar
to
previous
Let
us
assume
that
V

S
is
not
a
INDE
Therefore,
there
are
two
vertices
B

S
and
there
is
an
edge
connecting
and
B.
Since
A,
B
bset
of
nodes
such
that
for
every
edge,
at
most
one
of
its
endpoint
is
in
Therefore,
there
are
vertices
A,
B

S
and
there
is
an
edge
conne
not
a
INDEPENDENT-SET.
Therefore,
there
two
vertices

and
graph
G(V,
E)
that
Vprevious

San
is
not
aconnecting
VERTEX-COVER.
Therefore,
there
are
two
vertices
A,
B

/NP-hard
VB
ysassume
similar
to
the
previous
lemma.
Let
us
assume
that
B.
SA,
is
not
aA,
INDEPENDENT-SET.
that
MAX-INDEPENDENT-SET
isA,
also
aS.
problem
by
reduc
yye,
similar
to
lemma.
Let
assume
that
VV

S
is
not
INDEPENDENT-SET.
and
there
is
an
edge
connecting
Aatwo
and
B.
Since
A,
B
V

S,
we
have
A,
B
A,
S.
As
ASVan
and
Band
are
connec
Therefore,
there
are
two
vertices
A,
B

Vedge,

S
and
ther
and
there
is
A
and
B.
Since
A,
B

/a/V
V
we
have
B

As
A
and
B
are
connec
ma.
Let
us
assume
that
Vedge

SB
is
not
aus
INDEPENDENT-SET.
and
there
is
an
edge
A
and
Since
B

/S,
V

S,
we
have
B

S.
As
A
B
are
c
there
are
two
vertices
A,

Vthere

STherefore,
and
there
an
edge
connecting
A
and
B.
Since
A,

S,
not
aMAX-INDEPENDENT-SET
INDEPENDENT-SET.
Therefore,
Therefore,
there
are
are
two
vertices
vertices
A,
B
B
V

S
S
and
and
there
there
is
is
an
an
edge
edge
connecting
connecting
A
A
and
and
B.
B.
Sin
Sin
isconnecting
also
NP-hard
problem
by
reducing
aand
MIN-VERTEX-COVER
problem
into
aB
reducing
athe
MIN-VERTEX-COVER
problem
into
ais
A
and
B.
Since
A,

Vthere

S,
,that
B

VS

S
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

S,
we
we
have
have
A,
A,
B
B

/
/
S.
S.
As
As
A
AA,
and
B
B
are
are
connected
connected
by
by
an
edge,
we
we
note
note
MAX-INDEPENDENT-SET
problem.
MAX-INDEPENDENT-SET
problem.
ng
NP-hard
problems
for
illustration.
Recall
that
NP-hard
problems
have
yet
to
be
solved
in
polynomial
eat
are
vertices
A,
B

VB

S
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

V
we
S,
tcting
VMIN-VERTEX-COVER
two
is
not
aan
VERTEX-COVER.
there
are
two
vertices
B

/A,
V

S
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

/S,
V

S,
have
A,
B

S.
As
and
and
there
there
is
is
an
edge
edge
connecting
connecting
A
A
and
and
B.
B.
Since
Since
A,
A,
B
B

/
and
V

there
S,
S,
we
we
is
have
an
have
edge
A,
B
B
connecting

S.
S.
As
As
A
A
A
and
and
and
B
B
B.
are
are
Since
connected
connected
A,

/
we
have
A,
B

/
S.
As
A
and
B
are
connected
by
an
edge,
we
note
that
S
is
not
a
VERTEX-COVER.
T
nding
a
maximum
subset
of
nodes
such
that
for
every
edge,
at
most
one
of
its
endpoint
is
in
Therefore,
are
two
vertices
S
there
is
an
edge
connecting
A
and
B.
Sinc
we
have
A,
B

/
S.
As
B
are
connected
by
an
edge,
we
note
that
S
is
not
a
VERTEX-COVER.
is
edge
connecting

and
.
Since
,
have
.
As

and
is
a
NP-hard
problem.
Therefore,
we
can
show
we
have
A,
B

/
S.
As
A
and
B
are
connected
by
an
edge,
we
note
that
S
n
edge
connecting
A
and
B.
Since
A,
B

/
V

S,
we
have
A,
B

S.
As
A
and
B
are
connected
ertices
A,
B

S
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

S,
emmas.
MAX-INDEPENDENT-SET
problem.
ertices
A,
B

S
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

by
an
edge,
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction.
Therefore
V

S
we
have
A,
B

/
S.
As
A
and
B
are
connected
by
an
edg
o
the
previous
lemma.
Let
us
assume
that
V

S
is
not
a
INDEPENDENT-SET.
by
an
edge,
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction.
Therefore
V

S
here
is
an
edge
connecting
Aconnected
and
B.
A,
B

Vnot

S,of
by
an
edge,
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
isnote
aINDEPENDENT-SET.
Therefore
VBi
Lemma
2.
If
S

Vby
isedge,
aSince
VERTEX-COVER
graph
G(V,
E),
then
V

Scontradiction.
is
an
INDEPENDENT-SE
B

/
S.
As
A
and
B
are
by
an
edge,
we
note
that
S
is
not
a
VERTEX-COVER.
This
is
a
and
B.
Since
A,
B

S,
we
we
have
have
A,
A,
B
B

/
S.
S.
As
As
A
A
and
and
B
B
are
are
connected
connected
by
by
an
an
edge,
edge,
we
we
note
that
that
S
S
is
is
not
not
a
a
VERTEX-C
VERTEXMAX-INDEPENDENT-SET
problem.
is
not
a
VERTEX-COVER.
This
is
a
eA,
connected
by
an
edge,
we
note
that
S
is
not
a
VERTEX-COVER.
This
is
a
contradiction.
contradiction.
Therefore
Therefore
V
V

S
S
is
is
an
an
INDEPENDENT-SET.
Proof.
Let
us
assume
that
V

S
is
a
VERTEX-COVER.
Therefore,
there
are
two
vertices
A,
than
4
decades.
MIN-VERTEX-COVER
is
a
graph
problem
that
involves
nding
a
minimum
subset
S.
As
A
and
B
are
connected
an
edge,
we
note
that
S
is
not
a
VERTEX-COVER.
This
is
a
ecting
A
and
B.
Since
A,
B

/
V

S,
we
have
A,
B

S.
As
A
and
B
are
connected
by
an
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction
by
by
an
an
edge,
edge,
we
we
note
note
that
that
by
edge,
note
that
SS
is
not
an
an
INDEPENDENT-SET.
INDEPENDENT-SET.
This
This
isisedge,
aan
aTherefore
contradiction.
contradiction.
Sshow
isisis
not
Therefore
INDEPENDENT
V
SS isis aa
is
are
connected
by
an
edge,
we
note
that
problem
iscontradiction.
notanaBVERTEX-COVER.
aTherefore
concontradiction.
Therefore
V
Sthat
isand
an
INDEPENDENT-SET.
we
already
know
that
MIN-VERTEX-COVER
isSSan
ais
NP-hard
problem.
we
can
we
have
A,VERTEX-COVER.
B

/not
S.
As
A
areisisaTherefore
connected
by
an
we
that
S
isan
not
a VVERTEX-C
contradiction.
V

S
is
INDEPENDENT-SET.
and
NP-hard
problem
aiswe
MIN-VERTEX-COVER
into
aSwe
contradiction.
V
Therefore,
INDEPENDENT-SET.
eVERTEX-COVER.
note
that
S
not
an
INDEPENDENT-SET.
This
aVERTEX-COVER.
contradiction.
V

S
is
aINDEPENDENT-SE
and
B
are
connected
by
an
we
note
that
isB
not
aan
This
isnote
B
are
connected
by
an
edge,
note
not
VERTEX-COVER.
This
is
VERTEX-COVER.
Therefore
VaaThis

S
an
B

V
note
S
and
is
an
edge
connecting
A
and
B.
Since
S,
VERTEX-COVER.
edge,
we
that
Sby
isreducing
not
aTherefore
This
alemmas.
VERTEX-COVER.
graph
G(V,
E)
tion.
Therefore
Visthere

S
is
an
INDEPENDENT-SET.
This
is
aedge,
contradiction.
contradiction.
Therefore
Therefore
V
VA

SS
isis
an
INDEPENDENT-SET.
INDEPENDENT-SET.
an
INDEPENDENT-SET.
We
will
rst
prove
the
following
twoA,A,
lemmas.
and
there
is
an
edge
connecting
and
B.
Since
Bthe

/VV
S,
we
have
A,
B

We
will
rst
prove
the
following
two
that
for
every
edge,
at
least
one
of
its
endpoint
is
in
the
subset.
MAX-INDEPENDENT-SET
isS.a As A and B are
ENT-SET
of
graph
G(V,
E),
then
V

S
is
a
VERTEX-COVER
of
Therefore
V

S
an
INDEPENDENT-SET.
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction.
Therefore
V

S
is
a
tradiction.
Therefore

is
an
INDEPENDENT-SET.
VERTEX-COVER.
VERTEX-COVER.
VERTEX-COVER.
VERTEX-COVER.
NDENT-SET
is
also
a
NP-hard
problem
by
reducing
a
MIN-VERTEX-COVER
problem
into
a
contradiction.
Therefore
V

S
is
an
INDEPENDENT-SET.
Theorem
1.
1.
IfIf SS

ofVThis
V
isis
aaisfollowing
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
of
of
graph
graph G(V
G(V
ER.
SSWe
an INDEPENDENT-SET.
INDEPENDENT-SET.
We
rst
prove
the
two
lemmas.

isis an
connected
by
edge,
we
note
is
aTheorem
VERTEX-COVER.
a G(V,
-SET.
Theorem
1.
IfVVfollowing
S
note
Vthat
isthat
graph
E),
then
VV
Sof
isgraph
Theorem
1.
If
S

Vnodes
isaaSaMAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
of
graph
then
S
isa aMIN-VERTEX
MIN-VERTE
will
rst
prove
the
two
lemmas.
Theorem
1.of
Ifwill
S of

V
is at
aE),
MAX-INDEPENDENT-SET
G(V, E),of
t
byan
an
edge,
we
Snot
is that
not
an
INDEPENDENT-SET.
This
isis
aMAX-INDEPENDENT-SET
contradiction.
Therefore
m
of nding
aV
maximum
subset
of
such
for
every
edge,
most
one
of
its
endpoint
is
in
Lemma
2.
S2.

is
a1.
VERTEX-COVER
of
graph
G(V,
E),
then
V
MIN-VERTEX-COVER
S
an
INDEPENDENT-SET
ofoV
Theorem
1.
Ifus
SG(V,

V
isE),
ais
Lemma
2.
IfIf
S

is
a1.
VERTEX-COVER
graph
G(V,
then
V

S
an
INDEPENDENT-SET
Lemma
If
SIf
S
V
is
VERTEX-COVER
graph
G(V,
E),
then
V

S
is
an
INDEPENDENT-SE
NT-SET
problem.
Proof.
The
proof
is
actually
similar
to
the
previous
lemma.
Let
assume
that
V

S
is
not
a
INDEPENDE
m
If
S

is
a
MAX-INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
Theorem
Theorem
If
If
S
S

V
V
is
is
a
a
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
of
of
graph
graph
G(V,
G(V,
E),
E),
then
then
V
V

S
S
is
is
a
MINMIN
hen
V

S
is
a
MIN-VERTEX-COVER
NDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
MIN-VERTEX-COVER
of
of
the
the
graph
graph
G(V,
G(V,
E).
E).
Lemma
1.
If
S

V
is
an
INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
VERT
Theorem
1.

is
a
MAX-INDEPENDENT-SET
of
graph
,
then
Lemma
1.
If
V
is
an
INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
VERTEX-C
nS 1.
INDEPENDENT-SET.

V
is
a
MAX-INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
MIN-VERTEX-COVER
Lemma
2.
If
S

V
is
a
VERTEX-COVER
of
graph
G(V,
E),
then
V

an
INDE
Lemma
Lemma
2.
2.
Lemma
2.
If
If
S
S

V
V
is
is
a
a
VERTEX-COVER
VERTEX-COVER
of
of
graph
graph
G(V,
G(V,
E),
E),
then
then
If
V
V
S

S
S
V
is
is
is
an
an
a
VERTEX-COVER
INDEPENDENT-SET
INDEPENDENT-SET
of
graph
of
of
the
the
G
of
the
graph
G(V,
E).
Theorem
1.
If
S

V
is
a
MAX-INDEPENDENT-SET
of
graph
G(V,
E),
then
S
is
a
MIN-V
of
the
graph
G(V,
E).
of
the
graph
G(V,
E).
VERTEX-COVER.
uppose
we
that
MIN-VERTEX-COVER
isVgraph
a
NP-hard
problem.
Therefore,
canofAshow
SLemma
graph
VMIN-VERTEX-COVER
isthen
aalready
VERTEX-COVER
of
graph
G(V,
E),
then
V1.
S
is
the
MAX-INDEPENDENT-SET
of
graph
G(V,
E),
then
MIN-VERTEX-COVER
Lemma
Ifand
an
V .INDEPENDENT-SET
isis
an
graph
E)
MAX-INDEPENDENT-SET
of
graph
G(V,
E),
then
VV

SSSof
isis
aaS
MIN-VERTEX-COVER
graph
G(V,
E)
the
graph
G(V,
E).
graph
G(V,
E)
of
G(V,
E),
then
VE)
graph
SG(V,
is
aG(V,
MIN-VERTEX-COVER
G(V,
lemmas.
Therefore,
there
are
two
vertices
A,
Bvertices
of

anINDEPENDENT-SET
edge
andofB.
Since
A, B
E).
S
aG(V,
of
the
graph
G(V,
E).
E).
1.
Ifgraph
S
know
V of
is
an
INDEPENDENT-SET
G(V,
E),
then
V
of
Sconnecting
is aweVERTEX-COVER
ofG(V,
the
G(V,
E),
VE)

S
is
athe
VERTEX-COVER
of
the
graph
E)
isgraph
MIN-VERTEXCOVER
of
the
graph
graph
G(V,
E)
taph
aisE).
VERTEX-COVER.
Therefore,
there
are Vtwo
A,
B

/ there
Vthat
V
SV
V,
VERTEX-COVER
of
G(V,
E),
then
Proof.
S
is
an
INDEPENDENT-SET
the
graph
G(V,
E)
graph
graph
G(V,
G(V,
E)
graph
G(V,
E)
of
the
graph
G(V,
E).
Proof.
We
We
know
know
that

S
S
is
is
a
a
vertex
vertex
cover
cover
by
by
lemma
lemma
1.
1.
The
The
on
o
DEPENDENT-SET
is
also
a
NP-hard
problem
by
reducing
a
MIN-VERTEX-COVER
problem
into
a
graph
G(V,
E)
DEPENDENT-SET
oflemmas.
graph
G(V,
E),
then

S
is aknow
MIN-VERTEX-COVER
ve
the following
twoWe
byby
Proof.
know
that
V

SVERTEX-COVER
is
athe
cover
lemma
1.
only
thing
for
us
pro
we
have
A,
Bis

/actually
S.
As
AV
and
BVisthe
are
connected
by
an
edge,
we
note
that
S
is
not
aremains
VERTEX-COVER.
Proof.
We
know
that
S
avertex
vertex
cover
1.aThe
The
only
thing
that
remains
forby
usto
tothin
p
graph
G(V,
E)
Proof.
We
that
Vlemma

S
is
vertex
cover
by
lemma
1.cover
The
only
Lemma
2.
If
S

VA,
isB
a
of
graph
G(V,
E),
then
V

Sisthat
isa
an
INDEPENDENT-S
B.
Since
A,
B

/
V

S,
we
have
S.
As
A
and
B
are
connected
Proof.
The
proof
is
actually
similar
to
previous
lemma.
Let
us
assume
that
V

S
is
not
a
INDEPENDENT-S
Proof.
We
know
that
V
S
vertex
lemm
Proof.
The
proof
similar
to
previous
lemma.
Let
us
assume
that
V

S
is
not
a
INDEPENDENT-S
Proof.
The
proof
is
actually
similar
to
the
previous
lemma.
Let
us
assume
that
V
S
is
not
a
INDEPEND
ENT-SET
of
graph
G(V,
E),
then
V

S
is
a
VERTEX-COVER
of
the
Proof.
We
know
that

is
vertex
cover
by
lemma
1.
The
only
thing
that
remains
We
know
that
V

S
is
a
vertex
cover
by
lemma
1.
The
only
thing
that
remains
for
us
to
prove
is
its
Proof.
Proof.
We
We
know
know
that
that
V
V

SSINDEPENDENT-SET.
is
a
anot
vertex
vertex
cover
cover
by
by
lemma
lemma
1.
1.
The
The
only
only
thing
that
that
remains
remains
for
for
ng
that
for
us
to
prove
is
its
vertex
cover
lemma
1.
The
only
that
remains
us
tous
prove
is
its
V
Vlemma

S
S
is
islemma.
not
not
minimum
minimum
vertex
vertex
cover.
cover.
Then,
Then,
t
minimality.
minimality.
Suppose
Suppose
ENDENT-SET
problem.
Proof.
Let
us
assume
that
Visalemma.
Sforvertex
not
athe
VERTEX-COVER.
Therefore,
there
are
two
ver
Proof.
Let
us
assume
aisProof.
VERTEX-COVER.
Therefore,
there
are
two
vertices
Ais
w
that
Vremains

Sby
is
a vertex
cover
by
lemma
The
only
thing
that
remains
for
us
to
prove
is
its
Proof.
The
proof
is
actually
similar
to
previous
Let
usand
that
VA,
B
SVTher
is
no
Proof.
Proof.
The
The
proof
proof
isis
actually
actually
similar
similar
to
to
the
the
previous
previous
lemma.
Let
Let
us
The
assume
assume
proof
that
isminimum
actually
V
V

S
Snot
similar
not
not
aassume
athing
INDEPENDENT-SET.
to
INDEPENDENT-SET.
the
previous
lemma.
Vcontradiction.
thing
S
isSV
not
minimum
cover.
Then,
there
is
another
vertex
cover
S
minimality.
Suppose
contradiction.
Therefore
Vfor

is
an
Proof.
We
know
that

S
is
vertex
cover
by
The
only
thing
that
remains
for
u
VThe

S
is1.
not
minimum
vertex
cover.
Then,
there
isvertex
another
vertex
cover
VV

minimality.
Suppose
INDEPENDENT-SET
V

S
is
not
cover.
Then,
there
minimality.
Suppose
graph
G(V,
E)
oof
actually
similar
to
the
previous
lemma.
Let
us
assume
that
V

S
is
athat
INDEPENDENT-SET.

STherefore,
is1.
vertex
cover
by
lemma
1.
The
only
thing
that
remains
for
us
to
prove
is
its
INDEPENDENT-SET.
This
is
avertices
Therefore
V

S
is
anot
Proof.
us
assume
V
1.
Sis
is
athere
VERTEX-COVER.

S
aaTherefore,
vertex
cover
by
lemma
1.
only
thing
that
for
us
to
prove
its
Therefore,
there
are
two
vertices
A,
B

VSS

S
and
there
an
edge
connecting
A
B.
Since
V
V

Sis
is
not
minimum
vertex
cov
minimality.
Suppose
and
there
are
two
A,
B

S
there
is
an
edge
connecting
A
B.
Since
A,
B

ma
The
only
thing
that
remains
us
to
prove
is
its
Therefore,
there
two
vertices
A,
B

S
there
is
an
edge
connecting
A
B.
Since
A,
B
that
Let
and
vertices
and

V
isisis
an
INDEPENDENT-SET
of
graph
G(V,
E),
then
Vremains

Sand
is
ais
VERTEX-COVER
of
for
us
to
prove
isare
its
minimality.
Suppose

is
not
minimum
vertex
cover.
Then,
V

S
is
not
minimum
vertex
cover.
Then,
there
is
another
vertex
cover
V

S
where
ty.
Suppose
emains
for
us
to
prove
is
its
V
V

S
is
is
not
not
minimum
minimum
vertex
vertex
cover.
cover.
Then,
Then,
there
is
is
another
another
vertex
vertex
cov
co
minimality.
minimality.
Suppose
Suppose
Proof.
Let
us
assume
that
V

S
is
not
a
VERTEX-COVER.
Therefore,
there
are
two
A,
B

/
V
S
the
.
there
are
two
vertices
A,
B

/
V

another
vertex
cover
V

S
where
minimum
vertex
cover.
Then,
there
is
another
vertex
cover
V

S
where
|V
|V

S
S
|
|
<
<
|V
|V

S|,
S|,
which
which
implies
implies
that
that
|S
|S
|
|
>
>
|S|.
|S|.
By
By
lemma
lemma
2,
2,
S
S
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

/
V

S,
we
have
A,
B

S.
As
A
a

and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

/
V

S,
we
have
A,
B

S.
As
A
and
B

V
minimum
S
is
not
minimum
vertex
cover.
Then,
there
is|S|.
another
vertex
cover
VA,

S
where
ppose
ySsimilar
to
the
previous
lemma.
Let
us
assume
that
V

S
not
aedge
INDEPENDENT-SET.
Therefore,
there
two
vertices
A,
B
V

S
and
there
is
an
edge
connecting
A
and
Therefore,
Therefore,
there
there
are
two
two
vertices
vertices
A,
A,
B
B

V
Vare

S
Sedge
and
there
there
Therefore,
is
is
an
an
edge
edge
there
connecting
connecting
are
two
A
A
and
and
B.
A,
Since
Since
B
set.
VA,
A,

B
B

and
VVis

ther
S,
S,
|V

SB
|are
<
|V

S|,
which
implies
that
|S
|connecting
>
By
lemma
2,
S
is
an
independent
Sini
V

is
minimum
cover.
Then,
there
isthat
another
vertex
cove
minimality.
Suppose
|V

S
|//B
<1.
|VThe

S|,
which
implies
that
|Sby
| isan
>
|S|.
By
lemma
2,
is
an
independent
set.
Therefore,
S
vertex

|V
S
|S
<
|V

S|,
which
implies
that
|S
|vertices
>
|S|.
By
lemma
2,
S
an
and
re
are
two
vertices
A,

V
S
there
is
an
A
and
B.
B
V

S,
is
not
vertex
cover.
Then,
there
is
another
vertex
cover

SSince
where
and
there
is
an
connecting
A
and
B.
Since
A,
B
/aTherefore,
VS|S|.
S,
we
S
is
not
minimum
vertex
cover.
Then,
there
is
another
cover
VV

S
we
have
A,
B
S.
As
A
and
B
are
connected
by
an
edge,
we
note
that
S
is
not
aisVVB.
VERTEX-COVER.
This
|V
|
<
|V

S|,
which
implies
|S
|aconnected
>
By
le
and
vertex
ertex
cover
by
lemma
only
thing
that
remains
for
us
to
prove
is
its
we
have
A,

S.
As
A
B
are
connected
edge,
we
note
that
S
is
not
ais
VERTEX-COVER.
This

an
S

over.
Then,
there
is
another
cover
V

where
we
have
A,
B

/S
S.
As
A
and
B
are
connected
by
edge,
we
note
that
S
is
not
aais
VERTEX-COVER.
there
is
another
vertex
cover
not
where
, where
which
implies
that
cover
and
Theorem
1.
If

V
is
a
MAX-INDEPENDENT-SET
of
graph
G(V,
E),
then

S
is
a
MIN-VERTEX
<
|V

S|,
which
implies
that
|S
|
>
|S|.
By
lemma
2,
S
is
an
independent
set.
Therefore,
S
not
vertex
V

S
where
|V
|V

S
S
|
|
<
<
|V
|V

S|,
S|,
which
which
implies
implies
that
that
|S
|S
|
|
>
>
|S|.
|S|.
By
By
lemma
lemma
2,
2,
S
S
an
an
independent
independent
set.
set.
The
Th
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

/
V

S,
we
have
A,
B

S.
As
A
and
B
are
an
the
S,
we
have
A,
B

S.
As
A
and
B
are
connected
dependent
set.
Therefore,
is
not
a
that
|S
|
>
|S|.
By
lemma
2,
S
is
an
independent
set.
Therefore,
S
is
not
a
maximum
maximum
independent
independent
set.
set.
This
This
is
is
a
a
contradiction.
contradiction.
Therefore
Therefore
V
V

st
prove
the
following
two
lemmas.
by
edge,
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
contradiction.
Th
Proof.
The
proof
is
actually
similar
to
previous
lemma.
Let
us
assume
that

S
is
not
INDEPEND
by
an
edge,
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction.
Therefore

S|,
which
implies
that
|S
|we
>
|S|.
By
lemma
Sby
isan
an
independent
set.
Therefore,
is
not
ertices
A,A
Band
V
S
and
there
isB
an
edge
Aedge,
and
A,
Vnot

S,
have
A,
B

/connecting
S.
As
A
and
BS
are
connected
by
an
edge,
we
note
that
S Viscover.
not
aisTher
VER
we
we
have
have
A,
A,
B
BB
/

/cover.
S.
S.
As
As
A
A
and
and
B
are
are
connected
connected
by
an
edge,
we
have
we
note
note
that
that

/is
S.
S
S
is
As
is
not
not
A
and
amaximum
aSThis
VERTEX-COVER.
VERTEX-COVER.
Ban
are
This
by
This
isis
edg
aS
aS
maximum
independent
set.
This
iswe
aimplies
contradiction.
Therefore
VB
S
is
minimum
vertex
|V

S
<
|V

S|,
which
that
|S
|
>
|S|.
By
lemma
2,
S
is
independent
set.
maximum
independent
set.
This
is2,
avertices
contradiction.
Therefore
V

S
isthe
the
minimum
vertex
cover.

are
t
aS.
VERTEX-COVER.
Therefore,
there
two
A,
B
/we
VSince

SB
maximum
independent
set.
This
a
contradiction.
Therefore

S an
the
that

/by
As
are
connected
by
an
edge,
note
that
isB.
not
aA,
VERTEX-COVER.
This
isaconnected
aminimum
implies
that
|S
|
>
|S|.
By
lemma
2,
S
is
an
independent
set.
Therefore,
S
is
not
a
by
an
edge,
we
note
S
is
an
INDEPENDENT-SET.
This
implies
that
|S
|
>
|S|.
2,
S
is
an
independent
set.
Therefore,
S
is
not
a
contradiction.
Therefore
V

S
is
an
INDEPENDENT-SET.
maximum
independent
set.
is
a
contradiction.
Ther
minimum
vertex
Then,
there
is
another
vertex
cover
V

S
where
.
By
lemma
2,

is
an
independent
set.
Therefore,
is
not
a
incontradiction.
Therefore
V
S
is
an
INDEPENDENT-SET.
lemma
2,
S
is
an
independent
set.
Therefore,
S
is
not
a
contradiction.
Therefore
V

S
is
an
INDEPENDENT-SET.
of
the
graph
G(V,
E).
m
independent
set.
This
is
a
contradiction.
Therefore
V

S
is
the
minimum
vertex
cover.
nt
set.
Therefore,
S
is
not
a
maximum
maximum
independent
independent
set.
set.
This
This
is
is
a
a
contradiction.
contradiction.
Therefore
Therefore
V
V

S
S
is
is
the
the
minimum
vertex
vertex
co
co
an
edge,
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction.
Therefore
V

S
is
a
T.
This
is
a
contradiction.
Therefore
V

S
is
a
minimum
vertex
cover.
a contradiction.
Therefore
Vedge,

SSSwe
is
the
minimum
vertex
cover.
VERTEX-COVER.
Therefore,
there
are
two
vertices
A,
Band

Sminimum
and
there
isTherefore
ancover.
edge
A
and B. vertex
Since A,
VERTEX-COVER.
VER
graph
G(V,
E),
then
V
SisisVTherefore
is
an
INDEPENDENT-SET
of
the
This
amaximum
contradiction.
V
SE),
the
vertex
and
Bof
are
connected
by
an
note
that
SThis
is
not
athen
VERTEX-COVER.
This
avertex
Therefore

S
isabove
antwo
INDEPENDENT-SET.
contradiction.
contradiction.
Therefore
Therefore
Vcontradiction.
V

an
an
INDEPENDENT-SET.
INDEPENDENT-SET.
contradiction.
S
an
me
that
Vis

isBy
not
aINDEPENDENT-SET.
VERTEX-COVER.
Therefore,
are
vertices
A, conclude
B

/V
V
Sis
independent
set.
isVisVathere
contradiction.
Therefore
Visconnecting
S
isthat
the
minimum
covB
B.
Since
B

/isS
Vis

S,
we
have
A,
S.
As
A
B
are
connected
isset.

From
From
the
the
above
theorem,
we
we
conclude
that
athe
aINDEPENDENT-S
MIN-VERTEX-CO
MIN-VERTEX-CO
SThis

an
INDEPENDENT-SET
of
graph
G(V,
V
Stheorem,
athe
VERTEX-COVER
ofeasily
Therefore
V
dependent
is
anminimum
.endent
This
contradiction.
Therefore

S
is
the
minimum
vertex
cover.
set.
This
aVB
contradiction.
Therefore
is
is
minimum
cover.
VERTEX-COVER.
aaA,
contradiction.
Therefore

S
is
the
minimum
vertex
cover.
hat
|SVis
|V
>
|S|.
lemma
2,
SS.
isis
an
independent
set.
Therefore,
not
a note
herefore

SS
the
vertex
cover.
From
the
above
theorem,
we
conclude
that
a
MIN-VERTEX-COVER
can
be
constructed
if
m
vertex
cover.
From
the
above
theorem,
we
conclude
that
a
MIN-VERTEX-COVER
can
be
easily
constructed
ifwc
VERTEX-COVER.
From
the
above
theorem,
we
conclude
that
a
MIN-VERTEX-COVER
we
have
A,
B

/
As
A
and
B
are
connected
by
an
edge,
we
that
S
is
not
a
VERTEX-COVER
Theorem
1.We
Sknow

ishave
aBVcontradiction.
MAX-INDEPENDENT-SET
of
graph
G(V,
E),
then

SifVconclude
iswe
acan
MIN-VERTEX-COV
From
the
above
theorem,
we
ausconstru
MIN-V

Sabove
is
an theorem,
INDEPENDENT-SET.
Theorem
1.
IfIfwe
S

VVSisthat
is
MAX-INDEPENDENT-SET
graph
E),
then
VVthen

S
is
aremains
MIN-VERTEX-COV
Theorem
1.
Ifwe

is
MAX-INDEPENDENT-SET
of
graph
G(V,
E),

S
isbe
athat
MIN-VERTE
ea)an
connecting
AMIN-VERTEX-COVER
and
B.
Since
A,

/V
VSais

S,
we
have
A,
B by
V of
S.
As
A
and
B
are
connected
INDEPENDENT-SET.
This
aa2.
Therefore
that
S we
is
aG(V,
Proof.
V
S
is
a
vertex
cover
lemma
1.
The
only
thing
that
for
to
pro
the
conclude
that
a
MIN-VERTEX-COVER
can
be
easily
constructed
have
a
From
From
the
the
above
above
theorem,
theorem,
we
we
conclude
conclude
that
a
a
MIN-VERTEX-COVER
MIN-VERTEX-COVER
can
be
easily
easily
constru
be
easily
constructed
if
a
onclude
that
a
can
be
easily
constructed
if
have
a
MAX-INDEPENDENT-SET.
MAX-INDEPENDENT-SET.
Lemma
If

V
is
a
VERTEX-COVER
of
graph
G(V,
E),
then
V

S
is
an
INDEPEN
Lemma
2.
If
S

a
VERTEX-COVER
of
graph
G(V,
E),
then
V

S
is
an
INDEPENDENT
contradiction.
Therefore
V

S
is
the
minimum
vertex
cover.
oveTheorem
theorem,
weIfthat
that
aabove
MIN-VERTEX-COVER
can
beV easily
constructed
if
we
a E),
Theorem
1.
If graph
S is
can
Vwe
is
a easily
MAX-INDEPENDENT-SET
then Vconstruc
Sthen
iso
Theorem
1.
1.
Theorem
1.
Ifconclude
SScan

V
V
isiseasily
aTherefore
athe
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
of
graph
G(V,
G(V,
E),
E),
IfaififVERTEX-COVER
Swe
then
then
have
V VVisof

a graph
S
MAX-INDEPENDENT-SET
S isishave
aaG(V,
MIN-VERTEX-COVER
MIN-VERTEX-COVER
MAX-INDEPENDENT-SET.
From
conclude
a Sis
MIN-VERTEX-COVER
can
be easily
MAX-INDEPENDENT-SET.
MAX-INDEPENDENT-SET.
contradiction.
Vtheorem,

S
an
INDEPENDENT-SET.
fm,

Vof
MAX-INDEPENDENT-SET
G(V,
E),
then

m,
we
conclude
ahave
MIN-VERTEX-COVER
can
be
easily
constructed
2.
Ifgraph
Sthat
then
V
we
conclude
that
a
MIN-VERTEX-COVER
be
constructed
of
the
graph
G(V,
E).
MAX-INDEPENDENT-SET.
the
graph
G(V,
-VERTEX-COVER
be
constructed
ifofLemma
we
aof
of
graph
G(V,
E).
eSthat
SVis2.
isaminimality.
an
INDEPENDENT-SET.
This
ishave
a contradiction.
Therefore
V INDEPENDENT-SET
aaisS another
is a of graph
Vgraph
G(V,
S Sof
isisE),
not
minimum
vertex
cover.
Then,
there
vertexG(V,
cover
V S
Suppose
DEPENDENT-SET.
sily
constructed
we
aof
MAX-INDEPENDENT-SET.
MAX-INDEPENDENT-SET.
Lemma
Ifnot
S1the
an
V
is
aE).
VERTEX-COVER
graph
G(V,
E),
VisaG(V,
MIN-VERTEX-COVER
SweE).
ishave
an
ofE),
the
E),
then
S
isif
INDEPENDENT-SET
of
the
graph
G(V,
E)
graph
G(V,
E)
previous
lemma.
Let
us
assume
that
V

not
a
INDEPENDENT-SET.
NDENT-SET.
MAX-INDEPENDENT-SET
of
graph
then
V

S
is
a
MIN-VERTEX-COVER
the
G(V,
E).
of
of
the
the
graph
graph
G(V,
G(V,
E).
E).
of
the
graph
MAX-INDEPENDENT-SET.

We
say
that
problem
X
is
reducible
to
problem
Y
assume
that
VMIN-VERTEX-COVER
S
Therefore,
arehave
two2,vertices
A,independent
B
/ V S set. Therefore, S
G(V,
E).G(V,
T.
graph
G(V,
E)there
T.
is not a VERTEX-COVER.

nclude
that
a Theorem
can
be easily
constructed
if we
a SG(V,
|V
Sis
|an
< |V
If connecting
S|,
which
that
|S
| >A,
|S|.
By
lemma
is an
graph
E)
In
In
the
the
beginning
beginning
of
of
this
this
section,
section,
we
we
assume
assume
we
know
know
that
that
MIN-V
MIN-V
1.
S

V
is
aimplies
MAX-INDEPENDENT-SET
ofS,
graph
E),
then
V we

S
aus
MIN-VERTE
V edge
of
SProof.
and
there
edge
and
B.
Since
B
B
V1.

Proof.
We
know
that

Sthis
is
aA
vertex
cover
by
lemma
1.
The
only
thing
that
remains
for
us
toisprove
prove
We
know
that
VV

S
is
aan
vertex
cover
by
lemma
The
only
thing
that
remains
for
to
is
Proof.
We
know
that
V
S
is
a
vertex
cover
by
lemma
1.
The
only
thing
that
remains
for
us
to
pis
InProof.
beginning
of
section,
we
assume
we
know
that
MIN-VERTEX-COVER
is
aisVaNP-hard
probl
Inthe
the
beginning
of
this
section,
we
assume
we
know
that
MIN-VERTEX-COVER
isis
NP-hard
prob
VER
graph
G(V,
E),
then
INDEPENDENT-SET
of
the
In
the
beginning
of
this
section,
we
assume
we
know
that
MIN-VERTE
n
connecting
A
and
B.
Since
A,
B

/
V

S,
we
have
A,

S.
As
A
and
B
are
connected
Proof.
The
proof
is
actually
similar
to
the
previous
lemma.
Let
us
assume
that

S
not
aits
IN
In
the
beginning
of
this
section,
we
assume
we
know
The
proof
is
actually
similar
to
the
previous
lemma.
Let
us
assume
that
V

S
not
a
INDEPE
Proof.
We
know
that
V

S
is
a
vertex
cover
by
lemma
1.
The
only
thing
that
rema
Proof.
Proof.
Proof.
We
We
know
know
that
that
V
V

S
S
is
is
a
a
vertex
vertex
cover
cover
by
by
lemma
lemma
1.
1.
The
The
We
only
only
know
thing
thing
that
that
that
V

remains
remains
S
is
a
vertex
for
for
us
us
cover
to
to
prove
prove
by
lemm
is
is
maximum
independent
set.
This
is
a
contradiction.
Therefore
V

S
is
the
minimum
vertex
cover.
e
beginning
of
this
section,
we
assume
we
know
that
MIN-VERTEX-COVER
is
a
NP-hard
problem.
It
is
In
In
the
the
beginning
beginning
of
of
this
this
section,
section,
we
we
assume
assume
we
we
know
know
that
that
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
is
a
a
NP-h
NP-h
its
X-COVER
is
a
NP-hard
problem.
It
is
we
assume
we
know
that
MIN-VERTEX-COVER
is
a
NP-hard
problem.
It
is
good
good
to
to
know
know
as
as
many
many
NP-hard
NP-hard
problem
problem
as
as
possible.
possible.
This
This
is
is
necessary
necessary

of
the
graph
G(V,
E).
ow
that
V

S
is
a
vertex
cover
by
lemma
1.
The
only
thing
that
remains
for
us
to
prove
is
its
nected
by
an
edge,
we
note
that
S
is
not
a
VERTEX-COVER.
This
is
a
Proof.
The
proof
isThis
actually
similar
to
the
Let
us
ning
this
section,
we
assume
weS
know
that
MIN-VERTEX-COVER
isisknow
athat
NP-hard
problem.
It
is lemma.
VINDEPENDENT-SET.

Sthere
is
not
minimum
vertex
cover.
Then,
there
is
another
vertex
cover
SVassu
wh
minimality.
Suppose
V

is
not
vertex
cover.
Then,
there
is
vertex
V

S
wh
Suppose
V
Sare
isminimum
not
minimum
vertex
cover.
Then,
there
is
another
vertex
cover

minimality.
Suppose
good
to
know
as
many
NP-hard
problem
as
This
isthere
necessary
so
that
ifprevious
encounter
aA
proble
is
aofminimality.
VERTEX-COVER
of
graph
G(V,
E),
then
V

Swe
isLet
an
INDEPENDENT-SET
of
the
In
the
beginning
of
this
section,
assume
we
that
MIN-VERTEX-COVER
isnew
a
NP-ha
good
know
as
many
NP-hard
problem
as
possible.
necessary
so
that
ifwe
we
encounter
aV
new
prob
good
to
know
as
NP-hard
problem
as
possible.
This
iscover
necessary
so
tha
Proof.
The
proof
isto
actually
similar
to
the
previous
lemma.
us
assume
Vis

not
aproblem
INDEPENDENT-SET.
us
assume
that
V

S
is
not
athere
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
ais
contradiction.
Therefore
Vedge

Sthat
is
aifA
Therefore,
two
A,
B

Swe
and
there
is
an
connecting
B.
sV
section,
we
assume
we
know
that
MIN-VERTEX-COVER
is
NP-hard
problem.
Itanother
is
Since
section,
we
assume
we
know
that
MIN-VERTEX-COVER
aaas
NP-hard
problem.
It
is
good
to
know
as
many
NP-hard
problem
as
possible.
This
Therefore,
two
vertices
A,
B

Vmany

S
and
is
an
edge
connecting
and
B.
A
where
w
MIN-VERTEX-COVER
is
apossible.
NP-hard
problem.
Itpossible.
is

S
aencounter
vertex
cover
by
lemma
1.
The
only
thing
that
remains
for
us
to
prove
is
its
V

Sany
is
not
minimum
cover.
Then,
there
another
minimality.
Suppose
V
Vto

S
S
is
isare
not
not
minimum
minimum
cover.
cover.
Then,
Then,
there
there
is
another
VS

S
vertex
vertex
is
not
cover
minimum
cover
VVis

vertex
Sit
Sand
where
cov
minimality.
minimality.
Suppose
Suppose
minimality.
Suppose
know
many
problem
as
This
isvertices
necessary
so
that
iftwo
encounter
ais
new
X,
we
so
R
isthat
aisas
NP-hard
problem.
It
is
good
to
know
know
as
as
many
many
NP-hard
NP-hard
problem
problem
as
possible.
possible.
This
is
isanother
necessary
so
that
if
we
we
encounter
encounter
aver
ano
nS
n
is
vertex
vertex
tblem
if
we
aThis
new
problem
X,
we
possible.
is
necessary
so
that
ifthat
we
encounter
a>
new
problem
X,
we
can
can
use
use
of
of
the
the
NP-hard
NP-hard
problems
problems
that
that
we
we
know,
know,
reduce
reduce
it
to
to
probl
prob
NP-hard
vertex
This
good
any
necessary
V
not
minimum
vertex
cover.
Then,
there
is
another
vertex
cover
V

S
where
uppose
DEPENDENT-SET.
Therefore,
there
are
vertices
A,
B

S
and
there
is
an
edge
many
NP-hard
problem
as
possible.
This
is
necessary
so
that
if
we
encounter
a
new
problem
X,
we
|V

S
|
<
|V

S|,
which
implies
that
|S
|
>
|S|.
By
lemma
2,
S
is
an
independent
set.
Therefore,
S
is
no
|V

S
|
<
|V

S|,
which
implies
|S
|
>
|S|.
By
lemma
2,
S
is
an
independent
set.
Therefore,
S
is
|V

S
|
<
|V

S|,
which
implies
that
|S
|
|S|.
By
lemma
2,
S
is
an
independent
set.
Therefore,
can
use
any
of
the
NP-hard
problems
that
we
know,
reduce
it
to
problem
X,
and
thus
prove
that
X
is
also
good
to
know
as
many
NP-hard
problem
as
possible.
This
is
necessary
so
that
if
we
encounter
a
ne
can
use
any
of
the
NP-hard
problems
that
we
know,
reduce
it
to
problem
X,
and
thus
prove
that
X
is
also
can
use
any
of
the
NP-hard
problems
that
we
know,
reduce
it
to
problem
X,
From
the
above
theorem,
we
conclude
that
a
MIN-VERTEX-COVER
can
be
easily
constructed
if
w
Therefore,
there
are
two
vertices
A,
B

S
and
there
is
an
edge
connecting
A
and
B.
Since
A,
B

S,
n
edge
connecting
A
and
B.
Since
A,
B

S,
note
VER.
we
have
A,
B

/
S.
As
A
and
B
are
connected
by
an
edge,
we
note
that
S
is
not
a
VERTEX

hard
problem
as
possible.
This
is
necessary
so
that
if
we
encounter
a
new
problem
X,
Proof.
We
know
that
V

S
is
a
vertex
cover
by
lemma
1.
The
only
thing
that
remains
for
us
to
pS

hard
problem
as
possible.
This
is
necessary
so
that
if
we
encounter
a
new
problem
X,
we
can
use
any
of
the
NP-hard
problems
that
we
know,
reduc
we
have
A,
B

/
S.
As
A
and
B
are
connected
by
an
edge,
we
that
S
is
not
a
VERTEX-COV
we
assume
we
know
that
MIN-VERTEX-COVER
is
a
NP-hard
problem.
It
is

his
is
necessary
so
that
if
we
encounter
a
new
problem
X,
we
S
is
not
minimum
vertex
cover.
Then,
there
is
another
vertex
cover
V

S
where

S
|
<
|V

S|,
which
implies
that
|S
|
>
|S|.
By
lemma
2,
S
is
an
independent
s
|V
|V

S
S
|
|
<
<
|V
|V

S|,
S|,
which
which
implies
implies
that
that
|S
|S
|
|
>
>
|S|.
|S|.
By
By
lemma
lemma
|V

S
2,
2,
|
S
<
S
|V
is
is
an
an

S|,
independent
independent
which
implies
set.
set.
Therefore,
that
Therefore,
|S
|
>
S
S
|S|.
is
is
not
not
By
a
le
a
ny
of
the
NP-hard
problems
that
we
know,
reduce
it
to
problem
X,
and
thus
prove
that
X
is
also
NP-hard.
|V

counter
a
new
problem
X,
we
can
can
use
use
any
any
of
of
the
the
NP-hard
NP-hard
problems
problems
that
that
we
we
know,
know,
reduce
reduce
it
it
to
to
problem
problem
X,
X,
and
and
thus
thus
prove
prove
that
that
previous
lemma.
Let
us
assume
that
V

S
is
not
a
INDEPENDENT-SET.
and
thus
prove
that
X
is
also
NP-hard.
ms
that
we
know,
reduce
it
to
problem
X,
and
thus
prove
that
X
is
also
NP-hard.
1contradiction.
1have

S|,
which
that
|S
| know,
>
|S|.
By
2,
S
isedge,
an
independent
SNP-hard.
isYYX,
not
we
A,
B

/problem
S.
As
and
B
connected
byaan
edge,
weisthat
note
NP-hard
problems
that
we
reduce
to
problem
X,that
and
thus
prove
Xare
is
also
maximum
independent
set.
This
islemma
contradiction.
Therefore
VXA

Sthat
isTherefore,
the
vertex
cover.
maximum
independent
set.
This
is
aait
contradiction.
Therefore
VX

S
the
minimum
vertex
cover.
maximum
independent
set.
is
aV
Therefore
Vis

Sto
is
theis
minimum
vertex
cover.
We
We
say
say
that
problem
isset.
reducible
reducible
to
to
problem
problem
can
use
any
of
the
NP-hard
problems
we
know,
reduce
it
problem
and
thus
prove
X
11
1not
MAX-INDEPENDENT-SET.
we
have
A,
Bimplies
/we
S.
As
A
and
BTherefore
connected
by
we
note
that
S
is
not
aminimum
VERTEX-COVER.
This
aV
note
that
S
is
aand
VERTEX-COVER.
contradiction.
Therefore

SINDEPENDENT-SET.
is
an
INDEPENDENT-SET.
dehe
problems
that
we
know,
reduce
to
problem
X,
and
thus
prove
that
X
also
NP-hard.

S
is1
not
minimum
vertex
cover.
Then,
there
another
vertex
cover
minimality.
Suppose
We
say
that
problem
X
is
reducible
to
problem
Yathat
problems
that
know,
reduce
ititare
to
problem
X,
and
thus
that
X
isisis
also
NP-hard.
We
say
problem
X
is
reducible
to
problem
Y
contradiction.
VThis
Sis
isaNP-hard.
an
lem
possible.
This
isthat
necessary
so
that
ifThis
we
encounter
new
problem
X,
we
We
say
that
problem
XV
is
reducible
to
problem
Yprove
uce
itasto
problem
X,
thus
prove
that
X
is
also

90

J.I. Gunawan

From the above theorem, we conclude that a MIN-VERTEX-COVER can be easily


constructed if we have a MAX-INDEPENDENT-SET.
In the beginning of this section, we assume we know that MIN-VERTEX-COVER
is a NP-hard problem. It is good to know as many NP-hard problem as possible. This
is necessary so that if we encounter a new problem X, we can use any of the NP-hard
problems that we know, reduce it to problem X, and thus prove that X is also NPhard.

3. How to Proceed

Suppose we already know that a problem is unsolvable (i.e. any known algorithm will
not solve this problem in time). In competition, it is impossible to complain that This
is unsolvable, can you eliminate this problem? to the judges, since the judges believe
How
How to
to proceed
proceed
they have a solution. Such a request is absurd when there are already several contestants
have
that problem.
Also,this
in aproblem
major competition
(e.g. ACM International
any
algorithm
will
in
s unsolvable
unsolvable (i.e.
(i.e. who
any known
knownsolved
algorithm
will not
not solve
solve
this
problem
in
Collegiate
Programming
Contest
World
Finals,
IOI),
it
is
unlikely
that the judges have
omplain that
complain
that "This
"This isis unsolvable,
unsolvable, can
can you
you eliminate
eliminate this
this problem?"
problem?"
incorrect
solution.
yy have
have aa solution.
solution. Such
Such aa request
request isis absurd
absurd when
when there
there are
are already
already

blem. Also,
oblem.
Also, inin aa major
major competition
competition (e.g.
(e.g. ACM
ACM International
International Collegiate
Collegiate
How to
isis unlikely
unlikely that
that the
the judges
judges have
have incorrect
incorrect solution.
solution. 3

3.1. Approximation

proceed

Suppose we already know that a problem is unsolvable (i.e. any known algorithm will not solve this pro
time).InInreal
competition,
it iscannot
impossible
to optimal
complainsolution,
that "This
is unsolvable,
can solution
you eliminate this pr
life, when we
find the
we can
try to find the
to can
thethat
judges,
since
the
judges
believe
they
a solution.
request
is absurd
try
to
nd
the
solution
that
isis close
to
the
optimal
all solution,
solution, we
we
can
try
toclose
nd
thethe
solution
that
close
to have
the
optimal
is
to
optimal
solution.
More
specifically,
we Such
try to afind
a solution
that iswhen there are
several
contestants
who
have
solved
problem.
Also, insolution
a major for
competition
(e.g. ACM
isis not
larger
(where
>
1)
the
optimal
not
than
(where
a minimisation
prob-International C
a solution
solution that
that
not
larger than
than
(where
>that
1)) times
times
theoptimal
optimal
lem. The Contest
mostalgorithm
common
Ithat
found
textbooks
the 2-approxProgramming
World approximation
it algorithm
is unlikely
theinjudges
haveisincorrect
solution.
most
approximation
IFinals,
in
isis the
most common
common
approximation
algorithm
I found
foundIOI),
in textbooks
textbooks
the
MIN-VERTEX-COVER
problem,
which
means that the algorithm will not
blem,
that
algorithm
more
twice
blem, which
which means
meansimation
that the
the
algorithm will
will not
not choose
choose
more than
than
twice
choose
more than
twice the
number
of3.1
vertices
than the optimal solution. However, apution.
problems
rarely
occur
in
competitive
lution. However,
However, approximation
approximation
problems
rarely
occur
in
competitive
Approximation
proximation
problems
rarely
occur
in
competitive
programming
(especially IOI). One
eason isis because
reason
because to
to create
create this
this kind
kind of
of problem,
problem, the
the judges
judges have
have to
to
In
real
life,
when
we
cannot
nd
the
optimal
solution,
we
can
try
to
nd
the solution
of
the
reason
is
because
to
create
this
kind
of
problem,
the
judges
have
to knowthat
theis close to the
y that
that the
the contestants
contestants solution
solution isis indeed
indeed -approximation.
-approximation. However,
However,
solution.
More
specically,
we
try
to
nd
a
solution
that
is
not
larger
than

(where

> 1) times the


optimal
solution
in
order
to
verify
that
the
contestants
solution
is
indeed
-approximaee (or
(or takes
takes aa long
long time).
time). Since
Since this
this approach
approach isis not
not really
really suitable
suitable for
for
tion.
generating
the optimal
solution
is impossible
(or takes
a long time).
solution
forHowever,
a minimisation
problem.
The most
common
approximation
algorithm
I found in textbook
this
in
this approach
approach
in detail.
detail.
Since this approach
is not really suitable
forwhich
competitive
I willwill
notnot
dis-choose more th
2-approximation
MIN-VERTEX-COVER
problem,
means programming,
that the algorithm
cuss this
in detail.
the number
of approach
vertices than
the optimal solution. However, approximation problems rarely occur in com
3.2
3.2 Pruning
Pruning
programming (especially IOI). One of the reason is because to create this kind of problem, the judges
know
the optimal
solution
in order
to verifyProgramming
that the contestants solution is indeed -approximation. H
programming
problems.
In
International
Collegiate
programming
problems.
In ACM
ACM
International
Collegiate
Programming
3.2. Pruning
the optimal
solution isto
impossible
takes aof
m
on
the
count
number
m II (Robots
(Robotsgenerating
on Ice)
Ice) required
required
the contestant
contestant
to
count the
the(or
number
oflong time). Since this approach is not really sui
I will n.d.),
not
discuss
approach
ICPC
Finals
problem
which
isis known
to
ICPC World
Worldcompetitive
Finals 2010
2010programming,
problem statement
statement
n.d.),
whichthis
known
to in detail.
ossible
the
isis to
prune
ossible paths
paths isis impossible,
impossible,
the solution
solution
for
this problem
problem
toprogramming
prune
This approach
is
usefulfor
in this
some
competitive
problems. In ACM International
Collegiate
Programming
Contestn.d.).
(ICPC)
World
Finals
ICPC
World
2010
If
at
lll possible
ICPC
World Finals
Finals
2010 Solutions
Solutions
n.d.).
If
at
possible paths
paths (ACM
(ACM
3.2 Pruning 2010, problem I (Robots
on Ice) points,
required
thewe
contestant
tothe
count
theand
number of Hamiltonian Paths with
visit
unvisited
then
can
path
visit the
the rest
rest of
of the
the
unvisited
points,
then
we
can prune
prune
the
path
and
This
approach
is
useful
in
some
competitive
programming
ACMwhich
International
Collegiate Prog
constraints
(ACM
ICPC
World
Finals
2010
problem
statement,Inn.d.),
is known
ery suitable
very
suitable for
for IOI.
IOI. Usually,
Usually, IOI
IOI problems
problems require
require deep
deep analysis
analysis from
fromproblems.
Contest
(ICPC)
World
Finals
2010,
problem
I
(Robots
on
Ice)
required
the
contestant
to
count the nu
to
be
a
NP-hard
problem.
While
finding
all
possible
paths
is
impossible,
the
solution
cepted by
ccepted
by only
only "hacking"
"hacking" aa complete
complete search
search algorithm.
algorithm. Therefore,
Therefore, we
we
Hamiltonian Paths with constraints (ACM ICPC World Finals 2010 problem statement n.d.), which is k
be a NP-hard problem. While nding all possible paths is impossible, the solution for this problem is
the exponential algorithm we use to nd all possible paths (ACM ICPC World Finals 2010 Solutions n.d
nding
nding Small
Small Constraints
Constraints
some point we know that it is impossible to visit the rest of the unvisited points, then we can prune the p
backtrack
immediately.
However,
it is not(e.g.
very N
suitable
for IOI. Usually, IOI problems require deep analy
hh large
isis impossible
to
exponentially
large N
N that
that
impossible
to solve
solve
exponentially
(e.g.
N>
> 50).
50).

.1
.1 Approximation
Approximation

1)
theto
optimal
tion.
However,
approximation
problems
rarely
occur
injudges
competitive
intimes
isthe
the
isthis
because
create
this
kind
of
problem,
the
judges
have
to
know
the
optimal
solution
in
order
verify
that
the
solution
isinco
in
know
the
solution
to
verify
that
the
contestants
solution
issolution
indeed
-approximation.
Howev
nd
oftextbooks
problem,
judges
have
to
In
real
life,
when
we
cannot
nd
the
optimal
solution,
we
try
toto
nd
the
that
istime).
to
the
optim
ming
Contest
World
Finals,
IOI),
itin
isorder
Programming
unlikely
that
the
Contest
World
have
Finals,
incorrect
IOI),
solution.
it(or
is
unlikely
thatfor
the
judges
have
generating
the
optimal
solution
impossible
(or
takes
acan
long
time).
Since
this
approach
isclose
not
really
suitabl
generating
the
optimal
solution
is
impossible
takes
acontestants
long
Since
this
ap
deed
-approximation.
However,
optimal
solution
is
impossible
(or
takes
long
time).
Since
this
approach
is
not
really
suitable
approach
isoptimal
not
really
suitable
for
competitive
programming,
Iaiswill
not
discuss
this
approach
in
detail.
in
textbooks
is
the
ason
is
because
to
create
this
kind
of
problem,
the
judges
have
to
oose
more
than
twice
the
contestants
solution
is
indeed
-approximation.
However,
generating
the
optimal
solution
is
impossible
(or
takes
a
long
time).
Since
this
af
generating
the
optimal
solution
is
impossible
(or
takes
a
long
time).
Since
this
approach
is
not
really
suitable
ndeed
-approximation.
However,
solution.
More
specically,
we
try
to
nd
a
solution
that
is
not
larger
than

(where

>
1)
times
the
optim
competitive
I will notindiscuss
this approach
competitive
programming,
I 3.1
will in
notdetail.
discuss this approach in detail.
approach
is Inot
suitablethis
forapproach
gramming,
willreally
not programming,
discuss
detail.
Approximation
oose
more
than
twice
that
the
contestants
solution
is
indeed
-approximation.
However,
occur
in
competitive
akes
a
long
time).
Since
this
approach
is
not
really
suitable
for
competitive
willdetail.
not discussalgorithm
this approach
in detail.
competitive
I problem.
will
not
discuss
this approach
approach
is not
suitable for
solution
for really
aprogramming,
minimisation
The programming,
most
commonI in
approximation
I found
in textbooks is th
3.1
Approximation
3.1
Approximation
3.2
Pruning
occur
in in
competitive
adetail.
long
Since
approach
isproblem,
not
really
suitable
for
,(or
thetakes
judges
havetime).
toInMIN-VERTEX-COVER
real
life,this
when
we Understanding
cannot
nd
the
optimal
solution,
we
can
try
to
nd
the
solution
is twic
clos
pproach
2-approximation
which
means
that
the
algorithm
will
not
choose
than
Unsolvable
Problem
91 morethat
3.2
Pruning
3.2
Pruning
3.2 solution,
Pruning
,his
judges
have
to
, the
when
we
cannot
nd
the
optimal
In
real
life,
we
when
can
try
we
to
cannot
nd
the
nd
solution
the
optimal
that
is
solution,
close
to
we
the
can
optimal
try
to
nd
the
sol
approach
in
detail.
oximation.
However,
solution.
More
specically,
we
try
to
nd
a
solution
that
is
not
larger
than

(where

>
1)
ti
the
number
of
vertices
than
the
optimal
solution.
However,
approximation
problems
rarely
occur
in
competitiv
This approach is useful in some competitive
problems. In ACM
3.2 International
PruningCollegiate Prog
3.2programming
Pruning
oximation.
However,
More
specically,
we
try
to
nd
a
solution
solution.
that
More
is
not
specically,
larger
than
we

try
(where
to
nd

a
>
solution
1)
times
that
the
is
optimal
not
larger
than

not
really
suitable
for
solution
for
a
minimisation
problem.
The
most
common
approximation
algorithm
I
found
in
This
approach
is
useful
in
some
competitive
programming
problems.
In
ACM
International
Collegiate
Programm
This
approach
useful
in
some
competitive
programming
problems.
In
ACM
Intern
useful
in
some
competitive
programming
problems.
In
ACM
International
Collegiate
Programming
for
this
problem
is
to prune
the
exponential
we
use
findkind
all possible
pathsthe
programming
(especially
IOI).
One of
the
reason
this
of contestant
problem,
havenut(
M
Collegiate
Programming
Contest
(ICPC)
World
Finals
2010,
problemis algorithm
Ibecause
(Robotsto
oncreate
Ice)torequired
the
to judges
count the
2 International
Pruning
This
approach
is
useful
in
some
competitive
programming
problems.
In
ACM
Inte
This
approach
is
useful
in
some
competitive
programming
problems.
In
ACM
International
Collegiate
Programmi
not
really
suitable
for
or
a
minimisation
problem.
The
most
solution
common
for
a
approximation
minimisation
algorithm
problem.
The
I
found
most
in
common
textbooks
approximation
is
the
algor
2-approximation
MIN-VERTEX-COVER
problem,
which
means
that
the
algorithm
will not
choose
Contest
(ICPC)
World
2010,
problem
I the
(Robots
on
required
the
contestant
count
the
numb
Contest
(ICPC)
World
Finals
2010,
problem
Iproblem
(Robots
on
Ice)
the
cont
rnational
Collegiate
Programming
(ACM
ICPC
World
2010
Solutions.
n.d.).
If
atIce)
some
we
know
that
it
isrequired
World
Finals
2010,
problem
I Finals
(Robots
on
Ice)
required
the
contestant
topoint
count
the
number
ofto
know
the
optimal
solution
in Finals
order
to
verify
that
contestants
solution
is
indeed
-approximation.
Howeve
he
contestant
to
count
the
number
of
3.2
Pruning
Hamiltonian
Paths
with
constraints
(ACM
ICPC
World
Finals
2010
statement
n.d.),
which
is k
mming
problems.
In
ACM
International
Collegiate
Programming
Contest
(ICPC)
World
Finals
2010,
problem
I
(Robots
on
Ice)
required
the
con
Contest
(ICPC)
World
Finals
2010,
problem
I
(Robots
on
Ice)
required
the
contestant
to
count
the
number
ternational
Collegiate
Programming
mation
MIN-VERTEX-COVER
problem,
2-approximation
which
means
that
MIN-VERTEX-COVER
the
algorithm
will
not
problem,
choose
which
more
means
than
twice
that
algorithm
the
number
of
vertices
than
the
optimal
solution.
However,
approximation
problems
rarely
occu
impossible
to
visit
the
rest
of
the
unvisited
points,
then
we
can
prune
the
path
and
Hamiltonian
Paths
with
constraints
(ACM
ICPC
World
Finals
2010
problem
statement
n.d.),
which
is
know
Hamiltonian
Paths
with
constraints
(ACM
ICPC
World
Finals
2010
problem
state
ntestant
to
count
the
number
of
thsstatement
with
constraints
(ACM
ICPC
World
Finals
2010
problem
statement
n.d.),
which
is
known
to
generating
the
optimal
solution
is
impossible
(or
takes
a
long
time).
Since
this
approach
is
not
really
suitable
em
n.d.),
which
is
known
to
be a NP-hard problem. While nding all possible paths is impossible, the solution for this problem isf
rogramming
problems.
In
ACM
International
Collegiate
Programming
obots
on
Ice)
required
the
contestant
to
count
the
number
of
Hamiltonian
Paths
with
constraints
(ACM
ICPC
World
2010
problem
sta
Hamiltonian
Paths
with
constraints
(ACM
ICPC
Finals
2010
problem
statement
n.d.),
which
is known
to
count
the
number
er
of competitive
vertices
than
the
optimal
solution.
the
number
However,
approximation
vertices
than
problems
optimal
rarely
solution.
occur
inproblems
competitive
approximation
prob
backtrack
immediately.
itof
ispossible
not
very
suitable
for
IOI.
Usually,
IOI
programming
(especially
IOI).
One
of
the
reason
is(ACM
because
to
create
this
kind
of Solutions
problem,
thp
be
athe
NP-hard
While
nding
all
paths
is
impossible,
the
solution
for
this
problem
issolutio
to
be
aHowever,
NP-hard
problem.
While
nding
all
possible
paths
isFinals
impossible,
the
tement
n.d.),
which
isproblem.
known
to
roblem.
While
nding
all
possible
paths
isuse
impossible,
the
solution
this
problem
isHowever,
to
prune
programming,
Iof
will
not
discuss
this
approach
inthe
detail.
eontestant
solution
for
this
problem
isalgorithm
to
prune
ICPC
World
Finals
2010
n.d
exponential
we
to
nd
allWorld
possible
paths
I
(Robots
on
Ice)
required
the
contestant
to
count
the
number
of
World
Finals
2010
problem
statement
n.d.),
which
is
known
to
be
a
NP-hard
problem.
While
nding
all
possible
paths
is
impossible,
the
solu
be
a
NP-hard
problem.
While
nding
all
possible
paths
is
impossible,
the
solution
for
this
problem
is
to
pru
tatement
n.d.),
which
is
known
to
require
deep
analysis
from
the
contestant.
It
is
rare
that
we
can
get
Accepted
by
only
ming
(especially
IOI).
One
of
the
reason
programming
is
because
(especially
to
create
this
IOI).
kind
One
of
of
problem,
the
reason
the
is
judges
because
have
to
to
create
this
kind
know
the
optimal
solution
in
order
to
verify
that
the
contestants
solution
is
indeed
-approxim
ICPC
World
Finals
2010
Solutions
n.d.).
the
exponential
algorithm
we
use
to
nd
all
possible
paths
(ACM
ICPC
World
the
exponential
algorithm
we
use
to
nd
all
possible
paths
(ACM
tion
for
thiswe
problem
is we
toall
prune
World
Solutionspoints,
n.d.). If
at we can prune theFip
algorithm
usepoint
to nd
possible
(ACM ICPC
World
Finals
2010
Solutions
n.d.).
If atitpaths
some
know
that
is impossible
to visit
the Finals
rest of2010
the unvisited
then
CPC
World
Finals
2010
problem
statement
n.d.),
which
is
known
to
legiate
Programming
paths
is
impossible,
the
solution
for
this
problem
is
to
prune
ICPC
World
the
exponential
algorithm
we
use
to
nd
all
possible
paths
(ACM
ICPC
World
Finals
2010
Solutions
n.d.).
the
exponential
algorithm
we
use
to
nd
all
possible
paths
(ACM
ution
for
this
problem
is
to
prune
hacking
a
complete
search
algorithm.
Therefore,
we
will
not
discuss
this
technique
optimal
solution
in prune
order
that
know
the
contestants
solution
solution
isorder
indeed
tocan
that
the
contestants
solution
is Ifintr
-approximation.
However,
generating
thethe
optimal
solution
is impossible
(or
takes
averify
long
time).
Since
this
approach
is analy
not
some
we
know
that
itsome
is
impossible
to
visit
the
of
the
unvisited
then
we
can
prune
the
path
point
we
know
that
itrest
isinimpossible
to
visitpoints,
the
rest
ofand
the
unvisited
points,
Finals
2010
Solutions
n.d.).
Ifverify
at
know
that
it backtrack
ispoint
impossible
to
rest
ofthe
the
unvisited
points,
then
we
prune
the
path
points,
then
we
can
thevisit
path
and
immediately.
However,
itoptimal
is
not
very
suitable
for
IOI.
Usually,
IOI
problems
require
deep
3.2
Pruning
legiate
Programming
ssible
paths
is
impossible,
the
solution
for
this
problem
is
to
prune
count
the
number
of
ICPC
World
Finals
2010
Solutions
n.d.).
If
at
ble
paths
(ACM
some
point
we
know
that
it
is
impossible
to
visit
the
rest
of
the
unvisited
points,
in
detail.
some
point
we
know
that
it
is
impossible
to
visit
the
rest
of
the
unvisited
points,
then
we
can
prune
the
path
d
Finals
2010
Solutions
n.d.).
If
at
g then
the
optimal
solution
impossible
(or
generating
takes
acan
the
optimal
time).
Since
solution
this
is
approach
impossible
(or
takes
reallyfor
asuitable
long
time).
fordeep
Since
thisa
competitive
programming,
Ilong
will
not
discuss
this
approach
inisIOI
detail.
immediately.
However,
it IOI.
isimmediately.
not
very
suitable
for
IOI.
Usually,
problems
require
analysis
backtrack
However,
it
is
not very
suitable
IOI.
Usually,
IOI
probl
webacktrack
canthe
prune
the
path
ediately.
However,
it deep
isisnot
very
for
Usually,
IOI
problems
require
deep
analysis
from
OI
problems
require
analysis
from
contestant.
Itand
is suitable
rare
that
we
get
Accepted
by
only
"hacking"
anot
complete
search
algorithm.
There
count
the
number
of
ICPC
World
Finals
2010
Solutions
n.d.).
If
at
possible
paths
(ACM
),
which
is
known
to
he
rest
of
the
unvisited
points,
then
we
can
prune
the
path
and
backtrack
immediately.
However,
it get
is
not
very
suitable
for
Usually,
IOI pro
backtrack
immediately.
However,
itcan
is
not
very
for
IOI.
Usually,
problems
require
deep
analysis
fros
s,
then
we
can
prune
the
path
and
This
approach
is
useful
in
some
programming
problems.
In
ACM
International
Collegiate
ve
Ican
will
not
this
competitive
approach
in
programming,
I we
will
not
discuss
this
approach
inIOI.
detail.
the
contestant.
ItTherefore,
isdiscuss
rare
that
we
get
Accepted
by
only
"hacking"
aIOI
complete
search
algorithm.
Therefore
the
contestant.
Itdetail.
issuitable
that
can
Accepted
by only
"hacking"
aProgrammin
complete
blems
require
deep
analysis
from
It programming,
is rare
that
we
get
Accepted
by
only
arare
complete
search
algorithm.
Therefore,
we
mplete
search
algorithm.
we
will
not
discuss
this
technique
in"hacking"
detail.
),
which
is
known
to
isit
the
rest
of
the
unvisited
points,
then
we
can
prune
the
path
and
problem
is
to
prune
itable
for
IOI.
Usually,
IOI
problems
require
deep
analysis
from
the
contestant.
It
is
rare
that
we
can
get
Accepted
by
only
"hacking"
a
complete
the
contestant.
It
is
rare
that
we
can
get
Accepted
by
only
"hacking"
a
complete
search
algorithm.
Therefore,
w
roblems
require
deep
analysis
from
Contest
(ICPC)
World
Finals
2010,
problem
I
(Robots
on
Ice)
required
the
contestant
to
count
the
number
o
will
notindiscuss
this technique
in detail.
discuss this technique in 3.2
detail. Pruning
ethis
search
algorithm.
Therefore,
we will not
technique
detail.
3.3.
Finding
Small
problem
is
todiscuss
prune
ry
for
IOI.
Usually,
IOIconstraints
problems
require
deep
fromin2010
n.d.).
If Paths
at
dSolutions
bysuitable
only
a Therefore,
complete
search
algorithm.
Therefore,
weFinals
will
not
discuss
thisanalysis
technique
detail.
will "hacking"
not
this
technique
in3.2
detail.
te
search
algorithm.
weConstraints
Hamiltonian
with
(ACM
ICPC
World
problem
statement
n.d.),
which
is
known
t
Pruning
3.2 Pruning
3.3
Finding
Small
Constraints
n.d.).
Ifand
atproblem.
epted
bythe
"hacking"
complete
Therefore,
we
nSolutions
prune
path
This aapproach
useful algorithm.
inall
some
competitive
problems.
In for
ACM
Collegia
be
aonly
NP-hard
Whileis search
nding
possible
paths isprogramming
impossible,
the
solution
thisInternational
problem is to
prun
3.3
Finding
Small
Constraints
3.3
Finding
Small
Constraints
3.3
Finding
Small
Constraints
ints
noach
prune
the
path
and
is
useful
in
some
competitive
programming
This
approach
problems.
is
useful
In
in
ACM
some
International
competitive
Collegiate
programming
Programming
problems.
In
ACM
Inte
e deep
fromContest
(ICPC)
World
Finals
2010,
problem
I
(Robots
on
Ice)
required
the
contestant
to
coun
ICPC
World
Finals
2010
Solutions
n.d.).
IfNa
theanalysis
exponential
algorithm
we
use
to
nd
all
possible
paths
(ACM
Suppose
there
an
NP-hard
problem
with
large
N
that
is
impossible
to
solve
exponentially
(e.g.
Suppose
thereisis
an
NP-hard
problem
large

that
is
impossible
to
solve
expo3.3 Finding Small Constraints
3.3 Finding Small Constraints
e
deep
analysis
from
ICPC)
World
Finals
2010,
problem
I
Contest
(Robots
(ICPC)
on
Ice)
World
required
Finals
the
2010,
contestant
problem
to
count
I
(Robots
the
number
on
Ice)
required
of
the
co
rithm.
Therefore,
we
Hamiltonian
Paths
with
constraints
(ACM
ICPC
World
Finals
2010
problem
statement
n.d.),
w
Suppose
there
is
an
NP-hard
problem
with
large
N
that
is
impossible
to
solve
exponentially
(e.g.
N
>
Suppose
there
is
an
NP-hard
problem
with
large
N
that
is
impossible
to
solve
is
an
NP-hard
problem
with
large
N
that
is
impossible
to
solve
exponentially
(e.g.
N
>
50).
some
point
we
know
that
it
is
impossible
to
visit
the
rest
of
the
unvisited
points,
then
we
can
prune
the
path
an
o
solve
exponentially
(e.g.
N
>
50).
nentially we
(e.g.
Sometimes
should
also look
formay
other
small
Sometimes
should also).look
for otherwe
small
constraints
that
help.
Forconstraints
example, a SUBSET-SUM
gs Small Constraints
Suppose
there
is
an
NP-hard
problem
with
large
N
that
is
impossible
to
solv
Suppose
there
is
an
NP-hard
problem
with
large
N
that
is
impossible
to
solve
exponentially
(e.g.
N
>
rithm.
Therefore,
we
an
Paths
with
constraints
(ACM
Hamiltonian
Paths
with
constraints
(ACM
ICPC
World
Finals
2010
problem
statement
n.d.),
ICPC
which
World
is
Finals
known
2010
to
problem
sta
be
a
NP-hard
problem.
While
nding
all
possible
paths
is
impossible,
the
solution
for
this
Sometimes
we
should
also
look
for
other
small
constraints
that
may
help.
For
example,
a
SUBSET-SUM
pro
Sometimes
we
should
also
look
for
other
small
constraints
that
may
help.
For
exam
ve
exponentially
(e.g.
N
>
50).
hould
also
look
for
other
small
constraints
that
may
help.
For
example,
a
SUBSET-SUM
problem
backtrack
immediately.
However,
it isa SUBSET-SUM
notand
verywill
suitable
for
IOI.isUsually,
problems
fro5
For example,
SUBSET-SUM
problem
may help.
For
example,
problem
considered
an
NP-hard
probding
Small
Constraints
isathat
considered
an NP-hard
problem,
not be
solvable
with NIOI
= 100.
Whenrequire
we
aredeep
givenanalysis
the constr
N
that
is
impossible
to
solve
exponentially
(e.g.
N
>
50).
Sometimes
we
should
also
look
for
other
small
constraints
that
may
help.
For
exw
Sometimes
we
should
also
look
for
other
small
constraints
that
may
help.
For
example,
a
SUBSET-SUM
proble
olve
exponentially
(e.g.
N
>
50).
2
hard
problem.
While
nding
all
possible
be
a
paths
NP-hard
is
impossible,
problem.
While
the
solution
nding
for
all
this
possible
problem
paths
is
is
to
impossible,
prune
the
solu
ICPC
World
Finals
2010
Solu
the
exponential
algorithm
we
use
to
nd
all
possible
paths
(ACM
considered
anwill
NP-hard
and
will
not100.
be
N
100.
When
we
are
given
constraint
isthat
considered
an
NP-hard
problem,
and
will
not
solvable
with
=the
100.
When
ample,
aiscontestant.
SUBSET-SUM
problem
NP-hard
problem,
and
will
not
beproblem,
solvable
with
Nsmall
=
When
wewith
are
given
thebe
constraint
that
not
be
solvable
with
. solvable
When
we
are
given
the
constraint
allNusing
thewe
It
is
rare
that
we
can
get
Accepted
by
only
a=problem
complete
search
algorithm.
Therefore,
When
are
given
constraint
alllem,
the and
elements
inside
the
array
are
(e.g.
[0, "hacking"
100]),
this
can
be that
solved
O(N
X )w
D
large
N
that
is
impossible
to
solve
exponentially
(e.g.
N
>
50).
2
straints
that
may
help.
For
example,
a
SUBSET-SUM
problem
2
is
considered
an
NP-hard
problem,
and
will
not
be
solvable
with
N
=
100.
When
is
considered
an
NP-hard
problem,
and
will
not
be
solvable
with
N
=
100.
When
we
are
given
the
constraint
th
2
example,
a
SUBSET-SUM
problem
ICPC
World
Finals
2010
Solutions
n.d.).
If
at
ICPC
World
ential
algorithm
we
use
to
nd
all
possible
the
exponential
paths
(ACM
algorithm
we
use
to
nd
all
possible
paths
(ACM
some
point
we
know
that
it
is
impossible
to
visit
the
rest
of
the
unvisited
points,
then
we
can
pru
all
the
elements
inside
the
array
are
small
(e.g.
[0,
100]),
this
problem
can
be
solved
using
O(N
X
)
Dyna
all
the
elements
inside
the
array
are
small
(e.g.
[0,
100]),
this
problem
can
be
so
nsan
we
given
the
constraint
that
the
elements
inside
the
array
are
small
(e.g.
),
this
problem
can
be
solved
using
inside
the
array
are
small
(e.g.
[0,
100]),
this
problem
can
be
solved
using
O(N
X
)
Dynamic
will
not
discuss
this
technique
in
detail.
beare
solved
using
O(N
X
)
Dynamic
Programming, where X is the upper bound of the elements inside the array. Even though the running
tim
2 can be
lltsolvable
constraints
that
example,
arest
SUBSET-SUM
problem
with
Nupper
100.
When
we
are
given
the
constraint
that
2 where
all
thepoint
elements
array
are
small
(e.g.
[0,
100]),
this
problem
all
the
elements
the
array
are
small
(e.g.
[0,
this
problem
can
solved
using
O(N
Xconstraint.
) Dynam
en
weknow
are
given
the
constraint
that
we
that
it=may
isX
impossible
to
visit
some
the
of
we
the
know
unvisited
itvery
points,
is
impossible
then
we
to
can
visit
prune
the
rest
the
of
path
the
and
unvisited
points
backtrack
immediately.
However,
it
not
suitable
for
IOI.
Usually,
IOI
problems
require
de
Programming,
X
isof
the
upper
bound
ofinside
the
elements
inside
array.
Even
though
the
running
time
o
Programming,
where
Xisthat
is
the
bound
of
thebe
elements
inside
the
array.
Even
help.
Dynamic
Programming,
where
100]),
isthe
the
upper
bound
of
the
elements
inside
solved
using
O(N
)inside
Dynamic
where
X
is
the
bound
ofFor
the
elements
inside
array.
Even
though
thestill
running
time
offor
the
y.
Even
though
the
running
time
the
algorithm
is
exponential
to
the
size
of
the
input,
the
algorithm
is
fast
enough
the
given
2 constraint that
2can
ot
be
solvable
with
N
=
100.
When
we
are
given
the
ally
(e.g.
N
>
50).
0,
100]),
this
problem
be
solved
using
O(N
X
)
Dynamic
Programming,
where
X
is
the
upper
bound
of
the
elements
inside
the
array.
Eve
Programming,
where
X
is
the
upper
bound
of
the
elements
inside
the
array.
Even
though
the
running
time
of
e
solved
using
O(N
X
)
Dynamic
immediately.
However,
it
is
not
very
backtrack
suitable
for
immediately.
IOI.
Usually,
However,
IOI
problems
it
is
not
require
very
suitable
deep
analysis
for
IOI.
from
Usually,
IOI
pro
the
array.
Even
though
the
running
time
of
the
algorithm
is
exponential
to
the
size
of
the
contestant.
It
is
rare
that
we
can
get
Accepted
by
only
"hacking"
a
complete
search
algorithm
algorithm
is
exponential
to
the
size
of
the
input,
the
algorithm
is
still
fast
enough
for
the
given
constraint.
Ano
algorithm
is
exponential
to
the
size
of
the
input,
the
algorithm
is
still
fast
enough
fo
n
though
the
running
time
of
the
onential
size
the this
input,
the algorithm
is still
enough
the too
given
constraint.
nough
forto the
given
constraint.
Another
way
to of
apply
technique
is when
the fast
value
of N for
is Constraints
not
large
(e.g. NAnother
< 40). For example, whilt
3.3
Finding
2 Small
ally
(e.g.
N
>
50).
e.g.
[0,
100]),
this
problem
can
be
solved
using
O(N
X
)
Dynamic
BSET-SUM
problem
elements
inside
the
array.
Even
though
the
running
time
of
the
N"hacking"
algorithm
is
exponential
to
the
size
of
the
input,
the
algorithm
still
fast
enough
algorithm
is
exponential
to
the
size
of
the
input,
the
algorithm
is
still
fast
enough
for
the
constraint.
Anoth
N
ven
though
the
running
time
of
the
the
input,
the
algorithm
is
still
fast
enough
for
the
given
constraint.
Another
way
N/2
stant.
It
is
rare
that
we
can
get
Accepted
the
contestant.
by
only
"hacking"
It
is
rare
a
that
complete
we
can
search
get
Accepted
algorithm.
by
Therefore,
only
we) (e.g.
a complete
will
discuss
technique
inin
detail.
way
to
apply
this
technique
isis)to
when
therun
value
of Nsecond,
tooFor
large
<isuse
40).
For
example,
while
O4
way
apply
this
technique
isnot
when
the
value
ofNN
not
too
large
N
<
the
givenalgorithm
Another
isfor
isconstraint.
when
the
value
of
Nthis
not
too
large
(e.g.
Nis <
40).
example,
while
O(2
)tois
Ntechnique
< 40).
For
example,
while
O(2
fornot
N
= 36
is
unlikely
to
one
we
can,
for(e.g.
instance,
agiven
O(2
Meet
In
The
BSET-SUM
problem
f
the
elements
inside
the
array.
Even
though
the
running
time
of
the
N/2
n
the
constraint
that
e
algorithm
is
still
fast
enough
for
the
given
constraint.
Another
N
N/2
way
to
apply
this
technique
is
when
the
value
of
N
is
not
too
large
(e.g.
N
<a
way
to
apply
this
technique
is
when
the
value
of
N
is
not
too
large
(e.g.
N
<
40).
For
example,
while
O(2
N/2
hscuss
for
the
given
constraint.
Another
there
is
an
NP-hard
problem
with
large
N
that
is
impossible
to
solve
exponentially
(e.g.
N
>
50
apply
this
technique
is
when
the
of

is
not
too
large
(e.g.
).
For
exN/2
this
technique
in
detail.
will
not
discuss
this
technique
in
detail.
for
N
=
36
is
unlikely
to
run
in
one
second,
we
can,
for
instance,
use
a
O(2
)
Meet
In
The
M
algorithm
for
N
=
36
is
unlikely
to
run
in
one
second,
we
can,
for
instance,
use
<ce,
40).
For
example,
while
O(2
)
=
36Suppose
is
unlikely
to
run
in
one
second,
we
can,
for
instance,
use
a
O(2
)
Meet
In
The
Middle
use
aalgorithm
O(2
)
Meet
In
The
Middle
for solving a problem like SUBSET-SUM.
While O(2
) is still exponential
to N , it is much fas
2 algorithm
N
N/2
N
n
the
constraint
that
the
algorithm
is
still
fast
enough
for
the
given
constraint.
Another
N/2
N/2
geut,
O(N
X
)
Dynamic
N
is
not
too
large
(e.g.
N
<
40).
For
example,
while
O(2
)
N/2
N/2
algorithm
for
=
unlikely
to
one
can,
instance,
use
ample,
while
While
algorithm
for
isis
unlikely
to run
run
in
second,
we
can,
for
= 36
isa unlikely
run
one
second,
we
can,
for
instance,
use
aa O(2
)solution.
In The
Midd
<
For)to
example,
while
O(2
)than
Sometimes
also
look
for
other
small
constraints
that
For
example,
athan
proble
N
NSUBSET-SUM
algorithm
solving
problem
like
SUBSET-SUM.
While
O(2
)help.
still
exponential
to
,Meet
much
faster
algorithm
for
solving
a36problem
likemay
SUBSET-SUM.
While
O(2
)itfor
isis still
exponent
a 40).
O(2
Meet
InN
The
Middle
lving
aalgorithm
problem
like
SUBSET-SUM.
O(2
)Nissolve
still
exponential
to
N
,isof
itin
isN
much
faster
xponential
N
,we
itfor
isshould
much
faster
Nto
that
itin
can
is
twice
the
range
using
O(2
)N
3.3
Finding
Small
Constraints
2N/2O(2 ), and the range of N/2
N
N/2
N/2
gese
O(N
X
)
Dynamic
ue
of
N
is
not
too
large
(e.g.
N
<
40).
For
example,
while
O(2
)
N
N
N and
running
time
of
the
ond,
we
can,
for
instance,
a
O(2
)
Meet
The
Middle
N
for
use
a

Meet
In
The
Middle
algorithm
for
solving
a
problem
like
algorithm
for
solving
a
problem
like
SUBSET-SUM.
While
O(2
)
is
still
expone
algorithm
for
solving
a
problem
like
SUBSET-SUM.
While
O(2
)
is
still
exponential
to
N
,
it
is
much
faster
thN
N
a
O(2
)
Meet
In
The
Middle
is
considered
an
NP-hard
problem,
will
not
be
solvable
with
N
=
100.
When
we
are
given
the
constraint
tha
),
the
range
oftwice
NO(2
that
canthe
solve
isusing
twice
range
of solve
N Finding
using
a O(2
)range
solution.
and
of N
that
can
is twice
the
of
N using a O(2
toofO(2
N)N
,solution.
itthat
is and
much
faster
than
range
it can
solve
isFinding
the),itrange
of range
NConstraints
a the
O(2
)it solution.
gntial
a O(2
3.3
Small
3.3
Small
Constraints
N/2
N/2
Nit
N
Nfaster
2
running
time
of
the
second,
we
can,
for
instance,
use
a
O(2
)
Meet
In
The
Middle
ne(2
constraint.
Another
Suppose
there
is
an
NP-hard
problem
with
large
N
that
is
impossible
to
solve
exponentially
SUBSET-SUM.
While

is
still
exponential
to
,
it
is
much
than
.eWhile
O(2
)
is
still
exponential
to
N
,
is
much
faster
than
N
O(2
),
and
the
range
of
N
that
it
can
solve
is
twice
the
range
of
N
using
a
O(
O(2
),
and
the
range
of
N
that
it
can
solve
is
twice
the
range
of
N
using
a
O(2
)
solution.
nential
to
N
,
it
is
much
faster
than
all
the
elements
inside
the
array
are
small
(e.g.
[0,
100]),
this
problem
can
be
solved
using
O(N
X
)
Dynam
) solution.
N/2
3.4
Finding
Special
Cases
N
N
nthere
constraint.
Another
isWhile
an NP-hard
large
Suppose
isimpossible
an
NP-hard
to
solve
problem
exponentially
with
large
(e.g.
N
N
is>a
impossible
50). time
toofsol
range
oftoN
that
itmuch
can
solve
isinside
twice
the
range
ofthough
that
using
SUM.
O(2
), problem
isand
still
exponential
N that
, there
it
is
faster
than
ample,
while
O(2
)where
Sometimes
we
should
also
look
for
other
small
constraints
that
may
help.
For
example,
a SUBSE
ice
the
range
of
NN using
aXthe
O(2
) solution.
O(2
)Programming,
solution.
iswith
the
upper
bound
ofis
the
elements
the
array.
Even
the
running
th
3.4
Finding
Special
Cases
3.4
Finding
Special
Cases
3.4
Finding
Special
Cases
es
N solution.
N
ample,
while
O(2
)
sMeet
should
also
look
for
other
small
Sometimes
constraints
we
that
should
may
help.
also
look
For
for
example,
other
small
a
SUBSET-SUM
constraints
that
problem
may
help.
For
ex
iswe
twice
the
range
of
N
using
a
O(2
)
solution.
In TheThis
Middle
is considered
an size
NP-hard
and
will
not
be
solvable
with
N
=
100.
When
we
are
given
th
algorithm
is is
exponential
the
of 3.4
theproblem,
input,
the
algorithm
is
still
fast
enough
for
the
given
constraint.
Anoth
the
most to
suitable
approach
inFinding
IOI,
and
thus
is
the
main
focus
of
this
paper.
To
solve
IOI
200
Finding Special Cases
Special 3.4
Cases
In
The
Middle
red
an
NP-hard
problem,
and
willIsland
not
isinside
be
considered
solvable
with
an
NP-hard
NNapproach.
=
100.
When
and
we
are
willnd
given
not
be
the
solvable
constraint
with
N
=
100.
When
tMeet
issuitable
much
faster
than
all
the
elements
the
array
are
small
(e.g.
[0,
100]),
this
problem
can
bethat
solved
using
O(
This
is
the
most
suitable
approach
in
IOI,
and
thus
isproblem,
the
main
focus
of
paper.
To
solve
2008
IsN
This
isthe
the
most
suitable
approach
in
IOI,
and
thus
is
the
main
focus
of
this
pa
ting
approach
in IOI
IOI,
and
thus
is
main
focus
of
paper.
To
solve
2008
Island
way
to
apply
this
technique
is
the
value
of
isthis
not
too
large
(e.g.
NIOI
<
40).
For
example,
while
O(2
this
paper.
To
solve
2008
and
IOI
2014
Friend,
wewhen
need
to
use
this
We
must
athis
special
constraint
inIOI
the
probl
Special
Cases
2
This
isin
the
most
suitable
approach
inthis
IOI,
and
thus
main
focus
ofcan
this
N/2
This
issolve
the
most
suitable
approach
IOI,
and
thus
isthe
the
main
focus
of
this
paper.
To
solve
IOI
2008
Isla
tpaper.
is much
faster
than
ments
inside
the
array
are
small
(e.g.
allto
the
[0,
100]),
elements
this
inside
problem
can
array
be
are
solved
small
(e.g.
O(N
[0,
100]),
Xis
)the
Dynamic
problem
be
n.
Programming,
where
X
is
upper
of
the
elements
inside
array.
Even
though
the
run
and
IOI
2014
we
need
to
use
this
approach.
We
must
nd
athe
special
constraint
in
the
problem
and
IOI
2014
Friend,
we
need
to
use
approach.
We
must
nd
special
c
To
IOI
2008
Island
Friend,
we
need
to
use
this
approach.
We
must
nd
a bound
special
constraint
inusing
problem
such
algorithm
for
N
=Friend,
36
is
unlikely
run
inthe
one
second,
we
can,
for
instance,
use
athe
O(2
)this
Meet
InaThe
Midd
pecial
constraint
in
the
problem
such
Finding
Special
Cases
that
this
constraint
allows
the
problem
to
be
solvable
in
polynomial
time.
We
can
check
whether
an
ad
hus
is
the
main
focus
of
this
paper.
To
solve
IOI
2008
Island
and
IOI
2014
Friend,
we
need
to
use
this
approach.
We
must
nd
a
special
N/2
and
IOI
2014
Friend,
we
need
to
use
this
approach.
We
must
nd
a
special
constraint
in
the
problem
su
s.aint
paper.
To
solve
IOI
2008
Island
n.
ming,
where
X
is
the
upper
bound
of
Programming,
the
elements
inside
where
the
X
array.
is
the
Even
upper
though
bound
the
of
the
running
elements
time
inside
of
the
the
array.
Eve
algorithm
is
exponential
to
the
size
of
the
input,
the
algorithm
is
still
fast
enough
for
the
given
con
that
this
constraint
allows
the
problem
to
be
solvable
in
polynomial
time.
We
can
check
whether
an
additi
that
this
constraint
allows
the
problem
to
be
solvable
in
polynomial
time.
We
ca
constraint
in the
problem
such
the
problem
toan
solvable
polynomial time.
WeO(2
can check
whether
an additional
algorithm
for
solving
a be
problem
likeinSUBSET-SUM.
While
) is still
exponential
to N , it is much faster tha
Weallows
can check
whether
additional
nd
thus
theinto
main
focus
of
this
paper.
Tothe
solve
IOI
2008
Island
ach.
WeisNmust
nd
asize
special
constraint
in
problem
such
that
this
constraint
allows
the size
problem
togiven
be
solvable
in polynomial
time.
We
N algorithm
that
this
constraint
the
problem
to
be
solvable
invalue
polynomial
time.
can
check
an
addition
al
constraint
the
problem
is exponential
the
ofallows
thesuch
input,
algorithm
the
algorithm
is exponential
istwice
still
fast
to
enough
for
of
input,
constraint.
the
Another
is
enough
way
to
apply
this
technique
is
the
ofofN
not
too
large
Nwhether
< still
40).fast
For
examp
can
check
whether
an
additional
O(2
), and
the
range
of
N
that
it can
solve
iswhen
the
range
Nisthe
using
aWe
O(2
) (e.g.
solution.
N
N/2
pproach.
We
must
nd
a
special
constraint
in
the
problem
such
able
in
polynomial
time.
We
can
check
whether
an
additional
eply
canthis
check
whether
an
additional
technique
isalgorithm
when
thefor
value
N
toisisapply
not too
thistolarge
technique
when
< 40).
the
For
value
example,
of N
iswhile
not too
O(2
<
N way
=of36
unlikely
run (e.g.
in oneisNsecond,
we
can,
for
instance,
use large
a)O(2(e.g.) N
Mee
Irvin
GUNAWAN
N/2 N/2
eolve
solvable
inJonathan
polynomial
time.
Weone
can
check
whether
an
additional
IOI=2008
Island
for
N
36
is
unlikely
to
run
in
algorithm
second,
we
for
can,
N
=
for
36
instance,
is
unlikely
use
to
a
run
O(2
in
one
)
Meet
second,
In
The
we
can,
Middle
for
instance,
use
algorithm
for
solving
a
problem
like
SUBSET-SUM.
While
O(2
)
is
still
exponential
to
N
,
it
is
Jonathan Irvin GUNAWANJonathan
Irvin Finding
GUNAWANSpecial Cases
GUNAWAN
3.4
N/2
N/2 N
olve
IOI
2008
Island
n
problem
suchO(2
Irvin
GUNAWAN
forthe
solving
a problem
likeNSUBSET-SUM.
algorithm
for
O(2
solving
is
a problem
still
exponential
to range
N , it of
is much
faster
O(2
than
) is
still expone
Jonathan
Irvin
GUNAWAN
), and the Jonathan
rangeWhile
of N
that
it )can
solve
is like
twiceSUBSET-SUM.
the
NWhile
using
a O(2
) solution.
N
N
n
the
problem
such
hether
an
additional
is the
approach
in), the
IOI,
and
thus
the
main
of this
paper.theTorange
solveofIOI
2008 Islan
nd theThis
range
of Nmost
thatsuitable
it can solve
isO(2
twice
andrange
the range
of Nisof
using
N that
a O(2
itfocus
can
) solution.
solve
is twice
N using
aO
hether
an IOI
additional
and
2014 Friend, we need to use this approach.
We
must
nd
a
special
constraint
in
the
problem
suc
3.4 Finding Special Cases
that this constraint allows
the
problem
to
be
solvable
in
polynomial
time.
We
can
check
whether
an
addition
3.4 Finding Special Cases
3.4 Finding Special Cases
This is the most suitable approach in IOI, and thus is the main focus of this paper. To solve
e most suitable approach
in 2014
IOI, and
This
thus
iswe
is
thethe
most
main
focus
approach
this paper.
in IOI,
Tomust
and
solve
thus
IOIisa2008
the
main
Island
focus of this
and IOI
Friend,
need
tosuitable
use
thisof
approach.
We
nd
special
constraint
in th
014 Friend,
we
need
to
use
this
approach.
and
IOI
2014
We
must
Friend,
nd
we
a
need
special
to
constraint
use
this
approach.
in
the
problem
We
must
such
nd
a
special
this constraint allows the problem to be solvable in polynomial time. We can check wheth
Jonathan Irvin that
GUNAWAN
constraint allows the problem to be that
solvable
this in
constraint
polynomial
allows
time.theWe
problem
can check
to bewhether
solvableaninadditional
polynomial time. We

Irvin GUNAWAN

Jonathan Irvin GUNAWAN


Fig. 4. Comparison of O(2N) and O(2N/2) SUBSET-SUM algorithm running time for various
Jonathan
GUNAWAN
input sizes. This experiment
is runIrvin
100 times
for each value of N on a MacBook Pro (Retina,
13-inch, Early 2015).

em. The most common approximation algorithm I found in textbooks


is theApproximation
3.1
OVER problem, which means that the algorithm will not choose more than twice
In real life, when
we cannot
theinoptimal
solution, we can try to nd the solution th
ptimal solution. However, approximation
problems
rarelynd
occur
competitive
2
2
Identifying
Identifying
Intractability
Intractability
2
Identifying
of
of
a
a
Problem
Problem
Intractability
through
through
Reduction
Reduction
ofa(where
Pro
solution.
More
specically,
we
try
to
nd
a
solution
that is not larger
than
J.I. Gunawan
e of the reason is92because to create this kind of problem,
the judges have to
Identifying Intractability
of
a
Problem
through
Reduction
solution
for ais minimisation
problem. The
most common approximation algorithm I f
r to
that
contestants
solution
indeed
We
Weverify
would
would
like
likethe
to
to know
know that
that the
the
problem
problem
that
thatWe
we
we-approximation.
are
would
are attempting
attempting
like to know
isisHowever,
unlikely
unlikely
that the
to
toproblem
have
have an
anthat
immediate
immediate
we are solution.
solution.
attempting
The
The
is
3.4.
Finding
Special
Cases
2-approximation
MIN-VERTEX-COVER
problem,
which
means thatsolution.
the algorithm
will no
impossible
(orknow
takes
a isis
long
time).
is not
really
suitable
for
would
to
that
the
problem
thatthis
we approach
aremost
attempting
is
unlikely
have
immediate
The
most
mostlike
common
common
way
way
to
to apply
apply
aaSince
well-known
well-known
technique
technique
common
called
called
way
reduction.
reduction.
is totoapply
Suppose
Suppose
aanwell-known
we
we know
know
technique
that
that problem
problem
calledXXredu
isis
number of
vertices than
the
optimal solution.
However,
approximation
problems ra
ot
discuss this
in we
detail.
t common
way
is
athe
well-known
technique
called
reduction.
we
know
that
problem
X
impossible
impossible
to
toapproach
solve,
solve,
and
and
we
also
also know
know that
that
we
weimpossible
can
can solve
solve problem
problem
to
solve,XXand
by
bySuppose
using
we
using
also
problem
problem
know
that
YY as
as
we
aa black-box
black-box
can
solve11.problem
. IfIfiswe
we can
can
Xb
22to apply
Identifying
Identifying
Intractability
Intractability
of
of
a
a
Problem
Problem
through
through
Re
Re
programming
(especially
IOI).
One
of
the
reason
isfocus
because
to paper.
create
this
kind
of pro
1 To
This
is
the
most
suitable
approach
in
IOI,
and
thus
is
the
main
of
this
ossible
solve, and
we
also
know
that
we
can
solve
problem
X
by
using
problem
Y
as
a
black-box
.
If
we
can
solve
solvetoproblem
problem
Y,
Y,
then
then
we
we
can
can
solve
solve
problem
problem
X
X
solve
as
as
well.
well.
problem
Therefore,
Therefore,
Y,
then
problem
problem
we
can
Y
Y
solve
is
is
also
also
problem
impossible
impossible
X
as
to
well.
to
solve.
solve.
Therefore,
pr
N/2
omparison of O(2N
) and
O(2
)toSUBSET-SUM
algorithm
running
time
for
various
input
sizes.
This
know
the
optimal
solution
in order
to
verify
that
the
contestants
solution
isimmediate
indeed We
We
would
would
like
likeproblem
to
know
know
that
the
the
problem
problem
that
that
we
we
are
are
attempting
attempting
is
is
unlikely
unlikely
to
to
have
have
an
an
immediate
IOI
2008
Island
and
IOIwell.
2014
Friend,
we
need
to
use
this
approach.
We
must
find
e problem Y, 3.2
thensolve
wePruning
can
solve
Xthat
as
Therefore,
problem
Y
is
also
impossible
to
solve.
NN
N/2
N/2
Figure
4:
Comparison
ofof
)Pro
) )NSUBSET-SUM
running
time
for
variou
Figure
4:of
Comparison
O(2
)and
and
SUBSET-SUM
algorithm
running
time
for
vario
N/2
NO(2
is run 100 times for
each
value
N4:on
atoMacBook
(Retina,
13-inch,
Early
2015)
generating
the
optimal
solution
is
impossible
(or
takes
athe
long
time).
Since
this
approac
Figure
4:O(2
Comparison
of
O(2
)N/2
and
O(2
)algorithm
SUBSET-SUM
algorithm
runnin
Figure
Comparison
O(2
)O(2
and
O(2
)problems
SUBSET-SUM
algorithm
running
time
for
most
common
common
way
way
isis
to
apply
apply
aaof
well-known
well-known
technique
technique
called
called
reduction.
reduction.
Suppose
Suppose
we
we
know
know
that
tha
special
constraint
in
the
problem
such
that
this
constraint
allows
problem
to
be
We
We are
are using
usingamost
NP-hard
NP-hard
problems
problems
for
for
illustration.
illustration.
We
Recall
Recall
are
that
that
using
NP-hard
NP-hard
NP-hard
problems
problems
have
have
for
illustration.
yet
yet
to
to
be
be
solved
solved
Recall
in
in
polynomial
that
polynomial
NP-har
N
N/2
Figure
4:
Comparison
of
O(2
)
and
O(2
)
SUBSET-SUM
algorithm
running
time
foE
experiment
is
run
100
times
for
each
value
of
N
on
a
MacBook
Pro
(Retina,
13-inch,
Early
20
algorithm
running
time
for
various
input
sizes.
This
experiment
is
run
100
times
for
each
value
of
N
on
a
MacBook
Pro
(Retina,
13-inch,
Early
2
mpetitive
programming
problems.
In
ACM
International
Collegiate
Programming
competitive
programming,
I
will
not
discuss
this
approach
in
detail.
SUBSET-SUM
algorithm
running
time
for
various
input
sizes.
This
experiment
is
run
100
times
for
each
value
of
N
on
a
MacBook
Pro
(Retina,
experiment
is
run
100
times
for
each
value
of
N
on
a
MacBook
Pro
(Retina,
13-inch,
N
N/2
solvable
in
polynomial
time.
We
can
check
whether
an
additional
constraint
causes
a
impossible
impossible
to
to
solve,
solve,
and
and
we
we
also
also
know
know
that
that
we
we
can
can
solve
solve
problem
problem
X
X
by
by
using
using
problem
problem
Y
Y
as
as
a
a
black-b
black-b
Wetime
are using
NP-hard
forMIN-VERTEX-COVER
illustration.
Recall
that
NP-hard
problems
have
yet
to befor
solved
inaapolynomial
time
for
for4:more
more
than
thanproblems
44 decades.
decades.
time
for is
more
isfor
aa graph
graph
than
problem
4problem
decades.
that
that
MIN-VERTEX-COVER
involves
involves
nding
nding
minimum
minimum
is sizes.
a 13-inch,
graph
subset
subset
pro
Figure
Comparison
of O(2
)MIN-VERTEX-COVER
and O(2
)100
SUBSET-SUM
algorithm
running
time
various
input
This
experiment
is
run
times
each
value
of
N
on
a
MacBook
Pro
(Retina,
E
ok
Pro
(Retina,
13-inch,
Early
2015)
0, on
problem
I (Robots
on
Ice)
required
the
contestant
to count
number
of
N
MacBook
Pro
(Retina,
13-inch,
Early
2015)
problem
to
bein
solvable
in
polynomial
time
using
the
reduction
proof
of
the
original
N
N/2
solve
solve
problem
problem
Y,
Y,
then
then
we
we
can
can
solve
solve
problem
problem
X
Xthe
as
as
well.
well.
Therefore,
Therefore,
problem
YY2015)
is(withis
also
also
impossible
impossible
auses
aa problem
torun
be100
solvable
polynomial
time
using
the
reduction
proof
of
the
original
problem
for
than
decades.
MIN-VERTEX-COVER
is
aits
graph
problem
involves
nding
avarious
minimum
subset
of
ofmore
nodes
nodes
such
such
that
that
for
for
every
every
edge,
edge,
at
atO(2
least
least
one
one
of
of
of
nodes
its
endpoint
endpoint
such
that
isisPro
in
for
inthat
the
the
every
subset.
subset.
edge,
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
atproblem
least
one
ofprobits
endpoint
isisto
ato
in
a
experiment
is4N
times
for
each
value
of
N
on
a
MacBook
(Retina,
13-inch,
Early
Figure
4:
Comparison
of
O(2
)
and
)
SUBSET-SUM
algorithm
running
time
for
input
sizes.
This
N
N/2
N/2
ts (ACMofICPC
World
Finals
2010
problem
statement
n.d.),
which
isSUBSET-SUM
known
to
Figure
of
O(2
)bebe
and
O(2
)additional
algorithm
running
time
various
mparison
O(2for
)of
and
O(2
)Comparison
SUBSET-SUM
algorithm
running
time
forathe
various
input
sizes.
This
lem
(without
the
additional
constraint),
and
whether
proof
still
holds
given
the
constraint
causes
acauses
problem
to
in
time
using
the
reduction
proof
of
the
orig
constraint
causes
aproof
problem
to
solvable
inpolynomial
polynomial
time
using
the
reduction
proof
of
the
or
3.2
Pruning
tional
constraint),
and
check
the
still
holds
the
constraint
to
theone
problem.
odes
such
that
every
edge,
at
least
one
of
endpoint
ischeck
in
the
subset.
MAX-INDEPENDENT-SET
isfor
aproof
graph
graph
problem
problem
of
nding
nding
a4:
awhether
maximum
maximum
subset
subset
of
of
graph
nodes
nodes
problem
such
such
that
that
of
nding
for
for
every
every
maximum
edge,
edge,
at
at
most
most
subset
one
of
of
of
nodes
its
its
endpoint
endpoint
such
that
isis for
in
in
experiment
is run
100
times
for
each
value
of
N
on
asolvable
MacBook
Pro
(Retina,
13-inch,
Early
2015)
constraint
causes
agiven
problem
to
bein
solvable
in
polynomial
time
using
the
reductio
constraint
aits
problem
to
be
solvable
polynomial
time
using
the
reduction
of
ding
all
possible
paths
is
impossible,
the
solution
for
this
problem
is
to
prune
experiment
is
run
100
times
for
each
value
of
N
on
a
MacBook
Pro
(Retina,
13-inch,
Early
201
additional
constraint
to
the
problem.
run
100
times
for
each
value
of
N
on
a
MacBook
Pro
(Retina,
13-inch,
Early
2015)
constraint
causes
a
problem
to
be
solvable
in
polynomial
time
using
the
reduction
proof
of
out
additional
constraint),
and
check
whether
the
proof
still
holds
given
the
additional
constra
ing
the
reduction
proof
of
the
original
problem
(without
the
additional
constraint),
and
check
whether
the
proof
still
holds
given
the
additional
constr
We
We
are
are
using
using
NP-hard
NP-hard
problems
problems
for
for
illustration.
illustration.
Recall
Recall
that
that
NP-hard
NP-hard
problems
problems
have
have
yet
yet
to
to
be
be
solved
solve
h the
problem
of using
nding
a we
maximum
subset
of
nodes
that
for
everyand
atthe
most
one
ofholds
its
endpoint
in show
the subset.
subset.
Suppose
Suppose
we already
already
know
know
that
that
MIN-VERTEX-COVER
MIN-VERTEX-COVER
thesuch
subset.
Suppose
iswe
isedge,
aaalready
NP-hard
NP-hard
know
problem.
problem.
that
MIN-VERTEX-COVER
Therefore,
Therefore,
we
weisInternationa
can
can
show
lynomial
time
the
reduction
proof
of
the
problem
(without
the
additional
constraint),
check
whether
the
proof
stillACM
holds
given
theis
out
the
additional
constraint),
and
check
whether
proof
still
given
the
additional
This
approach
isinoriginal
useful
some
competitive
programming
In
causes
apaths
problem
to be
solvable
polynomial
time
using
the
proofproblems.
of the
original
problem
(withICPC
World
Finals
2010
Solutions
n.d.).
at
toconstraint
ndgiven
all possible
(ACM
We
will
give
we
example
ofin
aproblem
special
case
in
a reduction
NP-hard
Suppose
we
out
the
additional
constraint),
andis
check
whether
the problem.
proof
still
holds
given
the
additional
holds
the
additional
to
the
time
time
for
more
more
than
than
4one
4also
decades.
decades.
MIN-VERTEX-COVER
MIN-VERTEX-COVER
iswe
is If
aaaaproblem.
graph
graph
problem
that
that
involves
involves
nding
nding
aaaam
m
give
we
onestill
example
offor
aconstraint
special
case
in
aaproblem.
NP-hard
problem.
Suppose
have
aisproblem
function
withwe
the
subset.
Suppose
we
already
know
that
MIN-VERTEX-COVER
areducing
NP-hard
Therefore,
can
show
that
that
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
is
is
also
a
NP-hard
NP-hard
that
MAX-INDEPENDENT-SET
problem
by
by
reducing
MIN-VERTEX-COVER
MIN-VERTEX-COVER
also
a
NP-hard
problem
problem
problem
by
into
into
reduc
er
the
proof
holds
given
the
additional
constraint
to
the
problem.
Contest
(ICPC)
World
Finals
2010,
problem
Iand
(Robots
onofIce)
required
the
contestant
out
the
additional
constraint),
and
check
whether
the
proof
still
holds
given
the
additional
constraint
to
the
problem.
constraint
causes
a
problem
to
be
solvable
in
polynomial
time
using
the
reduction
proof
the
original
problem
(withossible
to
visit
the
rest
of
the
unvisited
points,
then
we
can
prune
the
path
have
a
function
with
the
following
formula
We
give
one
example
of
case
inthe
NP-hard
problem.
Suppose
we
have
a
We
will
give
we
one
example
ofafor
aspecial
special
case
in
aspecial
NP-hard
problem.
Suppose
have
nodes
nodes
such
such
that
that
for
for
every
every
edge,
edge,
at
at
least
least
one
one
ofspecial
its
endpoint
endpoint
isThis
inNP-hard
the
the
subset.
subset.
MAX-INDEPEND
MAX-INDEPEND
N
N/2
rmula
MAX-INDEPENDENT-SET
iswill
also
awill
NP-hard
problem
by
reducing
aits
MIN-VERTEX-COVER
problem
into
awe
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
problem.
problem.
MAX-INDEPENDENT-SET
problem.
constraint
causes
awe
problem
to
be
solvable
inexample
polynomial
time
using
the
reduction
proof
of
the
origi
ses
a) problem
to
beof
inHamiltonian
polynomial
time
using
the
reduction
proof
of
original
problem
We
will
give
we
one
of
aasizes.
case
in
a (withNP-hard
problem.
Su
We
give
we
one
example
of
aof
case
inis
ain
problem.
Suppose
we
(2
and
O(2suitable
)ofsolvable
SUBSET-SUM
algorithm
running
time
various
input
Paths
with
constraints
(ACM
ICPC
World
Finals
2010
problem
statement
out
thevery
additional
constraint),
and
check
whether
the
proof
still
holds
given
the
additional
constraint
to
the
problem.
it
is
not
for
IOI.
Usually,
IOIgive
problems
require
deep
analysis
from
We
will
we
one
example
of
a
special
case
in
a
NP-hard
problem.
Suppose
we
following
formula
ard
problem.
Suppose
we
have
a
function
with
the
following
formula
graph
graph
problem
problem
of
of
nding
nding
a
a
maximum
maximum
subset
subset
of
nodes
nodes
such
such
that
that
for
for
every
every
edge,
edge,
at
at
most
most
one
one
of
of
its
its
X-INDEPENDENT-SET
problem.
out
the
additional
constraint),
and
check
whether
proof
still
holds
given
the additional
constrai
onal
constraint),
and
check
the
proof
stilla formula
holds
given
the
additional
constraint
toiswe
the
problem.
case
ineach
a NP-hard
problem.
Suppose
we
have
function
the
following
following
formula

s forget
value
of
Nonly
on
awhether
MacBook
Pro
(Retina,
13-inch,
Early
2015)
be a NP-hard
problem.
While
nding
allthe
possible
paths
impossible,
the solution
for
We
will
give
we
one"hacking"
example
a special
case
in
a with
NP-hard
problem.
have
a function
with the
can
Accepted
by
aofcomplete
search
algorithm.
Therefore,
weSuppose
following
formula
the
the
subset.
subset.
Suppose
Suppose
we
we already
already
know
know
that
that
MIN-VERTEX-COVER
MIN-VERTEX-COVER
isis aa NP-hard
NP-hard problem.
problem. Therefore
Therefor
1,
n
=
1

n
=
2

We
We
will
will
rst
rst
prove
prove
the
the
following
following
two
two
lemmas.
lemmas.
We
will
rst
prove
the
following
two
lemmas.
N following
N/2

ICPC
World
Finals
2
the
exponential
algorithm
we
use
to
nd
all
possible
paths
(ACM
f
(n)
=
formula
We
will
give
we
one
example
of
a
special
case
in
a
NP-hard
problem.
Suppose
we
have
a
function
with
the
) and O(2
) SUBSET-SUM
algorithm running time
foraavarious
sizes. by
This
etail.
1,1,input
nn=
1MIN-VERTEX-COVER
n
=MIN-VERTEX-COVER
1nthe
that
MAX-INDEPENDENT-SET
isproblem.
is also
also
NP-hard
NP-hard
problem
problem
by
reducing
reducing
aawith

We
willone
rstexample
prove that
the
We
will
give
we+
one
example
of
a2impossible
special
case
a NP-hard
problem.
Suppose
we
=2have
1then
naw
=
1,invisit
=n=1=22points,
nn=
f two
(n
lemmas.
1)
f (n
2),
n
>(n)
ve we
of following
aMAX-INDEPENDENT-SET
special
case
in
awe
NP-hard
Suppose
we
have
a1,
function
f
(n)
=
f
=
some
point
know
that
it
is
to
the
rest
of
the
unvisited
following
formula
ortoLemma
each
value
of
on
MacBook
Pro the
(Retina,
13-inch,
Early
2015)
be solvable
polynomial
time
using
reduction
proof
problem
(withf1,1)
(n)
=
f (n)
=

Lemma
1.
1.
Lemma
1.of Ifthe
Ifin
If N
SS

VVa is
is an
an
INDEPENDENT-SET
INDEPENDENT-SET
of
of graph
graph
S
G(V,
G(V,

VE),
E),
then
an
then
VV

2),
SS2),
isis n
aanVERTEX-COVER
VERTEX-COVER
of
of the
theE
n = of
1 graph
n = 2G(V,
MAX-INDEPENDENT-SET
problem.
problem.
foriginal

1)
++
fINDEPENDENT-SET
>
f(n
(n
is
f(n
(n
2(n
n following
= 1 nbacktrack
=formula
2
mula n = 1 n = 2MAX-INDEPENDENT-SET
fE),
(n)
=not
fa
(n

1)IOI.
+>2fto
22),IOI
nthe
>2
fto
(n

1)
+
fVERTEX-COVER
(n
2),
nknow
>
1,
n
=
1

n
=
2
immediately.
However,
it
is
very
suitable
for
Usually,
problems
r
the
sequence
F
=
{f
(n)}
,
and
we
dene
F
(N
)
to
be
the
rst
N
terms
of
F
.
We
want
t),
and
check
whether
the
proof
still
holds
given
the
additional
constraint
the
problem.
mma
1.
If
S

V
is
an
INDEPENDENT-SET
of
graph
G(V,
then
V

S
is
of
N/2
graph
graph
G(V,
G(V,
E)
E)
graph
G(V,
E)

n=1
3.3
Finding
Small
Constraints
)),
and
SUBSET-SUM
algorithm
running
time for various
f (n This
1) + f (n 2), n > 2
f (n) =
n+O(2
>
2(n )2),

input sizes.

1)
f
n
>
2

We
consider
the
sequence
F
=
{f
(n)}
,
and
we
dene
F
(N
)
to
be
the
rst
N
terms
of
F
.
We
consider
the
sequence
F
=
{f
(n)}
,
and
we
dene
F
(N
)
to
be
the
rst
N
terms
of
F
We
consider
the
sequence
,
and
we
define

to
be
the
first

the
contestant.
It
is
rare
that
we
can
get
Accepted
by
only
"hacking"
a
complete
search
1,
n
=
1

n
=
2
can
create
a
partition
of
F
(N
)
into
two
disjoint
multisets
A
and
B
such
that
the
sum
of
all
elements
n=1
n=1
ffollowing
(n

1)
+
f=
(n
original
2),F n=1
n {f
>
2 we
hbe
G(V,
E) in
We
consider
the
sequence
=
(n)}
, and we
dene
F=(N
) to
rs
consider
the
sequence
{f
(n)}
, and
dene
F (N
)
tonbe
the
rstbeNthe
term
n=1
We
will
willWe
rst
rst
prove
prove
the
the
following
two
lemmas.
lemmas.
each
value
ofus
Nassume
on aWe
MacBook
Pro
13-inch,
Early
solvable
polynomial
time
reduction
proof
of
the
(with1,
n
=
2A,
fS
(n)
=
problem
1,
n two
=F
1of

n2015)
=
2Therefore,
Proof.
Proof.
Proof.
Let
Let
us
assume
that
that
Vusing
VB

Sthe
is(Retina,
is
not
not
VERTEX-COVER.
VERTEX-COVER.
Let
us
assume
Therefore,
that
Vthere
there
dene
SReduction
are
is
are
two
a 1vertices
vertices
VERTEX-COVER.
A,
B
B

/
/that
VN
V

The
SS s
We
consider
the
sequence
F
=
{f
(n)}
, into
and
we
Ftwo
(N
)A
be
the
rst
term
whether
we
can
create
partition
of
F
)partition
multisets
A
and
B
such
the
ntifying
ntifying
Intractability
Intractability
of
of
a
a
Problem
Problem
through
through
Reduction
N
)to
tothe
be
the
rst
Nto
terms
of
F
.
We
want
toaathis
know
with
large
N
that
whether
isof
impossible
can
create
to
solve
a(n
partition
exponentially
F(N
(N
(e.g.
)into
into
Ntwo
two
>
50).
disjoint
multisets
and
B
such
that
the
case
terms
.we
We
want
to
know
whether
we
can
create
adisjoint
partition
ofnot
to
into
two
will
not
discuss
technique
in
detail.
n=1
al
sum
of
all
elements
in
fpartition
(n)
=
ample
of
a
special
in
a
NP-hard
problem.
Suppose
we
have
a
function
with
the
f
(n)
=
f

1)
+
f
(n

2),
n
>
2
dblem
we
dene
F
(N
)
be
the
rst
N
terms
of
F
.
We
want
to
know
whether
we
can
create
a
of
F
(N
)
into
two
disjoint
multisets
A
and
B
whether
we
can
create
a
of
F
(N
)
two
disjoint
multisets
A
and
B
such
tha

and
check
whether
the
proof
still
holds
given
the
additional
to
the
problem.
We
consider
thedisjoint
sequence
{f
,create
and
we
dene
(N
)F
to
be
rst
N
terms
of
Fthe
.BWe
want
know
n=1
fin
(n

1)
+the
f (n

2),
nAs
>
2Since
of.
Let
us
that
Vconnecting

is=
not
aV+
VERTEX-COVER.
Therefore,
there
are
vertices
A,

/are
V a
fF
(n

1)
fiscan
(n
2),
nA,
>
and
and
there
there
isconstraints
is an
an
edge
edge
connecting
A
A(n)}
and
and
B.
B.
Since
Since
and
there
B
B2
/constraint

/is
VVF
an

edge
S,
S,
we
we
connecting
have
have
A,
A,
B
Btwo
A

and
S.
S.
As
B.
A
A
and
and
B
A,
B
B
are
/a
connected
connected
V
S, we
whether
aA,
partition
of
(N
)problem
into
two
disjoint
multisets
A
and
BSto
such
th
Vwe
and

such
that
the
sum
of
all
elements
in
is
equal
toV
sum
inthat
Amultisets
is
equal
to
the
sum
of
all
elements
in
B
multisets
A assume
and
B
such
the
sum
of
all
elements
small
in
that
A
isS
may
equal
help.
to
the
For
sum
example,
ofsum
all
aof
elements
SUBSET-SUM
B
Lemma
Lemma
1.
1.
If
If
SS

is
an
an
INDEPENDENT-SET
INDEPENDENT-SET
of
of
graph
graph
G(V,
G(V,
E),
E),
then
then
V

S
S
is
is
VERTEX-C
VERTEXo other
two
disjoint
multisets
A
and
B
such
that
the
sum
of
all
elements
in
A
is
equal
to
the
sum
of
all
elements
in
B
in
A
is
equal
to
the
all
elements
in
B

whether
can
create
a partition
of
F
(N
),the
into
two
disjoint
multisets
A
and
Bnot
such
that
the
ofwant
all
elements
We
the
sequence
F
=
{f
(n)}
and
we
dene
Fwe
(N
)This
to
be
the
rst
N
terms
of
F
.sum
We
toSSknow
ke
ke
to
to will
know
know
that
that
the
the
problem
problem
that
that
we
we
are
are
attempting
attempting
is
unlikely
unlikely
to
to
have
have
an
an
immediate
immediate
solution.
solution.
The
The
there
isconsider
edge
connecting
A
and
B.
Since
A,
Bsum

/{f
Vis

S,
have
B

S.
As
and
B
are
connected
n=1
by
by
an
an
edge,
edge,
we
we
note
note
that
that
an
edge,
note
that
S
S
isis
not
an
an
INDEPENDENT-SET.
INDEPENDENT-SET.
This
is
is
athat
aof
S
contradiction.
contradiction.
isF
INDEPENDENT-SET.
Therefore
Therefore
V

of
all
elements
in
not
.sequence
eand
solvable
inwe
polynomial
time
using
the
reduction
proof
of
the
original
problem
(within
A
iswe
equal
to
of
all
elements
inA,
B
not
be
solvable
with
N
=the
100.
When
we
are
given
the
constraint

graph
graph
G(V,
G(V,
E)
E)
ks
like
a an
classic
PARTITION
problem.
PARTITION
problem
is3.3
by
reduction
from
SUBSETWe
consider
Fby
=
(n)}
,aNP-hard
and
we
dene
(N
)Aan
to
beConstraints
the
rst
N Vterms
ofisisThi
Faa.
he
sequence
F
=
{f
(n)}
,
and
dene
F
(N
)
to
be
the
rst
N
terms
F
.
We
want
to
know
Finding
Small

n=1
n=1
mple
of
a
special
case
in
a
NP-hard
problem.
Suppose
we
have
function
with
the
in
A
is
equal
to
the
sum
of
all
elements
in
B
whether
we
can
create
a
partition
of
F
(N
)
into
two
disjoint
multisets
A
and
B
such
that
the
sum
of
all
elements
2
on
on
way
way
is
to
to
apply
apply
a
a
well-known
well-known
technique
technique
called
called
reduction.
reduction.
Suppose
Suppose
we
we
know
know
that
that
problem
problem
X
X
is
is
n
edge,
we
note
that
S
is
not
an
INDEPENDENT-SET.
This
is
a
contradiction.
Therefore
V

S
is
a
This
looks
like
a
classic
PARTITION
problem.
PARTITION
problem
is
NP-hard
by
VERTEX-COVER.
VERTEX-COVER.
ndVERTEX-COVER.
check
the
proof
still
holds
given
the
additional
constraint
to) two
the
problem.
This
like
classic
PARTITION
PARTITION
problem
isin
bybyreduct
are
small
100]),
this
This
problem
looks
like
can
aThis
be
solved
using
O(N
X
Dynamic
PARTITION
problem
isNP-hard
NP-hard
reduc
1,value
na=
1classic
=PARTITION
2like
efore,
for whether
a partition
large[0,
of(N
N
itlooks
is
unlikely
to
be
toofA
nd
an
algorithm
that
nds
B
ansuch
whether
can
create
a
partition
(N
)problem.
into
disjoint
multisets
A problem
and
B
that
the
su
an
create
a(e.g.
of
F
), we
into
two
disjoint
multisets
Bproblem.
such
that
the PARTITION
sum
ofA
all1and
elements
looks
aFand
classic
PARTITION
problem.
is by
NP
This
looks
like
an able
classic
PARTITION
problem.
isproblem
NP-hard
1PARTITION
in
Af (n)
isand
equal
to
the
sum
ofTherefore,
all
elements
in
B
=
Proof.
Proof.
Let
Let
us
us
assume
assume
that
that
VVlarge

Svalue
Svalue
isisby
not
not
aN
aNVERTEX-COVER.
VERTEX-COVER.
Therefore,
Therefore,
there
are
are
two
two
vertices
vertices
A
ooN
solve,
solve,
and
we
we
also
also
know
know
that
that
we
we
can
can
solve
solve
problem
problem
XX
by
using
using
problem
problem
YY
as
as
ato
a black-box
black-box
..nd
Ifnd
Ifthere
we
we
can
can
Suppose
there
is
an
NP-hard
problem
with
large
N
that
is
impossible
to
solve
expo
reduction
from
SUBSET-SUM.
Therefore,
for
a
large
value
of
,
it
is
unlikely
to
be
TEX-COVER.
This
looks
like
a
classic
PARTITION
problem.
PARTITION
problem
is
NP-hard
by
SUM.
for
a
large
of
,
it
is
unlikely
to
be
able
to
an
algorithm
that
n
problem
is
NP-hard
by
reduction
from
SUBSETer
bound
of
the
elements
SUM.
inside
Therefore,
the
array.
for
Even
a
though
the
of
running
,
it
is
time
unlikely
of
the
be
able
to
an
algorithm
that

y.
However,
this
sequence
is
dened
in
a
very
special
way,
in
the
sense
that
F
is
dened
using
the
in
A
is
equal
to
the
sum
of
all
elements
in
B
toLemma
the
sum
of
all
elements
in
B
em.
PARTITION
problem
is
NP-hard
by
reduction
from
SUBSETSUM.
Therefore,
for
a
large
value
of
N
,
it
is
unlikely
to
be
able
to
nd
an
at
SUM.
Therefore,
for
a
large
value
of
N
,
it
is
unlikely
to
be
able
to
nd
an
algorithm
f
(n

1)
+
f
(n

2),
n
>
2
Lemma
2.
2.
Lemma
2.
If
If
S
S

V
V
is
is
a
a
VERTEX-COVER
VERTEX-COVER
of
of
graph
graph
G(V,
G(V,
If
S
E),
E),

then
V
then
is
V
a
V
VERTEX-COVER

S
S
is
is
an
an
INDEPENDENT-SET
INDEPENDENT-SET
of
graph
G(V,
of
E),
of
the
the
the
This
looks
like
a
classic
PARTITION
problem.
PARTITION
problem
is
NP-hard
by
reduction
from
SUBSETand
and
there
there
is
an
an
edge
connecting
connecting
Asequence
and
and
B.
B.
Since
Since
A,
A,
B
B

/
/away.
Vconstraints
Vvery

S,
S,
we
we
have
have
A,
A,
B
Bthe

S.
S.
As
Asalgorithm
A
Athat
and
and
B
B
ancan
m
m
Y,
then
we
we
can
solve
solve
problem
problem
XXedge
as
as
well.
well.
Therefore,
Therefore,
problem
problem
isisefficient
also
also
impossible
impossible
to
to
solve.
able
find
an
algorithm
that
finds
we
and
for
in
an
However,
this
sequence
Sometimes
we
should
also
look
other
that
may
help.
For
example,
le
ofthe
athen
special
case
into
aecient
NP-hard
problem.
Suppose
have
aYY
function
with
the
SUM.
Therefore,
for
aA
value
of
N
,small
it
is
tosolve.
be
able
nd
an
ecient
way.
However,
this
sequence
isin
dened
in
way,
into
sense
that
is
ble
to
nd
algorithm
that
nds
A
and
B
in
an
way.
However,
this
is
dened
in
aunlikely
very
special
way,
in
the
ofY,
input,
the
algorithm
isis
still
fast
enough
for
the
given
Another
F
ned
recurrence.
we
should
inspect
the
formula
more
unlikely
be
able
tofor
nd
an
algorithm
that
nds
Alarge
and
Bconstraint.
an
ecient
way.
However,
this
sequence
is
dened
in
a very
special
way,
inFan
the
ecient
However,
this
sequence
is
dened
inalgorithm
aspecial
very
special
way,
insense
the
sense
th

mma
2.
Ifto
Slooks

V,Therefore,
is
aan
VERTEX-COVER
of
graph
G(V,
E),
then
Vproblem

S
isclosely.
an
INDEPENDENT-SET
of
the
1,E)
n)way.
=
1be

nNP-hard
=
2recurrence
graph
graph
G(V,
G(V,
E)
graph
G(V,
E)
SUM.
Therefore,
a
large
value
of
N
,
it
is
unlikely
to
be
able
to
nd
an
that
nds
A
and
B
in
This
like
a
classic
PARTITION
problem.
PARTITION
is
NP-hard
by
reduction
from
SUBSETN
F
=
{f
(n)}
and
we
dene
F
(N
to
the
rst
N
terms
of
F
.
We
want
to
know
by
by
an
edge,
edge,
we
we
note
note
that
that
S
S
is
is
not
not
an
an
INDEPENDENT-SET.
INDEPENDENT-SET.
This
This
is
is
a
a
contradiction.
contradiction.
Therefo
Therefo
is
defined
in
a
very
special
way,
in
the
sense
that
is
defined
using
the
aforementioned
is
considered
an
problem,
and
will
not
be
solvable
with
N
=
100.
When
we
are
n=1
ecient
way.
However,
this
sequence
is dened
in
a recurrence
very
special
way,
inmore
the
th
aforementioned
recurrence.
Therefore,
should
inspect
the
formula
closely.
way,
the
that
F
issense
dened
using
the
en
the
value
ofPARTITION
Nsense
isway,
not
aforementioned
too
large
(e.g.
recurrence.
<
40).
Therefore,
For
example,
we
should
while
O(2
inspect
)inspect
the
recurrence
more
closely.
fin
(n)
= in special
This
looks
like
aN
classic
PARTITION
problem.
PARTITION
problem
isformula
NP-hard
bysense
reductio
secial
like
aa classic
problem.
PARTITION
problem
iswe
NP-hard
by
reduction
from
SUBSETed
very
in
the
that
F
ismultiples
dened
using
the
aforementioned
recurrence.
Therefore,
we
should
inspect
recurrence
aforementioned
recurrence.
Therefore,
we
should
the
recurrence
more
hsing
G(V,
E)
ecient
way.
However,
this
sequence
dened
a of
very
special
way,
in
sense
that
F
isthe
dened
the
Any
consecutive
subsequence
of
Finstance,
with
length
three
can
be
partitioned
into
two
multisets
SUM.
Therefore,
afclosely.
large
value
of
N
it
is
unlikely
to
be
able
to
nd
anthe
algorithm
that
nds
Aformula
andusing
informu
ancc
fproblems
(n

1)for
+
(n

2),
nRecall
>
2is,should
recurrence.
Therefore,
we
inspect
the
recurrence
formula
more
closely.
N/2
artition
of
Fformula
(N
) into
two
disjoint
multisets
Athat
and
Bin
such
that
the
sum
of
all
elements
VERTEX-COVER.
VERTEX-COVER.
sing
NP-hard
NP-hard
problems
for
for
illustration.
illustration.
Recall
that
NP-hard
NP-hard
problems
problems
have
have
yet
yet
to
to
be
be
solved
solved
in
in
polynomial
polynomial
all
the
elements
inside
the
array
are
small
(e.g.
[0,
100]),
this
problem
can
beB solved
aforementioned
recurrence.
Therefore,
we
should
inspect
the
recurrence
formula
more
recurrence
more
o
run
in
one
second,
we
can,
for
use
a
O(2
)
Meet
In
The
Middle

Proof.
Proof.
Proof.
The
The
proof
proof
is
is
actually
actually
similar
similar
to
to
the
the
previous
previous
lemma.
lemma.
The
proof
Let
Let
us
us
is
assume
assume
actually
that
that
similar
V
V

to
S
S
is
the
is
not
not
previous
a
a
INDEPENDENT-SET.
INDEPENDENT-SET.
lemma.
Let
us
assu
SUM.
for
a be
large
value
of Nan, italgorithm
isFF
unlikely
to nds
bemultiples
able
to nd
anan
algorithm
that nd
ore,aforementioned
for a large
value
of
Nformula
, Therefore,
it is
unlikely
to
able
to nd
that
A and
Bthree
in
uld
inspect
the
recurrence
more
closely.
Any
consecutive
subsequence
of
with
length
of
can
partitioned
Lemma
3.sequence
Any
subsequence
of
with
length
multiples
of
canbebeEven
partitione
Lemma
3.
recurrence.
Therefore,
we
inspect
the
recurrence
formula
closely.
m.
ecient
way.
However,
this
isisisnwhere
dened
special
way,
in
the
sense
that
Fthree
isof
dened
using
the
N/2
fe SUBSET-SUM.
all
elements
in
B
than
than
44proof
decades.
decades.
MIN-VERTEX-COVER
MIN-VERTEX-COVER
aashould
graph
graph
problem
problem
that
that
involves
involves
nding
nding
aaFmore
minimum
minimum
subset
subset

Programming,
X
is
the
upper
bound
of
the
elements
inside
the
array.
thoug
Any
consecutive
subsequence
of
with
length
multiples
of
three
c
1,
n
=
1consecutive

=
2Therefore,
Lemma
3.
Any
consecutive
subsequence
ofconnecting
F
with
length
multiples
three
can
be
part
Lemma
3.
ere
While
O(2
) SS
isthe
still
exponential
toin
Nathere
,very
itin
is
much
faster
than
of.
The
is
actually
similar
to
previous
lemma.
Let
us
assume
that
V

S
is
not
a
INDEPENDENT-SET.
=
{f
(n)}
,
and
we
dene
F
(N
)
to
be
the
rst
N
terms
of
F
.
We
want
to
know
Lemma
3.
Any
consecutive
subsequence
of

with
length
multiples
of
three
can
be
Therefore,
Therefore,
there
there
are
are
two
two
vertices
vertices
A,
A,
B
B

V
V

S
S
and
and
there
there
is
is
an
an
are
edge
edge
two
connecting
vertices
A,
A
A
B
and
and

V
B.
B.

S
Since
Since
and
A,
A,
there
B
B

is
V
Van

S,
S,
ecient
way.
However,
this
sequence
is
dened
in
a
very
special
way,
in
the
sense
that
Fedg
is
n=1
However,
this
sequence
is
dened
in
a
very
special
way,
the
sense
that
F
is
dened
using
Lemma
Lemma
2.
2.
If
If

V
V
is
is
a
a
VERTEX-COVER
VERTEX-COVER
of
of
graph
graph
G(V,
G(V,
E),
E),
then
then
V
V

S
S
is
is
an
an
INDEPENDEN
INDEPENDEN
f
(n)
=
Any
consecutive
subsequence
of
F
with
length
multiples
of
three
can
be
par
Lemma
3.
of
equal
sum.
ltiples
of
three
can
be
partitioned
into
two
multisets
of
equal
sum.
aforementioned
recurrence.
Therefore,
we
should
inspect
the
recurrence
formula
more
closely.
Ninto
ch
h
that
that
for
for
every
every
edge,
edge,
at
at
least
least
one
one
of
of
its
its
endpoint
endpoint
is
is
in
in
the
subset.
subset.
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
is
is
a
a
algorithm
is
exponential
to
the
size
of
the
input,
the
algorithm
is
still
fast
enough
for
the
with
length
multiples
of
three
can
be
partitioned
two
multisets
of
equal
sum.
of
equal
sum.

t any
can
solve
is)(n
twice
the
of
N
using
O(2
)with
solution.
fA,

1)
+
frange
(n
2),
n
>
2AaSlength
into
two
multisets
of
equal
refore,
there
are
two
vertices
A,
B

and
there
issum.
an
edge
connecting
Ais
and
B.
Sinceby
A,F
Binto
V
This
S,
tion
ofhave
F (NA,
into
two
disjoint
multisets
and
such
that
the
sum
ofwhich
allclosely.
elements
we
we
have
B
B
/
/partitioned
S.
S.
As
As
A
A
and
and
B
are
are
connected
connected
we
by
by
have
an
an
edge,
edge,
A,formula
B
we

/we
S.
note
note
As
that
A
that
and
SSwe
B
iscan
not
not
are
adenote
connected
a partitioned
VERTEX-COVER.
VERTEX-COVER.
by
an
edge,
This
we isnote
is aa
Any
consecutive
subsequence
of
FB
length
multiples
of
three
be
two
multisets
Lemma
3.
consecutive
subsequence
of
F
with
multiples
of
three,
will
=
aforementioned
recurrence.
Therefore,
we
should
inspect
the
recurrence
formula
more
closely.
ed
recurrence.
Therefore,
we
should
inspect
the
recurrence
more
graph
graph
G(V,
G(V,
E)
E)
of
equal
sum.
cem
PARTITION
PARTITION
problem
istechnique
NP-hard
reduction
from
SUBSETm
of
ofA,
nding
nding
aB
aproblem.
maximum
maximum
subset
subset
of
of
nodes
nodes
such
such
that
that
for
for
every
every
edge,
edge,
at
atF
most
most
one
one
of
ofisan
its
its
endpoint
endpoint
is
isthree,
in
inThiswhich
way
tois
apply
this
isby
when
the
value
of
NVERTEX-COVER.
not
too large
(e.g.
N
<
40).
F
note
Pick
any
consecutive
subsequence
of
F
with
length
multiples
of
three,
we
wiw
Proof.
Pick
any
consecutive
subsequence
of
with
length
multiples
of
which
we
Proof.
ave
B

/
S.
As
A
and
B
are
connected
by
an
edge,
we
that
S
is
not
a
is
a
l
elements
in
contradiction.
contradiction.
Therefore
Therefore
V
V

S
S
is
an
an
INDEPENDENT-SET.
INDEPENDENT-SET.
contradiction.
Therefore
V

S
is
INDEPENDENT-SET.

of
equal
sum.
+{f1),
f (a + ,2),
...f
(b)}
for
some
a
< Pick
b.
We
can
Fof
into
Any
consecutive
subsequence
ofsubsequence
Fpartition
with
length
multiples
of
three
can
into
two multisets
Lemma
3.and
Pick
any
consecutive
subsequence
ofbeof
Fpartitioned
with
length
multiples
of thr
Proof.
Proof.
any
consecutive
subsequence
of
F
with
length
multiples
ofwe
three,
which
we
(n)}
we
dene
F
(N
)
to
be
the
rst
N
terms
of
F
.
We
want
to
know
Proof.
Pick
any
consecutive

with
length
multiples
three,
which
n=1
ge
value
of
N
,
it
is
unlikely
to
be
able
to
nd
an
algorithm
that
nds
A
and
B
in
an
Any
consecutive
subsequence
of
F
with
length
multiples
of
three
can
be
partitioned
Lemma
3.

Suppose
Suppose
we
we
already
already
know
know
that
that
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
is
a
a
NP-hard
NP-hard
problem.
problem.
Therefore,
Therefore,
we
we
can
can
show
show
ny consecutive
subsequence
of
F(a+
with
length
multiples
of
three
partitioned
into
multisets
algorithm
for
N+2),
=
36
is
unlikely
tocan
run
inb.
one
second,
wetwo
can,
use
awhich
O(2
Proof.
Proof.
The
The
proof
isis1),
actually
actually
similar
similar
to
to
the
the
previous
previous
lemma.
lemma.
Let
us
uspartition
assume
assume
that
that
Vinto
Vinstance,

SSof
isis not
not
aa INDEPE
INDEP
any
consecutive
subsequence
of
FLet
with
length
multiples
three,
Proof.
{f
fby
(a
1),
f{f
+
...f
(b)}
for
some
aabe
<
We
can
F
into
multiples
of
three,
which
we
will
by
F
=
{f
(a),
fproof
+
f(a
(a
2),
...f
(b)}
for
some
<
b.
We
can
Ffor
radiction.
Therefore
Vdisjoint
(a),
S
isthree,
an
INDEPENDENT-SET.
denote
of
3.4
Finding
Special
Cases
F
with
length
multiples
of
which
we
will
denote
by
F
=
(aTheorem
+
1),
(a
+
2),
...f
(b)}
for
some
a
<SS
We
can
partition
into
=Pick
{f
(a),
ffin
(a
+
1),
ff(a
+
2),
...f
(b)}
for
some
apartition
<
b.b..isisWe
partition
FF F
into
F
will
denote
for
some
We
can
parti
on
of equal
F (N
)sum.
into
two
multisets
A
and
B
such
that
the
sum
of
allisE),
elements
N/2
b
a(a

2(a),
bE),

a
an
2We
any
consecutive
subsequence
of
F
with
length
multiples
of
three,
which
we
will
denote
by
=
Proof.
A
Theorem
Theorem
1.
1.
1.
If
If
S
S

V
V
is
is
a
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
of
of
graph
graph
If
S

G(V,
G(V,
V
a
MAX-INDEPENDENT-SET
then
then
V
V

a
a
MIN-VERTEX-COVER
MIN-VERTEX-COVER
of
graph
G(V
is
sequence
is
dened
in
a
very
special
way,
the
sense
that
F
is
dened
using
the
of
equal
sum.
Pick
NDEPENDENT-SET
NDEPENDENT-SET
is
is
also
also
a
a
NP-hard
NP-hard
problem
problem
by
by
reducing
reducing
a
a
MIN-VERTEX-COVER
MIN-VERTEX-COVER
problem
problem
into
into
a
a
algorithm
for
solving
a
problem
like
SUBSET-SUM.
While
O(2
)
is
still
exponential
to
Therefore,
Therefore,
there
there
are
are
two
two
vertices
vertices
A,
A,
B
B

V
V

S
S
and
and
there
there
is
is
an
edge
edge
connecting
connecting
A
and
and
B.
B.
Since
Since
{f
(a),
f
+
1),
f
(a
+
2),
...f
(b)}
for
some
a
<
b.
can
partition
F
into
rtition
F can
into
ARTITION
problem.
PARTITION
from
SUBSETA
=
{f
(a +
3k),
0 into

k problem}isNP-hard
{f (a + 1by
+ reduction
3k), 0 bkb

}
<
b.
We
partition
F
tion
into
2 2
elements
in
B

2so

a
b

2
N
N
3
3
{f
(a),
fIfPick
(a
+
1),
f
(a
+
2),
...f
(b)}
for
some
a
<
b.
We
can
partition
F
into
orem
1. graph
Swe
thus
Vproblem.
is
a
MAX-INDEPENDENT-SET
of
graph
G(V,
E),
then
V

S
is
a
MIN-VERTEX-COVER
of
of
the
the
graph
G(V,
G(V,
E).
E).
of
the
graph
G(V,
E).
any
consecutive
subsequence
of
F
with
length
multiples
of
three,
which
we
will
denote
by
F
=
Proof.
Therefore,
should
inspect
the
recurrence
formula
more
closely.
h
in
IOI,
and
is
the
main
focus
of
this
paper.
To
solve
IOI
2008
Island
PENDENT-SET
PENDENT-SET
problem.
b

2
b

2
b

O(2
),
and
the
range
of
N
that
it
can
solve
is
twice
the
range
of
N
using
a
O(2
)
we
we have
havetoA,
A,
B
Bable

/
/Fany
S.
S.
As
A
A=and
and
B
B(a
are
are
connected
connected
by
by
an
an
edge,
edge,
we
note
note
that
S+
isis1three,
not
not
a k+
VERTEX-COV
VERTEX-CO
Alength
{f{f
(a
+
3k),
0+
k{f
}}we

(a
+that
11+
0+

}
=
+
3k),
0

{f
{f
(a
+
+S3k),
3k),
0
ak

valueconsecutive
of N , it is subsequence
unlikely
be
toAs
nd
an
algorithm
that
nds
A
and
B
in
an
Pick
consecutive
subsequence
of
Fwhich
with
length
multiples
of
which
we
wil
Proof.
A
=
(a
+
3k),
0

}
{f
(a
1
+
3k),
0

A
=
{f
(a
3k),
0

{f
(a
3k),
0

any
of
with
multiples
of
three,
we
will
denote
by
F
=
b

2
b

2
3
3
b

2
3
3
he
graph
G(V,
{f1(a),
fisapproach.
(a
+E).
1),
f
(a
+
2),
...f
(b)}
some
a}.
<sense
b.an
We
can
partition
F using
into3 the } {f
this
We
must
nd
afor
special
constraint
in 3k),
the
problem
such
use
a
2 3k),
b
ain

2
3 (a
A
=
{f
(a
+
0

+
1
+
3k),
0

contradiction.
contradiction.
Therefore
Therefore
V
V

S
S
is
is
an
INDEPENDENT-SET.
INDEPENDENT-SET.
a
+
+
0

k
}

B
=
{f
(a
+
2
+
3k),
0

sequence
dened
in
a
very
special
way,
the
that
F
is
dened
b
a

2
b

2
e Proof.
subsequence
of(b)}
F 1that
with
of
three
can
be
partitioned
two
{f
(a),
f0(a
(a
+
1),
f0(a
+
2),
(b)}
for
athat
<1into
b.
partition
F into

{f
(a
+
+ 3k),

kisproblem

}...f
1),
f (a +} We
2),
...f
for
some
a
<
We
can
partition
FWe
into
Proof.
Proof.
We
know
know
that
Vlength
V{f

S
S+multiples
is
ab.
a vertex
vertex
cover
by
by
lemma
lemma
know
1.
1.(a
The
The
only
only

thing
thing
that
a vertex
for
uslemma
to
to prove
prove
1. is
The
is its
itso
bVbWe

aS

acan
RTITION
problem.
PARTITION
isk cover
NP-hard
by
reduction
from
SUBSET3is2
3
}3k),
some
{f
+
3k),
0multisets
remains
A
3k),

{f
b cover
a for
2}byus
b
2that
2remains
oblem
to be
solvable
in =
polynomial
time.
can
check
additional
rst
rst
prove
the
the
following
following
two
two
lemmas.
lemmas.
3 prove
3We
}.ka
B3B
=
(a
+
22+
0+
k+k+

}.k
=
{f
(a
+
+whether
3k),
0
an

3.4
Finding
Special
Cases
herefore,
we
should
inspect
the
recurrence
formula
more
closely.
3
3
b
a
2
b

2
}.
B
=
{f
(a
2
+
3k),
0

}.
B
=
{f
(a
+
2
3k),
0

of.
We
know
that
V

S
is
a
vertex
cover
by
lemma
1.
The
only
thing
that
remains
for
us
to
prove
is
its
b

2
V
V

S
S
is
is
not
not
minimum
minimum
vertex
vertex
cover.
cover.
Then,
Then,
V
there
there

S
is
is
is
another
another
not
minimum
vertex
vertex
cover
vertex
cover
V
V
cover.

S
S
where
Then,
where
minimality.
minimality.
Suppose
Suppose
minimality.
Suppose
3graph
alueb
of aN, 2it is unlikely
to{f
be1.
able
algorithm
that
nds
B
in
ank3G(V,
Theorem
Theorem
1.
Sto

isan
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
of
of
G(V,
E), 3then
then}VV
SS isisb a
a MIN-VE
MIN-VE
A as
=
(a
+
3k),
0VV2kis
kaaba2

}+22{f
02
E),
a2
b+A10and
a+
2a3graph
b 3k),

bIfIfS
nd
}.
B =b{f
(a
+(a
3k),
k
ll have
the
sum,
for
every
0a

{fsame
3(a
a3k),
isanother
}.

33k),
3 3k),
A
=
{f
+
0

{f
(a
+
1
+
0

k
A
=
(a
+
3k),
0

1
+
0
k

}
V

S
is
not
minimum
vertex
cover.
Then,
there
vertex
cover
V

S
where
mality.
Suppose
3
|V
|V

S
S
|
|
<
<
|V
|V

S|,
S|,
which
which
implies
implies
that
that
|S
|S
|
|
>
>
|V
|S|.
|S|.

S
By
By
|
<
lemma
lemma
|V

2,
2,
S|,
S
S
which
is
an
an
implies
independent
independent
that
|S
set.
set.
|
>
Therefore,
Therefore,
|S|.
By
lemma
S
S
is
is
not
not
2, S
aa}
If
If
S
S

V
V
is
is
an
an
INDEPENDENT-SET
INDEPENDENT-SET
of
of
graph
graph
G(V,
G(V,
E),
E),
then
then
V
V

S
S
is
is
a
a
VERTEX-COVER
VERTEX-COVER
of
of
the
the
quence
is
dened
in
a
very
special
way,
in
the
sense
that
F
is
dened
using
the
ba2
ba2
}.
B
=
{f
(a
+
2
+
3k),
0

of
of
the
the
graph
graph
G(V,
G(V,
E).
E).
This
ismultiples
the
suitable
approach
in
IOI,
and
thus
is =
the main ba2
focus of this paper.
ubsequence
of F of
with
length
multiples
of most
three
can
be
partitioned
into
two
multisets
3
3
3
B
will
have
the
same
sum,
as
for
every
0

Aand
and
B
will
have
the
same
sum,
as
for
every
0

ve subsequence
FA
with
length
of
three,
which
we
will
denote
by
F
ba2
3
3
will
as for
3
3 3 0 k
b

2
A
and
B
will
have
the
same
sum,
as
for
every
A
and
B
have
the
same
sum,
every
0

Smaximum
| < |V
should
S|,
which
that
|S(a
>
lemma
2,
S
is
independent
isspecial
not a constr
maximum
independent
independent
set.
set.
This
This
a3k),
a|acontradiction.
contradiction.
maximum
Therefore
Therefore
independent
VVan

this
S
S
isisapproach.
the
This
minimum
isset.
a ba2
contradiction.
vertex
vertex
cover.
V S
3 SaTherefore
3Therefore,
E)
E)
erefore,
weba2
the
formula
closely.
3k)
Bb.fimplies
=
{f
+
2 is
+
0|S|.
kBy
more
b set.

athe

2minimum
(a
+(a
3k)
+
+
1F
+
=
f (a
+sum,
2 }.
+
and
IOI
we
need
to 3k)
use
must cover.
nd
bfis
2Friend,
Arecurrence
and
B2014
will
have
the
same
as
for
every
0
k We
..f
(b)}
for
some
a2inspect
<
We
can
partition
into
3 thing
3
0
k

}.
B
=
{f
(a
+
2
+
3k),
0

ba2
}.
B
=
{f
(a
+
+
3k),
0

Proof.
Proof.
We
We
know
know
that
that
V
V

S
S
is
is
a
a
vertex
vertex
cover
cover
by
by
lemma
lemma
1.
1.
The
The
only
only
thing
that
that
remains
remains
for
for
us
us
imum
independent
set.
This
is
a
contradiction.
Therefore
V

S
is
the
minimum
vertex
cover.
3
A and B will have the same
sum,
asconstraint
for every allows
0k
fthe
+
fto
+
1f1+
+
3k)
=
+
+
3k)
f(a(aproblem
3k)
f(a(a
+solvable
+3k)
3k)
=ffpolynomial
f(a(a+
+12f2+
3k)
that
this
be
in
time.
We
can
3(a
3+3k)
fmultisets
(a
3k)
fif3k)
(a
2 +che
fthere
(a+
++
3k)
+
(a
1+
+
3k)
=
(a+
+MIN-VERTEX-CO
+
From
Fromthat
the
the
theorem,
we
we
conclude
conclude
that
that
aaTherefore,
From
MIN-VERTEX-COVER
MIN-VERTEX-COVER
the
above
theorem,
can
can
we
be
be
conclude
easily
easily
constructed
that
a
we
we+have
have
a3k
a
bsequence
of
FofVabove
with
multiples
of 3Vthree
can
be
partitioned
into
two
us
us
assume
assume
that
Vabove

with
Slength
Satheorem,
isislength
not
not
aaSuppose
VERTEX-COVER.
VERTEX-COVER.
Therefore,
there
are
are
two
two
vertices
vertices
A,
A,
B
Bconstructed

/
/isVV

SS2=+ifvertex
subsequence
F
multiples
of
three,
which
we
will
denote
by
F
=
ba2
V

S
S
is
is
not
not
minimum
minimum
vertex
vertex
cover.
cover.
Then,
Then,
there
there
is
another
another
vertex
cover
cover
minimality.
minimality.
Suppose
b

2
b

2
(a + 1 + 3k) = f (a + 2 + 3k)
=
f (a
+
2B
+
3k)
A
and
will
have
the
same
sum,
as 1for
every
0kk 3 f (a}+ 3k) + fba2
f
(a
+
1
+
3k)
=
f
(a
+
2
+
3k)
a
+
3k),
0
k

{f
(a
+
+
3k),
0
ba2

vin
GUNAWAN

From
the
above
theorem,
we
conclude
that
a
MIN-VERTEX-COVER
can
be
easily
constructed
if
we
have
a
MAX-INDEPENDENT-SET.
MAX-INDEPENDENT-SET.
an
anMAX-INDEPENDENT-SET.
edge
edge
connecting
connecting
and
B.
B.
Since
Since
B
Binto

/3k)

/same
Vimplies
V+

fsum,
S,
S,
we
we
have
A,
A,
B
Bf
S.
S.
As
A
and
and
B
B is
are
are
connected
A
and
B
have
as
for3k)
every
0

+A
and
will
will
have
the
for
have
thesome
sameasum,
as
for|can
every
0 S|,

kA,
the
fA,
(a
+
(athat
+as
1have
+
(aBy
+klemma
2As
3k)
(b)}
for
<|V
b. A
We
partition
F
|V

S
|<
<
|V
|V

S|,
which
which
that
|S
|S
|3|every
>
>=
|S|.
|S|.
By
lemma
2, SS
is
an
anconnected
independent
independent set.
set. Theref
Theref
3 S
32,
3implies
Jonathan
Irvin
Jonathan
IrvinGUNAWAN
GUNAWAN
X-INDEPENDENT-SET.
we
we note
note that
that SS maximum
ismaximum
is not
not
an
INDEPENDENT-SET.
INDEPENDENT-SET.
This
This
is
is
a
a
contradiction.
contradiction.
Therefore
Therefore
V
V

S
S
is
is
a
a
Jonathan
Irvin
GUNAWAN
Jonathan
Irvin
GUNAWAN
b an
a
2
f
(a
+
3k)
+
f
(a
+
1
+
3k)
=
f
(a
+
2
+
3k)
independent
independent
set.
set.
This
Thiswhich
isis aa contradiction.
contradiction.
Therefore
Therefore
SS isis the
the minimum
minimum vertex
vertex cover.
cover
V
ubsequence
of0
multiples
three,
we
denote
F
=V
bFkwith
af(a
2length
bthe
will
2 MIN-VERTEX-COVER
}.
a + 2In
+ the
3k),
Jonathan
Irvin
GUNAWAN
f(a
+
3k)
+ fof(athis
+by1section,
+ 3k)
=we
f (a
2NP-hard
+we
3k)know
+
1ofassume
+
3k)
f
(a
+
2abeginning
+
3k)
Jonathan
Irvin
GUNAWAN
the
beginning
of
of
this
this
section,
section,
we
we
assume
we
In
know
know
that
that
assume
isis+
aa NP-hard
problem.
problem.
that MIN-V
ItIt isis
OVER.
OVER.
+
3k),
0In
k beginning

}+
3k)
{f
(a f+(a1 +
+
0 =kwe
}MIN-VERTEX-COVER
3
3k),
Jonathan
Irvin
GUNAWAN
b)} for some a < b. 3We
canthe
partition
Ftheorem,
into we
3isisthat
From
From
the
above
above
theorem,
we conclude
conclude
that
aa MIN-VERTEX-COVER
MIN-VERTEX-COVER
can
can
be
be easily
easily
constructe
n the
beginning
of
this
section,
we
assume
wepossible.
know
that
MIN-VERTEX-COVER
is aencounter
NP-hard
Itisconstructe
isnecessary
good
good
to
to know
know as
as many
many
NP-hard
NP-hard
problem
problem
as
as
possible.
good
to
This
This
know
necessary
necessary
as many
NP-hard
so
so that
that ififproblem
we
we
encounter
as possible.
aaproblem.
new
new
This
problem
problem
X,
X, we
we
ba2
Jonathan
Irvin
GUNAWAN
b

2
me
sum,
as
for
every
0

If
If
S
S

V
V
is
is
a
a
VERTEX-COVER
VERTEX-COVER
of
of
graph
graph
G(V,
G(V,
E),
E),
then
then
V
V

S
S
is
is
an
an
INDEPENDENT-SET
INDEPENDENT-SET
of
of
the
the
MAX-INDEPENDENT-SET.
MAX-INDEPENDENT-SET.
3
by
the
construction
of
the
function.
dn to
many
problem
possible.
This
that if X,
we
encounter
a new
problem
X, we
bof

aNP-hard
NP-hard
2
bisreduce
necessary
a of
2itit the
Jonathan
Irvin as
GUNAWAN
can
can
use
useas
any
the
the
NP-hard
problems
that
that we
we know,
know,
can use
reduce
any
to
tosoproblem
problem
NP-hard
X,
problems
and
and thus
thusthat
prove
prove
wethat
that
know,
XX is
reduce
is also
also
NP-hard.
it
NP-hard.
to prob
}.problems
+
2GUNAWAN
+know
3k),
0any

kof
3k), 0 k
}3 {f (a + 1 + 3k), 0 k
}
E)
E)
use
any
of
the
NP-hard
problems
that
we
know,
reduce
it
to
problem
X,
and
thus
prove
that
X
is
also
NP-hard.
3
3
11We
1
f (a
3k)problem
+ f (aXX+isis1reducible
+ 3k) =to
(a + 2 Y
+
We
say
say+
that
that
problem
reducible
tofproblem
problem
Y 3k)We say that problem X is reducible to problem Y
the
the
beginning
beginning of
of this
this section,
section, we
we assume
assume we
we know
know that
that MIN-VERTEX-COVER
MIN-VERTEX-COVER isis aa NP-hard
NP-hard
In
a

2ba2
um, as
for everysimilar
0b
kIn
proof
proof
isisthat
actually
actually
to
to the
the
previous
lemma.
lemma.
Let
Let us
us assume
assume that
that VV
SS isis not
not aa INDEPENDENT-SET.
INDEPENDENT-SET.
We
X is reducible
to problem
Y
}.3previous
2 +say
3k),
0 problem
k similar
good
good3 to
to know
know as
as many
many NP-hard
NP-hard problem
problem as
as possible.
possible. This
This isis necessary
necessary so
so that
that ifif we
we encounter
encounter aa new
new
here
here are
two
vertices
vertices
A,
B
3k)
VV

SSfand
and+there
there
isis an
an edge
edge connecting
connecting A
A and
and B.
B. Since
Since A,
A,B
B VV
S,
S,
fare
(atwo
+ 3k)
+ fcan
(aA,
+
1Bany
+
=
(a
2 + problems
3k)
can
use
use
any
of
of
the
the
NP-hard
NP-hard
problems
that
that
we
we
know,
know,
reduce
reduce
it
it
to
to
problem
problem
X,
X,
and
and
thus
thus
prove
prove
that
that
XX ii
ba2
B
B
/
/as
S.
S.for
As
Asevery
A
A and
and
B
Bkare
are
connected
by
by an
an edge,
edge, we
we note
note that
that SS isis not
not aa VERTEX-COVER.
VERTEX-COVER. This
This isis aa
m,
0
connected
3
11We
We
say
that
that problem
problem XX isis reducible
reducible to
to problem
problem YY
n.
n. Therefore
Therefore VV
SS isis
an
ansay
INDEPENDENT-SET.
INDEPENDENT-SET.

ICPC
World
Finals
2010
Solutions
n.d.).
at problem.
we
use
tosolvable
nd
all
possible
paths
(ACM
to be
in
polynomial
time
using
the
reduction
ofgiven
the
original
problem
(withemadditional
constraint),
and
check
whether
the
proof
stillproof
holds
the
additional
constraint
to the problem.
onstraint),
and
check
whether
the
proof
still
holds
given
the
additional
constraint
toIfthe
re
that
we
can2
get
Accepted
by
only
"hacking"
a complete
search
algorithm.
Therefore,
we through
ollowing
formula
2
Identifying
Identifying
Intractability
Intractability
of
a
Problem
of
a
Problem
through
Reduction
Redu
is
impossible
to
visit
the
rest
of
the
unvisited
points,
then
we
can
prune
the
path
and
int), and check whether the proof still holds given the additional constraint to the problem.
causes ainproblem
to be solvable in polynomial time using the reduction proof of the original problem (withchnique
detail.
wever,
it
is
not
very
suitable
for
IOI.
Usually,
IOI
problems
require
deep
analysis
from

e one
will example
give
we one
ofwhether
a in
special
inproblem.
a NP-hard
problem.
Suppose
we havewith
a function
with the
editional
of a example
special
case
a NP-hard
Suppose
weadditional
have
a function
the problem.
constraint),
and
check
thecase
proof
still
holds
given
the
the
We
likewould
to
know
likeonly
that
to know
the problem
that
that
problem
we
are
that
attempting
we
are
attempting
unlikely
unlikely
havetoan
to
immediate
have an immediate
solution. solu
The
1,athe
n=
1is
n = constraint
2is to
at
weformula
canwould
getaWe
Accepted
by
"hacking"
complete
search
algorithm.
Therefore,
we
example
of
special case
in a NP-hard
problem.
Suppose
we
have
a
function
with
the
ing
f (n) = Understanding Unsolvable Problem
93
most
common
most
common
way
is
to
way
apply
is
to
a
well-known
apply
a
well-known
technique
technique
called
reduction.
called
reduction.
Suppose
Suppose
we
know
we
that
know
problem
that
pro
X
i
Finding
Small
f (n 1) + f (n 2), n > 2
ue in detail.3.3by the
construction
of
theConstraints
function.
case
of
1
1
l give
we oneimpossible
example
asolve,
special
in
a know
NP-hard
problem.
Suppose
we
have
ausing
function
with
the
impossible
to
solve,
to
and
we
also
and
know
we
also
that
we
can
that
solve
we
can
problem
solve
X
problem
by
using
X
problem
by
Y
problem
as
a
black-box
Y
as
a
black-box
.
If
we
can
.
by
the
construction
of
then function.
by
construction
of
the
bysequence
the
construction
of time
the
function.
function.
1,
1
=
2rst
1,
n
=dene
1then
solve
n F=
2n
) SUBSET-SUM
algorithm
running
for
various
input
sizes.
This
the
We
consider
the
=
{f
, and
weX
(N
)=well.
to
bebe
the
ofimpossible
F
We impossible
want
to know
NP-hard
with
large
Ncan
that
is
impossible
to
exponentially
(e.g.NY
Nterms
>
50).
Theorem
2.FIf
=
is(n)}
divisible
by
three,
can
partitioned
two
multisets
ormula
n=1
fwe
(n)
fthe
(n)function.
=
solveproblem
problem
Y,
problem
then
Y,
then
solve
we
can
problem
solve
problem
as
well.
X
Therefore,
as
Therefore,
problem
problem
isinto
also
is .also
to solve.
to solve
Theorem
2.
If
N
is
divisible
by
three,
then
F
(N
)
can
be
partitioned
into Y
two
multisets
of equal
sum.
nstruction
of solve
by
the
construction
of
the
function.
by
the
construction
of
the
function.
1,
n
=
1

n
=
2
3.3
Finding
Small
Constraints
f
N
on
a
MacBook
Pro
(Retina,
13-inch,
Early
2015)
f
(n

1)
+
f
(n

2),
n
>
2
fpartition
(n
N
1)
+
fSUBSET-SUM
(n
2),
n >algorithm
2then
hether
can
asum.
of
Fthat
(Nfunction.
)may
into
two
disjoint
A
suchproblem
that
the
sum
allpartitioned
elements
ofcreate
equal
also
lookwe
small
constraints
For
acan
SUBSET-SUM
N
N/2
Theorem
2.example,
IfF
N
is)) can
divisible
by
then
F
(N
) canof
be
int
by
the
of
the
Theorem
2.
IfIf
by
three,
(N
be
partitioned
into
two
multisets
of
equal
f for
(n)
=
Theorem
2.
N
is
divisible
byhelp.
three,
then
Fmultisets
(N
beand
partitioned
into
two
multisets
of
equal sum.
sum.
omparison
ofother
O(2
)construction
and
O(2
) divisible
running
time
forBthree,
various
input
sizes.
This
is
by
construction
of
the
function.
fthe
(n
the
1)
+
felements
(n

2),
n
>
2
by
the
construction
of
the
function.
by
construction
of
the
function.
by
the
construction
of
the
function.
nrd
A
is
equal
to
the
sum
of
all
in
B
problem,
and
will
not
be
solvable
with
N
=
100.
When
we
are
given
the
constraint
that

Proof.
If
N
is
divisible
by
three,
then
F
(N
)
is
a
prex
of
F
with
length
multiples
of
three.
By
lemm
2.
If
N
is
divisible
by
three,
then
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum.
1,
n
=
1

n
=
2

Theorem
2.
If
N
is
divisible
by
three,
then
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
by
the
construction
of
the
function.
Theorem
2.
Ifthen
N
isthe
divisible
by
three,
F>
(N
) problems
can
partitioned
into
two mult
is run
100
times
for
each
value
N, and
on
a(N
MacBook
13-inch,
Early
2015)
nsider
the
F
=
we
dene
FPro
(N
)(Retina,
the
rst
terms
of
F
.be
We
want
totoknow
We=sequence
are
using
We
are
NP-hard
using
problems
NP-hard
problems
for
illustration.
for
Recall
Recall
NP-hard
that
problems
NP-hard
have
yet
to
have
be of
yet
solved
be
in polynomia
solved
in p
quence
F
{fProof.
(n)}
,N
and
we
dene
F three,
) to
to
beillustration.
rst
Nabe
terms
ofthen
FN
We
want
tomultiples
know
rd
problem
with
large
that
isof
impossible
solve
exponentially
(e.g.
50).
If
{f
is=(n)}
divisible
by
to
isthat
prefix
of
.N
with
length
n=1
fN
(n)
2 length
Proof.
Ifof
N(N
is))F
divisible
bybe
three,
then
Finto
(N multiples
)multiples
is amultisets
prex
F equal
with
length
Theorem
2. is
Ifdivisible
N
isn=1
divisible
by
three,
can
partitioned
two
of
sum.
Proof.
IfIf
by
three,
then
F
is
aa )prex
of
F
of
three.
By
Proof.
N
is[0,
divisible
by
three,
then
Fthen
(N
is(N
prex
of
F with
with
length
of of
three.
By lemma
lemm

the
array
are
small
(e.g.
100]),
this
problem
can
be
solved
using
O(N
X
)to
Dynamic
can
be
partitioned
into
two
multisets
equal
sum..
f
(n

1)
+
f
(n

2),
n
>
2
eer
F
=
{f
(n)}
,
and
we
dene
F
(N
)
to
be
the
rst
N
terms
of
F
.
We
want
know
polynomial
time
using
the
reduction
proof
of
the
original
problem
(withwe
can
create
a
partition
of
F
(N
)
into
two
disjoint
multisets
A
and
B
such
that
the
sum
of
all
elements
three.
By
lemma
3,

can
be
partitioned
into
two
multisets
of
equal
sum.
time
for
more
time
for
than
more
4
decades.
than
4
decades.
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
a
graph
is
problem
a
graph
that
problem
involves
that
nding
involves
a
nding
minimum
a
minimu
subse
ate
a
partition
of
F
(N
)
into
two
disjoint
multisets
A
and
B
such
that
the
sum
of
all
elements
ook
for
other
small
constraints
that
may
help.
For
example,
a
SUBSET-SUM
problem
Theorem
If
N
divisible
bypartitioned
three,
then
(N
)be
can
be
partitioned
into
of equa
n=1
Theorem
2.can
IfF
N
is))F
by
three,
then
F
(N
)two
besum.
partitioned
Theorem
2.
N
is)divisible
divisible
by
three,
Fsum..
(N
can
be
partitioned
into
two
multisets
of three.
equal
sum
Theorem
2.
IfIfN
N
is
by
three,
then
(N
can
partitioned
into
two
multisets
of
equal
sum
Nfunction.
isthe
divisible
by
three,
then
F2.
(N
istwo
aisIfproblem.
prex
of
multiples
of
By
lemma
3,can
Fmultisets
(N
)of
Ifelements
is
then
F
(N
)problem
isdivisible
a prex
of
length
Byin
Theorem
2. be
IfProof.
N
isthe
divisible
bydivisible
three,
then
(N
)then
be
partitioned
into
two
multisets
of
equal
can
beFF
into
two
ofprex
equal
sum..
Proof.
Nby
isthree,
divisible
bylength
three,
then
Fmultisets
(N
)three.
isF
awith
of
F multiples
with
length
multiples
can
be
partitioned
into
multisets
of
equal
can
be
partitioned
into
two
multisets
ofwith
equal
sum..
looks
like
classic
PARTITION
PARTITION
isthe
NP-hard
by
reduction
from
SUBSETX
isThis
upper
bound
of
inside
the
array.
Even
though
the
running
time
of
the
then
Fnodes
(N
)will
can
partitioned
into
two
multisets
of
equal
sum.
partition
ofthe
Fcan
(N
)aholds
into
two
disjoint
multisets
Athen
and
Bequal
such
that
the
sum
of
allin
elements
ther
the
proof
still
given
the
additional
constraint
to
the
problem.
s
equal
to
sum
of
all
elements
in
B
of
of
such
nodes
that
such
for
every
that
for
edge,
every
at
least
edge,
one
at
least
of
its
one
endpoint
of
its
endpoint
is
in
subset.
is
the
MAX-INDEPENDENT-SET
subset.
MAX-INDEPENDENT
is a
e
sum
of
all
elements
in
B
oblem,
and
not
be
solvable
with
N
=
100.
When
we
are
given
the
constraint
that
Proof.
If
N
is
divisible
by
three,
F
(N
)
is
a
prex
of
F
with
length
multiples
of
three.
By
lemma

then
F
(N
)
be
partitioned
into
two
multisets
of
sum.
3.the
If
N

1 be
(mod
3),
F
(N
))to
bebeof
partitioned
into
two
multisets
of(withequal
sum.
er
the
F
=
{f
(n)}
,can
and
we
dene
Fusing
(N
to
be
the
rst
Nofconstraint.
terms
of
FAnother
. We
want
to
know
artitioned
intoofTheorem
two
ofalgorithm
equal
sum..
asequence
problem
toofmultisets
be
solvable
in
polynomial
time
the
reduction
proof
ofalgorithm
the
original
problem
nto
two
multisets
sum.
Theorem
3.
If
,three,
cannot
cannot
partitioned
into
two
multisets
of
can
be
partitioned
into
two
multisets
of
equal
sum..
into
two
multisets
equal
sum..
n=1
UM.
Therefore,
aequal
large
value
of
N
,ispartitioned
it
is
unlikely
be
able
to
an
that
nds
A
Bfunction.
inBy
anlengt
lauses
tothe
the
size
the
input,
still
fast
enough
for
the
given
sible
by
three,
then
F
(N
)100]),
can
be
partitioned
into
two
multisets
equal
sum.
Proof.
If
N
isthe
divisible
by
then
F
(N
)partitioned
isO(N
and
prex
of
F
with
length
multiples
of
three.
By
2
by
the
construction
the
Proof.
Ifnodes
N
is
divisible
by
three,
then
F
(N
)of
isbe
aone
prex
of
F
with
Proof.
N
is
divisible
by
three,
then
F
(N
is
aF
prex
of
F
with
length
multiples
ofand
three.
By
lemm
Proof.
IfIf
N
is
divisible
by
three,
then
F
(N
))of
is
a
prex
of
F
with
length
multiples
of
three.
lemm
by
the
construction
of
the
function.
by
construction
the
function.
by
construction
of
the
function.
of
all
elements
infor
B
graph
problem
graph
of
problem
nding
of
a
nding
maximum
a
maximum
subset
of
subset
such
nodes
that
such
for
every
that
for
edge,
every
at
most
edge,
at
most
of
its
one
endpoint
of
its
endp
is
in
Proof.
If
N
is
divisible
by
three,
then
F
(N
)
is
a
prex
of
with
length
multiples
three.
By
lemma
3,
F
(N
array
are
small
(e.g.
[0,
this
problem
can
be
solved
using
X
)
Dynamic
Theorem
3.
If
N
1
(mod
3),
F
(N
)
cannot
partitioned
into
two
m
can
be
partitioned
into
two
multisets
of
equal
sum..
Theorem
3.
If
N

1
(mod
3),
F
(N
)
cannot
be
into
two
multisets
of
equal
sum.
the
construction
of
the
function.
Theorem
3.
If
N

1
(mod
3),
F
(N
)
cannot
be
partitioned
into
two
multisets
of
equal
sum.
ecient
aHowever,
partition
ofofFN
(N
into
two
disjoint
multisets
A and
Bexample,
the sum
all
elements
equal
sum.
Fcan
(N))create
isway.
a prex
prex
ofand
F check
with
length
multiples
ofstill
three.
By
lemma
3,
Fsuch
(N
)that
itional
constraint),
whether
the
proof
holds
given
the
additional
constraint
toNofFthe
problem.
this
sequence
is
dened
in
athat
very
special
way,
in
the
sense
that
is
dened
using
the
not
F (N
nique
is
when
the
value
is)inside
too
large
(e.g.
N
<
40).
For
while
O(2
)elements.
F
(N
is
a
of
F
with
length
multiples
of
three.
By
lemma
3,
)contains
can
be
partitioned
into
two
multisets
of
equal
sum..
n.
can
be
partitioned
into
two
multisets
of
equal
sum..
can
be
partitioned
into
two
multisets
of
equal
sum..
can
be
partitioned
into
two
multisets
of
equal
sum..
Proof.
Suppose
F
(N
)
=
F
(N
)

f
(1).
Note
that
F
(N
)
N

1
Since
N

1
(m
3.
If
N
1
(mod
3),
F
(N
)
cannot
be
partitioned
into
two
multisets
of
equal
sum.
l
case
in
a
NP-hard
problem.
Suppose
we
have
a
function
with
the
th
multiples
of
three.
By
lemma
3,
F
(N
)
Theorem
3.
If
N

1
(mod
3),
F
(N
)
cannot
be
partitioned
into
two
multisets
of
equal
sum.
his
looks
like
a
classic
PARTITION
problem.
PARTITION
problem
is
NP-hard
by
reduction
from
SUBSETthe
subset.
the
Suppose
subset.
we
Suppose
already
we
know
already
that
know
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
a
NP-hard
is
a
NP-hard
problem.
problem.
Therefore,
Therefore,
we
can
show
we
can
be
partitioned
into
two
multisets
of
equal
sum..
a
classic
PARTITION
problem.
PARTITION
problem
is
NP-hard
by
reduction
from
SUBSEThe
upper
bound
of
the
elements
the
array.
Even
though
the
running
time
of
the
Theorem
3.
If
N

1
(mod
3),
F
(N
)
cannot
be
partitioned
into
two
multisets
of
e
yis
three,
then
F
(Nall
is
a3.
prex
of
F1 )can,
with
length
multiples
ofby
three.
By
lemma
3,
FNMiddle
(N
)1of
ual
to the
sum
of
elements
in
B
of
equal
sum..
three,
Fdivisible
Theorem
2.
Ifthen
Nsum.
is
by
three
N/2

=
Theorem
2.
If
N
istwo
divisible
by
three,
(N
) can
be
part
(N
Theorem
2.
If
N
is)divisible
divisible
by
three,
then
F(N
(N
)fis
can
be
partitioned
into
two
multisets
equal
sum.
Theorem
2.
If
N
divisible
then
F
(N
)two
can
be
partitioned
into
two
multise
Proof.
Suppose
F
(N
)
F
(N
)

f
(1).
Note
that
F
(N
)
contains
N

forementioned
recurrence.
Therefore,
we
should
inspect
recurrence
formula
more
closely.
Theorem
If
N
(mod
3),
F
(N
)
cannot
be
partitioned
into
multisets
of
equal
sum.
the
Proof.
Suppose
F
(N
=
F
(N
)

(1).
Note
that
F
(N
)
contains

elements.
Since
N

1
(m
unlikely
to
run
in
one
second,
we
for
instance,
use
a
O(2
)
Meet
In
The
Proof.
Suppose
F
(N
)
=
F
(N
)

f
(1).
Note
that
F
)
contains
N

1
elements.
Since
N

1
(m
heorem
2.
If
N
is
by
three,
then
F
)
can
be
partitioned
into
multisets
of
equal
f
equal
sum..
Proof.
Suppose
.
Note
that

contains

elements.
n.
haveN

0
(mod
3).
By
lemma
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum.
The
sic
PARTITION
problem.
PARTITION
problem
is
NP-hard
by
reduction
from
SUBSETTherefore,
for
aoflarge
of3.NIfis,case
itstill
is
unlikely
to
be
able
to nd
an
algorithm
that
nds
Awith
and the
Bofin
an sum.
that
that
MAX-INDEPENDENT-SET
is
also
aNP-hard
NP-hard
is
also
aproblem.
NP-hard
problem
by
problem
reducing
by
reducing
ahave
MIN-VERTEX-COVER
aB
MIN-VERTEX-COVER
problem
into
probla
or
asize
large
value
N
,sum..
itvalue
is
unlikely
be
able
to
nd
an
algorithm
that
nds
and
in multisets
an
he
ofMAX-INDEPENDENT-SET
the
input,
the
algorithm
fast
enough
the
given
constraint.
Another
one
wo
multisets
equal
(mod
3),into
Theorem
N
1two
(mod
3),
cannot
be
partitioned
into
two
equal
give
we
example
of
a1fSuppose
special
in
we
a)N
function
N
hree,
then
Fof
)Fcan
partitioned
multisets
sum.
Theorem
If)F
N

13).
FA
(N
cannot
be
partitioned
into
two
m
Theorem
3.
N
3),
13).
(mod
3),
F)F(N
(N
)F
cannot
be
partitioned
into
two
multisets
ofbe
equal
sum.
Theorem
3.
IfIfWhile
N

1to
3),
F
)for
cannot
be
partitioned
two
multisets
of
equal
sum.
3.
rtitioned
into
two
multisets
of
equal
sum.
of
uppose
Flike
(N
)(N
=
(N
)be
elements
Note
that
(N
contains

1be
elements.
Since

1)F)can
(mod
3),
we
Proof.
F
(N
)have
=
Fstill
(N
)sum.

(1).
Note
that
FA
(N
)elements
contains

1sum.
elements.
Since
N

Theorem
3.
If
N

(mod
F
(N
)aF
cannot
be
partitioned
into
two
multisets
equal
haveN

1F

(mod
By
lemma
3,
Ftwo
(N
be
partitioned
into
tw
Proof.
Suppose
(N
)f(N
=0)equal
(N
)Suppose

(1).
Note
that
Fof
(N
contains
N

1sum.
element
N/2
equal
problem
SUBSET-SUM.
O(2
is
exponential
to
N
,fpartitioned
it
isof
much
faster
than
haveN

11sequence

0(1).
(mod
3).
By
lemma
3,
F
(N
can
into
multisets
of
equal
The
Since
,into
we
.(mod
By
lemma
3,
is(N
can
haveN
all

0not
(mod
By
lemma
3,
(N
)N
can
be
partitioned
into
two
multisets
of
sum.
The
Nin
sum
of
in
F
(N
)
is
even.
However,
the
sum
all
in
)
=
F
(N
)
+
f
(1),
wh
arge
value
of
N
,
it
is
unlikely
to
be
able
to
nd
an
algorithm
that
and
B
an
))ever,
cannot
be
partitioned
into
two
multisets
of
equal
too
nds
Proof.
If
N
divisible
by
three,
nt
way.
However,
this
is
dened
in
a
very
special
way,
in
the
sense
that
F
is
dened
using
the
MAX-INDEPENDENT-SET
MAX-INDEPENDENT-SET
problem.
problem.
this
sequence
is
dened
in
a
very
special
way,
in
the
sense
that
F
is
dened
using
the
is
when
the
value
of
N
is
large
(e.g.
N
<
40).
For
example,
while
O(2
)
Proof.
If
N
is
divisible
by
three,
then
F
(N
)
is
a
prex
of
F(m
w
Proof.
If
N
is
divisible
by
three,
then
F
(N
)
is
a
prex
of
F
with
length
multiples
of
three.
By
lemma
3,
F
(N
)then
Proof.
If
N
is
divisible
by
three,
then
F
(N
)
is
a
prex
of
F
with
length
multiples
of
Any
consecutive
subsequence
of
F
with
length
multiples
of
three
can
be
partitioned
into
two
multisets
emma
3.
Proof.
Suppose
F
)
=
F
(N
)

f
(1).
Note
that
F
(N
)
contains
N

1
elements.
Since
N

1
(N
oof.
If
N
is
divisible
by
three,
then
F
(N
)
is
a
prex
of
F
with
length
multiples
of
three.
By
lemma
3,
F
(N
)
cannot
be
partitioned
into
two
multisets
of
equal
sum.

oks
like
a
classic
PARTITION
problem.
PARTITION
problem
is
NP-hard
by
reduction
from
SUBSEThree,
then
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum.
ormula

1ofN
03),
(mod
3).
By
lemma
3,
F
(N
)F
can
partitioned
into
two
of
equal
sum.
Therefore,
multisets
of
equal
sum.
haveN
1very

(mod
3).
By
lemma
3,equal
FTherefore,
(N
)multisets
can
be
into
two
equal
sum
of
all
elements
F
)F
is
even.
However,
the
sum
of
all
elements
haveN
multiples
1))way,

0using
(mod
3).
By
lemma
3,dened
(N
can
be
partitioned
into
multisets
partitioned
into
two
multisets
of
equal
sum.
the
sum
of
all
elements
in
twice
(N
partitioned
that
can
solve
is
the
range
of
N
aaformula
O(2
)partitioned
solution.
sum
of
all
elements
in
)be
is
However,
the
of
all
elements
in
(N
=
F
(N
)of
+
ff(1),
wh
in
the
0
sum
of
all
elements
in
F
(N
is
However,
the
sum
of
all
elements
in
F
(N
)multisets
=
F
(N
)contains
+Since
(1),
wh
we
(N
by
the
construction
the
function.
nSuppose
=
1
n
=
2special
mod
F
(N
cannot
be
partitioned
two
multisets
of
sum.
because
F
(N
)=
is
even
while
fsum
(1)
isinto
odd.
Therefore,
there
is
no
to
partition
F
(N
).
Proof.
Suppose
F
(N
=
F
(N
)(1).

(1).
Note
that
F
(N
))1can
contains

1)equal
elements.
N

this
sequence
dened
in
a
in
the
sense
that
Fsum
is
using
the
of
N/2
f
be
partitioned
into
two
multisets
mentioned
recurrence.
Therefore,
should
inspect
the
recurrence
formula
more
closely.
then
F
(N
)itaSuppose
is
ais
prex
of
F
with
length
three.
By
lemma
3,
F
(N
)way
Proof.
Suppose
F
(N
)F
=
F
)

felements.
(1).
Note
that
FN
)1two
Proof.
Suppose
F
(N
)of
=
F
(N
)even.

Note
that
(N
)(N
contains
N

1F
elements.
Since
N
The
(m
Proof.
F
(N
)into
=
(N
)even.

ffof
(1).
Note
that
F
(N
)into
contains
N

1N
elements.
Since
N

11N
(m
urrence.
Therefore,
we
should
inspect
the
recurrence
more
closely.
ikely
to
run
in)multiples
one
second,
we
can,
for
instance,
use
O(2
Meet
In
The
with
length
three.
By
lemma
3,
can
be
two
multisets
of
sum..
can
be
partitioned
into
two
equal
sum..
can
be
partitioned
two
of
equal
sum..
frefore,
equal
sum.
Proof.
F
(N
)all
F
(N
)unlikely

fF
(1).
Note
that
F
))an
contains
N
Since

(mod
w
haveN

1of

0multisets
(mod
3).
By
lemma
3,
F
(N
)(N
can
be
partitioned
into
two
of(N
equal
into
Middle
be
partitioned
two
multisets
of
equal
sum..
sum.3),
for
large
value
of
N
,elements
it
is
to
be
able
to
nd
algorithm
that
nds
Amultisets
and
B
in
an
elements
multisets
of

ln).
elements
in
F
)
is
even.
However,
the
sum
of
all
in
F
(N
)
=
F
(N
)
+
f
(1),
which
is
odd
1).
Note
that
F
(N
)
contains
N

1
elements.
Since
N
1
(mod
3),
we
sum
in
F
(N
)
is
even.
However,
the
sum
of
all
elements
in
)
=
F
(N
)
+
f
(p

is
even.
However,
the
sum
of
all
elements
in
,
which
is
because
F
(N
)
is
even
while
f
(1)
is
odd.
Therefore,
there
is
no
way
to
(N
sum
of
all
elements
in
F
(N
)
is
even.
However,
the
sum
of
all
elements
in
F
(N
)
=

because
F
(N
)
is
even
while
f
(1)
is
odd.
Therefore,
there
is
no
way
to
partition
F
(N
).
by
the
construction
of
the
function.

because
F
(N
)
is
even
while
f
(1)
is
odd.
Therefore,
there
is
no
way
to
partition
F
(N
).
more
N/2
Note
that
F
(N
)
contains
N

1
elements.
Since
N

1
(mod
3),
we
haveN

0
(mod
3).
By
lemma
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum
ce.
Therefore,
we
should
inspect
the
recurrence
formula
closely.
hen
F
(N
)
is
a
prex
of
F
with
length
multiples
of
three.
By
lemma
3,
F
(N
)

sets
of
equal
sum..
haveN

0
(mod
3).
By
lemma
3,
F
(N
)
can
be
partitioned
into
tw
haveN

0
(mod
3).
By
lemma
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum.
Th
We
will
rst
We
prove
will
rst
the
prove
following
the
following
two
lemmas.
two
lemmas.
haveN

0
(mod
3).
By
lemma
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum.
Th
em
SUBSET-SUM.
O(2
) (N
is
still
tobe
Npartitioned
, nitthe
is
faster
than
n

1)
+
f (n

2),
nisWhile
>
213).is
F(N
1Theorem
elements.
Since
N

haveN
be
1this

0sequence
By
lemma
3,
Fexponential
(N
)(1)
can
be
partitioned
into
two
of
equal
sum.
Therefore,
th
(mod
sum
all
elements
F
)while
is
even.
However,
the
sum
of
all
elements
in to
F
(N
)two
=
F
) +). f3),
(1),F (N
wh
1,two
n
=
1to
=
2much
like
N
ay.
However,
dened
inwith
very
special
way,
in
sense
that
F
is
dened
using
the
Ifof
N
divisible
by
three,
then
F
(N
))multiples
can
two
multisets
equal
sum.
while
Any
subsequence
of
Fwe
length
of
three
can
partitioned
into
multisets
ma
3.
=
(N
)is)can
fconsecutive
(1).
Note
that
Finto
(N
)
contains
N

1
elements.
Since
N

1into
(mod
3),
we
Theorem
4.
If
2is
(mod
3).
F
(N
can
be
partitioned
into
two
multisets
of
equal
sum.
subsequence
of
F
with
length
of
can
be
partitioned
into
two
multisets
F
) Pick
even
while
f1(mod
is=
odd.
Therefore,
there
is
no
way
partition
F
(N
).
,nsecutive
(N
partitioned
multisets
of
equal
sum.
Therefore,
the
odd
because
in
is3),
even
length
is
odd.
Therefore,
there
is
no
way
partition
because
Fsubsequence
(N
)(N
even
f
is
odd.
there
ismultisets
no
way
to
partition
F
(N
Theorem
3.
Ifin
N
1)(N
(mod
because
Faof
(N
)be
is
even
while
fTherefore,
(1)
is
Therefore,
there
is
no
way
partition
F
Theorem
3.
If
N
1be
(mod
3),
Fwe
(N
)of
cannot
be
partitioned
i(
F

Theorem
3.
If2.
N

(mod
3),
F
)F
cannot
partitioned
into
two
multisets
of
equal
sum.
any
consecutive
with
multiples
of
three,
which
will
denote
by
F
=
roof.
odd.
to
multiples
multisets
N
Theorem
3.
If
N
1three
(mod
3),
F
(N
)the
cannot
be
partitioned
into
two
of
equ
f(1)
(n)
heorem
3.
Ifsolve
N

1
(mod
3),
F
(N
)
cannot
be
partitioned
into
two
multisets
of
equal
sum.
,ets
F of
(N
)can
can
be
partitioned
into
two
multisets
of
equal
sum.
Therefore,
the
3.4
Finding
Special
Cases
sum
all
elements
in
F
(N
)
is
even.
However,
sum
of
all
elements
F
(N
=
F
(N
)
+
f
equal
sum..
range
(N
of
sum
of
all
elements
in
F
(N
)
is
even.
However,
the
sum
of
all
elements
sum
of
all
elements
in
(N
)
is
even.
However,
the
sum
of
all
elements
in
F
(N
)
=
F
(N
)
+
f
(1),
w
sum
of
all
elements
in
F
(N
)
is
even.
However,
the
sum
of
all
elements
in
F
)
=
F
(N
)
+
f
(1),
w
that
it
is
twice
the
of
N
using
a
O(2
)
solution.
wo
multisets
of
equal
sum.
Therefore,
the
sum
of
all
elements
in
F
(N
)
is
even.
However,
the
sum
of
all
elements
in
F
(N
)
=
F
(N
)
+
f
(1),
which
is
od

Theorem
4.
If
know
2then
(mod
3).
F
(N
)
can
be
partitioned
intomultisets
twoofmult
because
F
(N
)Sinto
is
while
ff3).
(1)
is (N
odd.
Therefore,
there
no
way
tothen
partition
F is
(N
).sum.
F
Theorem
4.
If
N

22N
(mod
F
(N
)) +
can
be
partitioned
into
two
multisets
of
equal
Theorem
2.
If+
N
is
divisible
by
three,
Fis
(N
)closely.
can
be
partitioned
into
two
o(
Theorem
4.
If
N

(mod
3).
(N
can
be
partitioned
into
two
multisets
of
equal
sum.
recurrence.
Therefore,
we
should
inspect
the
recurrence
formula
more
E),
tive
subsequence
of
F
with
length
multiples
of
three
can
be
partitioned
into
two
multisets
feven
(n

1)
(n

n
>
2Nto
we
dene
Fsum
)of
be
the
rst
terms
of
F
We
want
ual
sum.
By
lemma
3,
Ff(N
(N
)to
can
be
partitioned
into
two
multisets
of
equal
sum.
Therefore,
the
.of
However,
the
all
elements
in
F
(N
)
=
F
)
f
(1),
which
is
odd
F
(N
)
cannot
be
partitioned
two
multisets
of
equal
sum.
Lemma
1.
Lemma
1.
If
S

V
If
is
an

INDEPENDENT-SET
V
is
an
INDEPENDENT-SET
of
graph
of
G(V,
graph
G(V,
then
E),
V
S
is
V
a

VERTEX-COVER
S
a
VERTEX-COV
the
dand
into
two
multisets
equal
sum.
.2),

foned
(a),
f
(a
+
1),
(a
+
2),
...f
(b)}
for
some
a
<
b.
We
can
partition
F
into

(N
sum
elements
in
F
(N
)4.
=
F
) B.
+
fSince
(1),
which
isof
odd
(N
because
F
(N
is(1).
even
while
f3).
(1)
is
odd.
Therefore,
is
no
way
to
partition
F=
(NFF
).
If=2N
by
then
F
(N
)Therefore,
is
a
prex
ofcan
F
with
length
multiples
of
three.
By
lemma
3,
is
there
Fway
F
(N
)contains
isSuppose
even
while
fiselements.
(1)
odd.
Therefore,
there
no
to
because
FF
(N
is
even
while
(1)
isto
odd.
Therefore,
there
no
way
to
partition
F
(N
).
because
F
(N
)f)which
is
even
while
fffbecause
(1)
is
odd.
Therefore,
there
way
to
partition
F
).
divisible
Proof.
(N
now
Proof.
Assign
(1)
A
and
(2)
fisbe
(1)
=
f
we
are
partition
(N
4.
If
N
(mod
3).
(N
))three,
can
be
partitioned
into
two
multisets
sum.
sHowever,
inProof.
F
(N
)the
F
(N
)Theorem
+
fno
(1),
is
odd
4.
If
N

2Note
(mod
F
(N
)(N
partitioned
into
multisets
equal
sum.
Proof.
Suppose
F
(N
)multisets
(N
)F

f) )(=
IOI,
because
F
(N
)of
is
while
f)to
(1)
is
odd.
there
to
partition
F
(N
).into
)3).
Theorem
Ifthat
N
2=
FN
(N
)equal
can
be
partitioned
two
of
equ
(N
)no
=
F
(N
)Since

(1).
Note
that
(N
) con
Suppose
F
(N
)all
=
F
(N
)
fall
F
(N
)paper.
N
1is
N
1of
(mod
3),
we
Proof.
Suppose
Fin
(N
)(N
F
(1).
Note
that
Ftwo
(N
)ftrying
contains
N
is13),
elements.
ble
approach
in
and
thus
is
main
focus
of
this
To
solve
IOI
2008
Island
nto
disjoint
multisets
A
and
B
such
that
the
sum
of
all
elements
oof.
Suppose
Fthere
(N
){f
=even
F
(N
fthe
(1).
Note
that
FFAssign
contains
F
1(2),
elements.
Since
N
1to
(mod
we
(N
)two
is
even.
However,
the
sum
of
elements
(N
))(mod
=
F
(N
)fno
+
fway
(1),
which
is
odd
FProof.
(N
)Therefore,
cannot
be
partitioned
into
two
multisets
of
equal
sum.
dd.
is
way
to
partition
F
(N
).

graph
G(V,
graph
E)
G(V,
E)
are no
we
denote
Proof.
f
(1)
to
A
and
f
(2)
to
B.
Since
f
(1)
=
f
(2),
Theorem
4.
If
N

2
(mod
3).
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum.
Any
consecutive
subsequence
of
F
with
length
multiples
of
three
can
be
partitioned
into
two
multisets
.onsecutive
r
the
sequence
F
=
(n)}
,
and
we
dene
to
be
the
rst
N
terms
of
F
.
We
want
to
know

Proof.
Assign
f
(1)
to
A
and
f
(2)
to
B.
Since
f
(1)
=
f
(2),
we
are
now
trying
to
partition
F
(N
)
=
Theorem
4.
If
.

can
be
partitioned
multisets
of
equal
Proof.
If
N
is
divisible
by
three,
then
F
(N
)
is
a
prex
of
F
with
length
multiples
of
thre
dd.
Therefore,
there
is
no
way
to
partition
F
(N
).

Proof.
Assign
f
(1)
to
A
and
f
(2)
to
B.
Since
f
(1)
=
f
(2),
we
are
now
trying
to
partition
F
(N
)
=
can
be
partitioned
into
two
multisets
of
equal
sum..

Pick
any
consecutive
subsequence
of
F
with
length
multiples
of
three,
which
we
will
by
F
=
n=1
subsequence
of
F
with
length
multiples
of
three,
which
we
denote
by
Fthe
bnd

aa2
23).
blemma

a 1obtain

2=
f(mod
(1)
3).
fapproach.
(2).
F
(N
)We
will
have
N

elements.
Since
N
2will
(mod
3),
we
N

0By
(mod
3).
partition
F
).
haveN

3,
0function.
3).
lemma

f (1).
Note
F
(N
) Since
contains
N

12
elements.
Since
Nlemma

1be
(mod
3),
we
by
the
construction
of
1
ontains
10that
elements.

(mod
3),
we
haveN

0partitioned
(mod
By
F(mod
(N
) 2equal
can
be
partition
1N
1

(mod
3).
By
3,1
F
(N
)can
can
be
partitioned
into
two
multisets
equal
sum.
Therefore,
the mu
3.4
Finding
Special
Cases
haveN
0to
(mod
By
3,
Fthe
(N
)3).
can
be
partitioned
into
two
multisets
of3
we
need
to
use
this
must
special
constraint
in
problem
such
BhaveN
veN

0(N
By
lemma
3,
F
(N
)(mod
be
partitioned
into
two
multisets
of
equal
sum.
Therefore,
the
hile
fTheorem
(1)
is
odd.
Therefore,
there
is
no
way
partition
F
(N
).
Theorem
4.
Ifpartitioned
N

3).
F
(N
)A
can
into
two
multisets
of
sum.
be
Theorem
4.
If
N
2B
(mod
3).
F
(N
)of
be
partitioned
into
two
Theorem
4.
Iflemma
NN

(mod
3).
F
(N
can
be
partitioned
into
two
multisets
of
equal
sum.
Theorem
4.
If
N

22
(mod
3).
F
(N
)})we
can
partitioned
into
two
multisets
of
equal
sum.
A
=
{f
(a
+
3k),
0
k

{f
(a
+
1
+
3k),
0

}
can

ssign
f
(1)
to
A
and
f
(2)
to
B.
Since
f
(1)
=
(2),
are
now
trying
to
partition
F
(N
)
=
F
(N
)

Proof.
Assign
f
(1)
to
A
and
f
(2)
to
B.
Since
f
(1)
=
f
(2),
we
are
now
trying
to
partition
F
4.
If
N

2
(mod
3).
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum.
f
(1)

f
(2).
F
(N
)
will
have
N

2
elements.
Since
N

2
(mod
3),
we
Proof.
Assign
f
(1)
to
A
and
f
(2)
to
B.
Since
f
(1)
=
f
(2),
we
are
now
trying
to
um.
can
create
a
partition
of
F
(N
)
into
two
disjoint
multisets
and
such
that
the
sum
of
all
elements
sum.

f
(1)

f
(2).
F
(N
)
will
have
N

2
elements.
Since
N

2
(mod
3),
we
obtain
N

0
(mod
3).
can
be
into
two
multisets
of
equal
sum..

f
(1)

f
(2).
F
(N
)
will
have
N

2
elements.
Since
N

2
(mod
3),
we
obtain
N

0
(mod
3).

utive
subsequence
FF
length
multiples
of
we
will
denote
by
F
with
even.
,aum
(a
+
1),
f(b)}
for
some
aHowever,
<
b.
We
can
partition
F
into
2),
...f
some
acontains
<
b.
We
can
partition
Fthree,
into
a which
3,+for
F2),
(N
) (N
can
be
partitioned
into
multisets
of
equal
which
our
theorem.
3two
3of

(1).
Note
Fof
(N
)(b)}
N

1
elements.
Since
N

1elements
(mod
3),
we
)ff+
can
be
partitioned
into
two
multisets
of
equal
sum.
sum
of
all
elements
inwhich
Fthe
)(N
is (N
ma
3,
F
(N
)(athat
can
be
partitioned
into
two
multisets
of
equal
Therefore,
the
Proof.
Proof.
Let
us
assume
Let
us
that
assume
V

that
S
is
not

S
athe
VERTEX-COVER.
is
not
VERTEX-COVER.
Therefore,
Therefore,
there
are
two
are
two
A,
vertices
B

/odd
V)even.
A,

BF
S
oned
two
multisets
of
equal
sum.
Therefore,
the
sum
of
in
F(N
(N
)implies
is
sum
of
ofinto
all
elements
in...f
(N
)fis
is
even.
the
sum
of
all
elements
in
F(N
)=
=
F (N
(N
)+
+fHowever,
fvertices
(1),
sum
all
elements
in
F
(N
)sum.
isall
However,
the
sum
all
elements
in(N
Fis
=
ows
problem
to
be
solvable
in
polynomial
time.
We
can
check
whether
additional
Proof.
Assign
(1)
and
fN
(2)
to
B.
Since
feven.
(1)
=
fsum,
(2),
we
are
now
trying
to
partition
F
)all
=
be
m
of
all
elements
F
even.
However,
sum
of
all
elements
in
F
F
)there
(1),
which
odd
)2).
can
partitioned
into
two
multisets
of
equal
of
Theorem
3.
If
N

1
(mod
3),
FA
(N
)V
cannot
be
partitioned
into
two
multisets
of
equal
sum.
sum.
in
F
Fthe
(N
)for
will
have
N

2)We
elements.
Since

2N
(mod
3),
we
obtain
Ninto
which
2an
0multisets
(mod
3).
By
lemma
ultisets
of
equal
sum.
pproach
IOI,
and
thus
is
the
main
focus
of
this
paper.
To
solve
IOI
2008
Island
fbe
(1)
fAssign
(2).
Fto
(N
)two
will
have
equal
2to
elements.
Since
N

2)
(mod
3),
we
obtain
N
iswhich
2obtain

0F
(mo
Theorem
2.
If
N
is
divisible
by
three,
then
(N
)
3,
F
(N
)
can
be
partitioned
two
of
equal
sum,
f
(1)

f
(2).
(N
)
have
N

2
elements.
Since
N

2
(mod
3),
we
N
al
to
the
sum
of
all
elements
in
B
in
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum,
which
implies
our
theorem.
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum,
implies
theorem.
our
will
impl

2
),
...f
(b)}
some
a
<
b.
can
partition
F
into

mod
3).
F
(N
)
can
partitioned
into
multisets
of
equal
sum.
Proof.
f
(1)
to
A
and
f
(2)
B.
Since
f
(1)
=
f
(2),
we
are
now
trying
to
partition
ma
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
sum.
Therefore,
the

because
F
(N
)
is
even
while
f
(1)
is
ven.
However,
sum
of
all
in
F
(N
)Since
F
(N
)B
+
fno
(1),
which
is
odd
Assign
fno
to
A
and
to
Since
fby
(1)
=
f
(2),
weF
are
Proof.
Assign
f)a2elements
(1)
A0with
and
fis
(2)
to
Since
(1)
=
(2),
we
are
now
trying
to
partition
F
(N
)no
and
is
an
there
edge
isF
connecting
an
connecting
A
and
B.
A
Since
and
A,
/(1)
VF
A,

B
S,

/
we
V
have

S,
A,
we
B

S.
A,
As
Bnotwo
A

S.
and
As
B
A
are
connected
B
are
cs
Proof.
Assign
f(N
(1)
to
A
and
f
(2)
to
B.
Since
ffway
(1)
ffpartition
(2),
we
are
now
trying
to
(N
all
elements
in
Fthe
(N
)problem
=
(N
+
(1),
odd
because
(N
)=
is
even
while
fB.
(1)
is
odd.
Therefore,
there
is(N
Proof.
Assign
f23k),
to
and
(mod
to
. 3),
Since
,(2)
we
are
now
trying
to
because
Fthere
(N
iseven
even
while
fisedge
(1)
is
odd.
Therefore,
there
to
F
(N
).
because
F
(N
)Proof.
even
while
f
(1)
is
odd.
Therefore,
there
is
way
to
partition
F
kcause
any
consecutive
subsequence
length
multiples
of
three,
which
will
F
=
Proof.
Assign
f3,
to
A
and
ftoF
(2)
to
B.
fB.
(1)
=
f(N
(2),
we
are
now
trying
to
partition
Fpartition
(N
=
F
(N
))n
f)is
(1)

f(1)
(2).
F
)isof
will
N

2=
elements.
Since
N
2whether
(mod
3),
we
obtain
N

2theorem.
0)and
(mod
3).
bwhich

2sum,
bwe

ahave

2denote
blem.
PARTITION
NP-hard
by
reduction
from
SUBSET is
}.
B
=
{f
(a
+
+

k
F
(N
)and
while
f
(1)
odd.
Therefore,
there
is
way
to
partition
F
(N
).
b

2
Theorem
3.
If
N
1
F
)
cannot
be
partitioned
into
multisets
of
equal
two
have
Therefore,
solving
this
problem
is
reduced
to
checking
N

1
(mod
3).
We
can
solve
this
can
be
partitioned
into
multisets
of
equal
which
implies
our
theorem.
B.
Since
f
(1)
=
f
(2),
we
are
now
trying
to
partition
F
(N
)
=
F
(N
)

eed
to
use
this
approach.
We
must
nd
a
special
constraint
in
the
problem
such
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum,
which
implies
our
k
F
)San
can
be
partitioned
into
two
multisets
equal
sum,
which
implies
our
theo
are
(a
+
Aby
{f
(a
0note

}+

{f
+
1f(N
+
3k),
0This

}contradiction.
3felements.
A
{f
(a
+
3k),
0we

}<
(N
{f
(a
+
1
3k),

}
3k),
B.
Since
(1)
=
(2),
we
now
trying
tofNote
partition
(N
)(1),
F
)

F
(N
)an
=
F
(N
)f)partition

felements.
fpartition
(2).
F0F
(N
)
will
have
N

2a1
elements.
Since
N

22
(mod
3),
we
sum
of
all
elements
in
F
(N
)
=
F
(N
)
+
which
isk22Ifis
odd
Proof.
Suppose
F
)will
=be
F
(N
)N

(1).
contains
elements.
Since

12whether
(mod
3),
we
there
f
)ven.
is=
odd.
Therefore,
is
no
way
to
F
).
(2).
F
)equal
will
have
N
2of
elements.
N
23).
(mod
3),
f=
(1)

(2).
F
(N
will
have
N(1)

2that
Since
N
(mod
3),
we
obtain
N(mod
then

(mod
3).
by
an
edge,
an
edge,
we
that
that
S3,
not
is
INDEPENDENT-SET.
not
an
INDEPENDENT-SET.
This
contradiction.
is
Therefore
Therefore

Slemm
is
Vowa1
partition
.
into
will
reduced
Since
fthe
(1)

ff(N
(2).
F
(N
))kis
will
have
N
2(N
elements.
Since
N

(mod
3),
obtain

00V
(mod
3).
no
way
to
partition
Fknote
(N
).
1),
f(2)
(a
2),
...f
(b)}
some
a
b.
We
can
F
now
trying
to
partition
F
(N
=
F
(N
Proof.
N
is
divisible
by
three,
F
(N
)N
is
a(N
b2(N

2)3),
bto
a=

2(N
fHowever,
f+
fto
(2).
F
)fafor
have

2
Since

2in
(mod
3),
we
obtain
N

2Since

0N
By
whether
Therefore,
solving
this
problem
to
checking

3,
F
(N
)
can
partitioned
into
two
multisets
of
sum,
implies
our
theorem.
s+
unlikely
to
be
able
to
nd
that
nds
A
and
B
an
Therefore,
solving
this
problem
is
reduced
checking
N

1a
(mod
3).
We
can
solve
this
3(1)
3elements.
Therefore,
solving
this
problem
is
reduced
to
checking
whether
N
)we
1sum.
(mod
3).
We
can
solve
this
3more
3have
and
f(1)
to
B.
Since
(1)
=
falgorithm
(2),
we
are
now
trying
toN
partition
F
(N
)which
=
Fequal
(N
We
will
provide
examples
of
special
cases
in
the
following
section.
lements.
Since
N

(mod
we
obtain
N

0
(mod
3).
By
lemma
he
problem
be
solvable
in
polynomial
time.
We
can
check
whether
an
additional
Theorem
4.
If
N

2
(mod
3).
F

Theorem
4.
If
N

2
(mod
3).
F
(N
)
can
be
partitioned
into
oks
like
a
classic
PARTITION
problem.
PARTITION
problem
is
NP-hard
by
reduction
from
SUBSETTheorem
4.
If
2
(mod
3).
F
(N
)
can
be
partitioned
into
two
multisets
of

f
(a
+
3k),
0

{f
(a
+
1
+
3k),
0

}
Theorem
4.
If
N

2
(mod
3).
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
ba2
heorem
4.
If
N

2
(mod
3).
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum.
Proof.
Suppose
(N
)
=
F
(N
)

f
(1).
Note
that
F
(N
)
contains
N

1
elements.
Sin
ements.
Since
N

2
(mod
3),
we
obtain
N

0
(mod
3).
lemma
(mod
3).
By
lemma
3,
F
can
be
partitioned
into
sum,
which
implies
is
odd.
Therefore,
there
is
no
way
to
partition
(N
).
haveN

0
(mod
3).
By
lemma
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum.
Therefore,
the
,
we
obtain
.
By
lemma
3,

can
be
parti
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum,
which
imp
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum,
which
implies
our
theorem.
VERTEX-COVER.
VERTEX-COVER.
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum,
which
implies
our
theorem.
bWe

2provide
fore,
solving
this
problem
is sum,
reduced
to2two
checking
whether
N

13the
(mod
3).
We
can
solve
this
in
O(1).
bthe

we
obtain
N

2
0 provide
(mod
3).
Byas
lemma
Therefore,
this
problem
is
checking
whether
N
(mod
We
can solv
A
and
BF
have
the
same
for
every
0we

kdened

can
be
partitioned
into
two
multisets
sum
3,
(N
)We
can
be
partitioned
into
multisets
ofsum.
equal
sum,
which
implies
our
theorem.
will
more
examples
of
special
cases
in1 the
following
section.
Therefore,
solving
this
problem
is
reduced
to
checking
whether
N3).of
1 equal
(mod
3).o
3 into
ned
in
awill
very
special
way,
in
that
F
is
using
the
will
more
examples
of
special
cases
in
following
section.
We
will
more
examples
of
special
cases
the
following
section.
WAN
3nd
have
N
2abe
Since
N,3k),
20asolving
(mod
3),
obtain
Nreduced
2inchecking

0to
(mod
3).
By
lemma
multisets
of
equal
sum,
which
implies
our
theorem.
F=
(N
) for
can
partitioned
two
multisets
equal
bsense

2(mod
bcan

abe
N
2
}.
B
=
{f
(a
+
+

kaof}.

nto
two
multisets
of
equal
sum.
refore,
large
value
oftwo
N
it
isis
unlikely
toof
be
able
to
an
algorithm
that
nds
AF
and
B
in
anmultisets
B
{f
(a
+
2elements.
+
3k),
0provide

k2F

solving
into
Therefore,
this
problem
is
reduced
to
whether
1
(mod
3).
We
can
solve
this
haveN
1

0
3).
By
lemma
3,
F
(N
)
partitioned
two
of
equ
tioned
into
multisets
equal
sum,
which
implies
our
theorem.
multisets
of
equal
sum,
which
implies
our
theorem.
sum
of
all
elements
in
(N
)
even.
However,
the
sum
of
all
elements
in
F
(N
)
=
(N
)
+
f
(1),
which
is
odd

bspecial
a kf
2 3to
Atheorem.
=examples
{f
(arecurrence
+We
0
cases
}following
{f
(a
+
1and
3k),
0 are

kB.
Since
}section.
rovide
more
of
in provide
the
section.
plies
will
provide
more
examples
of
special
cases
innow
the
following
Proof.
Assign
fF(mod
(1)
to
AF
and
to
We
will
more
examples
of
special
cases
in
the
following
section.
Proof.
Assign
fG(V,
(1)
to
A
and
f=
(2)
to
Since
fwhether
(1)
=
fof
(2),
inspect
the
formula
more
closely.
Proof.
Assign
f0(1)
to3k),
A
and
(2)
B.
Since
fspecial
(1)
=
f+
(2),
we
now
trying
to
partition
(N
)We
=
F(N
(N)solve
)f(2)

Proof.
Assign
fproblem
(1)
to
A
fwe
(2)
to
fF
(1)
f1INDEPENDENT-SET
(2),
we
are
trying
to
oof.
Assign
(1)
to
A
and
fsolving
(2)
to
B.
Since
f3(a
(1)
=
fcases
(2),
are
trying
to
partition
F
(N
).the
=now
ned
into
two
ofTherefore,
equal
sum,
which
implies
our
theorem.
solving
this
isway,
reduced
to
checking
whether
N

1B.
3).
We
can
solv
F
(NHowever,
)our
can
befmultisets
partitioned
into
two
multisets
ofof
equal
sum.
}.
fould
(a
+
2
+
3k),

Therefore,
solving
this
problem
is
reduced
to
checking
N
p
Therefore,
solving
this
problem
is
reduced
to
checking
whether
N

(mod
3).
can
solve
thi
Lemma
2.
Lemma
2.
If
S

V
If
is
S
a

VERTEX-COVER
V
is
a
VERTEX-COVER
of
graph
of
G(V,
graph
E),
then
E),
V

then
S
is
V
an

S
is
an
INDEPENDENT-SE
the
Therefore,
solving
this
problem
is
to
checking
whether
N

1
(mod
3).
We
can
3
3
reduced
this
ay.
sequence
is
dened
in
a
very
in
the
sense
that
dened
using
this
Theorem
3.
If
N

1
(mod
3),
F
(N
)
cannot
be
Therefore,
solving
this
problem
is
reduced
to
checking
whether
N

1
(mod
3).
We
can
solve
this
in
O(1).
f
(a
+
3k)
+
f
+
1
+
3k)
=
f
(a
+
2
+
3k)
We
will
provide
more
examples
special
in
the
following
section.
Therefore,
this
problem
is
reduced
to
checking
whether
sum
of
all
elements
in
F
(N
)
is
even.
However,
the
sum
of
all
elements
in
F
(N
)
=
F
(N

because
F
(N
)
is
even
while
f
(1)
is
odd.
Therefore,
there
is
no
way
to
partition
F
(N
).
(mod
Fof

3
educed
to
checking
whether
N

1
3).
We
can
solve
this
in
O(1).
f
(1)

f
(2).
F
(N
)
will
have
N

2
e
2)
to
B.
Since
f
(1)
=
f
(2),
we
are
now
trying
to
partition
F
(N
)
=
(N
)

4
Some
example
special
cases

),
we
are
now
trying
to
partition
F
(N
)
=
F
(N
)

ba2
f
(1)

f
(2).
F
(N
)
will
have

2
elements.
Since
N

2
(m
foned
(1)

f
(2).
F
(N
)
will
have
N

2
elements.
Since
N

2
(mod
3),
we
obtain
N

0
(mod
3).
By
lemma
ba2
f
(1)

f
(2).
(N
)
will
have
N

2
elements.
Since
N

(mod
3),
we
obtain
N

2
1)

f
(2).
F
(N
)
will
have
N

2
elements.
Since
N

2
(mod
3),
we
obtain
N

0
(mod
3).
By
lemma
educed
to
checking
whether
N

1
(mod
3).
We
can
solve
this
in
O(1).
B
will
have
the
same
sum,
as
for
every
0

We
will
more
examples
ofin
special
cases
insection.
the
following
section.
the
same
sum,
as
for
every
0provide
kcan

We
will
provide
more
examples
of
special
cases
in the
following
section.
We
provide
more
examples
of
special
cases
in the
the
following
section.
graph
G(V,
graph
E)
G(V,
E)
We
will
provide
examples
of
special
cases
in
following
section.
inspect
recurrence.
Therefore,
we0more
should
the
recurrence
formula
more
closely.
with
length
multiples
of
three
be
into
two
multisets
sF
1
(mod
3).
We
can
solve
this
in
O(1).
3
We
can
solve
this
in
.
We
will
provide
more
examples
of
special
cases
the
following
3partitioned
odd.
because
F
(N
)
is
even
while
f
(1)
is
Therefore,
there
is
no
way
to
partition
F
(N
).

4
Some
example
of
specia
4
Some
example
of
special
cases
4
Some
example
of
special
cases

}.
B
=
{f
(a
+
2
+
3k),

problem
is
reduced
to
checking
whether
N

1
(mod
3).
We
can
solve
this
in
O(1).

)ial
B.)3),
Since
fpartitioned
(1)
=
(2),
we
are
now
trying
to
partition
Fwhich
(N
)Proof.
=
Fpartitioned
(N
)our
of
ial
cases
in
the
following
3,theorem.
Finto
)two
be(N
partitioned
into
two

2FTheorem
elements.
Since
2section.
(mod
3),(N
we
obtain
N

23,sum,
sum,
(mod
3).
By
lemma
(mod
wethe
obtain
N

03,ba2
(mod
3).
lemma
F0 (N
)into
be
equal
sum,
w
3,
(N
)can
can
be
partitioned
into
two
of
equal
implies
F
)(N
can
be
partitioned
into
two
multisets
equal
sum,
which
our
theore
Suppose
F(N
(N
)can
=multisets
F
) implies
of
f (1).
Note
tha
3can
ame
sum,
as
for
every
0f
k

Fto
(N
be
into
two
multisets
of
equal
which
implies
our
theorem.
cases
in
following
4.
If
NN
2section.
(mod
3).
Fmultisets
)By
be
two
multisets
of
equal
sum.
3 common
We
will
provide
more
examples
ofpartitioned
special
cases
in
the
following
section.
4
Some
example
of
special
cases
4theorem.
Some
example
of
special
cases
4three
Some
example
of
special
We
will
look
atfwhich
some
examples
of=
special
cases
that
may
occur
inistwo
competitive
programming
p
mples
ofimplies
special
cases
in
the
following
section.
Irvin
GUNAWAN
case
,onathan
2 elements.
Since
N

2proof
(mod
3),
we
obtain
N

0
(mod
3).
By
lemma
Any
consecutive
subsequence
of
F
with
length
multiples
of
can
be
partitioned
into
multisets
3k)
+
f
(a
+
1
+
3k)
f
(a
+
2
+
3k)
two
multisets
offour
equal
sum,
implies
our
Proof.
Proof.
The
proof
is
actually
is
similar
actually
to
similar
the
previous
to
the
lemma.
previous
Let
lemma.
us
assume
Let
us
that
assume
V

S
that
not
V

a
S
INDEPENDENT-SET
is
not
a
INDEPEND
(a
+The
3k)
+
(a
+
1
+
3k)
=
f
(a
2
+
3k)
which
theorem.
haveN
partitioned
1special
occur
0occur
(mod
3).
By
lemma
3,of
Fequal
(Noccur
) sum
can
Theorem
4.

2checking
(mod
3).
F (Ncases
)common
can
be
into
two
multisets
4Ifk NWe
Some
example
of
cases
ba2
will
look
at
some
examples
of
special
cases
that
may
We
will
look
at
some
common
examples
of
special
that
may
in
competitive
programming
p
We
will
look
at
some
common
examples
of
special
cases
that
may
in
competitive
programming
p
Therefore,
solving
this
problem
is
Therefore,
solving
this
problem
is
reduced
to
checking
whet
Therefore,
solving
this
problem
is
reduced
to
whether
N

1
(mod
3).
We
can
solve
this
in
O(1).
will
have
the
same
sum,
as
for
every
0

Therefore,
solving
this
problem
is
reduced
to
checking
whether
N

1
(mod
3).
W
this
problem
is
reduced
toV
checking
14
(mod
3). We
can
this
inB.
solve
3
flength
(asolving
+there
3k)
+are
fto
(a
+of
1vertices
+
3k)
=
(a
24
+BS
3k)
two
multisets
of
equal
sum,
which
implies
our
theorem.
Assign
f (1)
A
and
ftwo
(2)
tofB
B.
Since
fdenote
(1)
= Sfby(2),
we
are
now
trying
to
partition
Feven.
(N
)O(1).
=
Fspeci
)
m.
Therefore,
Therefore,
there
two
are
A,
vertices
+
A,

and
V whether

there
and
is
an
there
edge
connecting
anSome
edge
connecting
Ain
and
B.A
Since
and
A,
B
Since
(N
VA,
BS
Some
example
of
special
cases
example
of
4
Some
example
of
special
cases
f Therefore,
FProof.
with
multiples
three,
which
we
will
FinN
=
sum
ofis
all
elements
F
(N
)competitive
is
However,
4ofWe
Some
example
of
special
cases
ook
at
some
common
examples
special
cases
that
may
occur
competitive
programming
problems.
will
look
atN
some
common
examples
ofprovide
special
cases
that
may
occur
in
will
look
at
some
common
examples
of
special
cases
that
may
occur
in programm
competit
We
will
provide
more
examples
ofparti
speth
m
is
reduced
to(mod
checking
whether

1cases
(mod
3).
We
can
solve
this
in3),
O(1).
me
example
of
special
cases
hether
N

1
3).
We
can
solve
this
in
O(1).
We
will
more
examples
of
special
cases
in
the
following
We
will
provide
more
examples
of
special
cases
in
the
following
section.
We
We
will
provide
more
examples
of
special
cases
in
the
following
section.

e
will
provide
more
examples
of
special
in
the
following
section.
Proof.
Assign
f
(1)
to
A
and
f
(2)
to
B.
Since
f
(1)
=
f
(2),
we
are
now
trying
to

f
(1)

f
(2).
F
(N
)
will
have
N

2
elements.
Since
N

2
(mod
we
obtain
N

0
(mod
3).
By
lemma
me
cases
wecases
have
A,
we
BSome
have

/of
S.
A,
B

/+some
S.
and
As
A
and
connected
byof
an
edge,
by+Planar
an
we
edge,
note
that
weF
note
S occur
is
that
aS VERTEX-COVER.
iswhile
not fa(1)
VERTEX-COVER.
ispa
4.1
graphs
aial
< example
b.
We
can
partition
Fspecial
into
We
will
look
common
special
cases
that
may
in
competitive
programming
because
(N
)will
isnot
even
odd. This
Therefo
Irvin
GUNAWAN
Example
ofB
Special
Cases
fAs
(aatA
3k)
+
fare
(a
+ length
1Bexamples
+are
3k)connected
=
fcan
(a
+solve
2of
3k)
khan
any
consecutive
subsequence
of
Fsome
with
multiples
three,
we
denote
bycompetitive
F =isthat
mNAWAN
is4
reduced
to4.
checking
whether
N

1 F(mod
3).
We
this
inwhich
O(1).
Some
example
of
special
cases
special
in
the
following
section.
ng
section.
cases
4.1
Planar
graphs
4.1
Planar
graphs
We
will
look
at
common
examples
of
special
cases
that
may
occur
in
programm
4.1
Planar
graphs
We
will
look
at
some
common
examples
of
special
cases
may
occur
We
will
look
at
some
common
examples
of
special
cases
that
may
occur
in
competitive
programming
We
will
look
at
some
common
examples
of
special
cases
that
may
occur
in
competitive
programming
f
(1)

f
(2).
(N
)
will
have
N

2
elements.
Since
N

2
(mod
3),
we
obtain
N

3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum,
which
implies
our
theorem.
contradiction.
contradiction.
Therefore
Therefore
V

S
is
V
an

INDEPENDENT-SET.
S
is
an
INDEPENDENT-SET.
We
will
look
at
some
common
examples
of
special
cases
that
may
occur
in
competitive
programming
problems.
AN
es
ofaspecial
special
cases
that
maysome
occur
in
competitive
programming
problems.
+
1),
f(a
...f
(b)}
for
a in
< competitive
b.that
We
F ainto
b
2+ 2),
bPlanar
acan
be
2partition
Planar
graph
a (N
graph
drawn
on
at
surface
without
having
twographs
edges
o
special
cases
in
thethat
following
4.1
graphs
4.1
Planar
4.1
Planar
es
of
cases
may
programming
problems.
Theorem
4.
Ifgraphs
N
2which
(mod
3). Fcrossing
(N
) theorem.
caneach
be pa
3,isoccur
Fsection.
) can
be can
partitioned
into
two
multisets
of
equal
sum,
implies
our
r
in
competitive
programming
problems.
}

{f
(a
+
1
+
3k),
0

}
Planar
graph
is
aof
graph
that
can
be
drawn
on
ais can
at
surface
without
havi
4
Som
Planar
graph
is
aaproblem
graph
that
can
be
drawn
on
aaspecial
at
surface
without
having
two
edges
crossing
each
ot
4
Some
example
of
Planar
graph
is
graph
that
can
be
drawn
on
at
surface
without
having
two
edges
crossing
each
ot
4.1
Planar
graphs
4
Some
example
of
special
cases
mmon
examples
of
special
cases
that
may
occur
in
competitive
programming
problems.
4
Some
example
of
special
cases
et
al.
2001).
There
are
many
graph
problems
which
are
easy
to
solve
if
the
graph
is
planar.
We
will
prov
Therefore,
solving
this
is
reduced
to
checking
whether
N

1
(mod
3).
We
solve
this
in
O(1).
3GUNAWAN
3
4
Some
example
of
cases
Theorem
1.
1.
If
S

V
If
is
S
a

MAX-INDEPENDENT-SET
V
is
a
MAX-INDEPENDENT-SET
graph
G(V,
of
graph
E),
G(V,
then
E),
V

then
S
V
a
MIN-VERTEX-COVER

S
is
a
MIN-VERTE
rvinTheorem
We will look at someb
common
examples of special
casesPlanar
thatb may
occur
in4.1
competitive
a at

2graph
graphs
acrossing

2at
4.1
graphs
Planar
graphs
4.1
is
aAa
graph
that
can
be
drawn
onamany
agraph
without
having
two
each
Planar
graph
is
that
can
be
on
aProof.
surface
without
having
two
crossing
et
al.
2001).
There
are
many
graph
which
easy
solve
ifprov
thefc
Planar
graph
graph
that
can
be
drawn
on
aproblems
surface
without
having
two
edg
Some
example
cases
et
al.
2001).
There
are
graph
problems
which
are
easy
to
solve
the
graph
planar.
We
will
et
al.
2001).
There
are
problems
which
are
easy
to
solve
the
isisare
planar.
We
will
prov
faphspecial
cases
4.1
Planar
graphs
b

2of
Assign
fifif}(1)
tograph
A other
and
f(West
(2)
toto
B.
Since
=
{f
(a
+more
3k),
0of

kspecial
E).
}surface
is
{fathis
(a
1drawn
+
3k),
0Planar

kat
edges
Therefore,
solving
problem
is
reduced
to
checking
whether
N

1edges
(mod
3).
We
examples.
We
will
provide
examples
of many
special
cases
in +
the
following
section.
of
the
graph
the
G(V,
graph
E).
G(V,
4.1
Planar
graphs
programming
problems.
Planar
graph
is
a
graph
that
can
be
drawn
on
a
at
surface
without
having
two
edges
crossing
each
otm
}.
k

3
3
4.1
Planar
graphs
We
will
look
at
some
common
examp
We
will
look
at
some
common
examples
of
special
cases
that
We
will
look
at
some
common
examples
of
special
cases
that
may
occur
in
competitive
programming
problems.

1).
There
are
many
graph
problems
which
are
easy
to
solve
if
the
graph
is
planar.
We
will
provide
several
et
al.
2001).
There
are
many
graph
problems
which
are
easy
to
solve
if
the
graph
is
planar.
We
wi
We
will
look
at
some
common
examples
of
special
cases
that
may
occur
in
competitiv
ome
example
of
special
cases
examples.
et
al.
2001).
There
are
many
graph
problems
which
are
easy
to
solve
ifcrossing
the
graph
ishav
poeo
examples.
e will look
some
common
examples
of
special
cases
that
may
occur
in
competitive
problems.
3 at examples.
fasurface
(1)
surface
fcan
(2).
Fwithout
(N
)programming
will
have
Nsurface

2crossing
elements.
Sin
We
will
provide
more
examples
of
special
cases
in
the
following
section.
Planar
graph
is
a
graph
that
can
be
drawn
on
at
having
two
edges
crossing
Planar
graph
is
a
graph
that
be
drawn
on
a
at
without
Planar
graph
is
a
graph
that
can
be
drawn
on
a
at
surface
without
having
two
edges
each
Planar
graph
is
a
graph
that
can
be
drawn
on
a
at
without
having
two
edges
each
4.1
Planar
graphs
b

2
Planar
graph
is
a
graph
that
can
be
drawn
on
a
at
surface
without
having
two
edges
crossing
each
other
(Wes
etsurface
al.cases
2001).
There
are
many
graph
problems
which
are
easy
toThe
solve
ifthat
the
graph
is planar.
We
will
prov
amples
ofa =
special
that
may
occur
inproblems.
competitive
programming
problems.
mayProof.
occur
in
competitive
programming
only
rawn
on
at
without
having
two
edges
crossing
each
other
(West
examples.
Proof.
We
know
We
that
know
V

that
S
is
V
a

vertex
S
is
a
cover
vertex
by
cover
lemma
by
1.
lemma
The
1.
thing
only
thing
remains
that
for
remains
us
to
for
prove
us
to
is
it
p
examples.
}.
B
{f
(a
+
2
+
3k),
0

3,
F
(N
)
can
be
partitioned
into
two
multisets
of
ba2
awn
on
a
at
surface
without
having
two
each
other
(West
et
al.are
2001).
There
are
many
graph
problems
which
are
easy
to
solve
ifgraph
the graph
is planar.
Weifpro
wi
et al.crossing
2001).
There
are
many
problems
which
easy
to
th
etcrossing
al.
2001).
There
are
many
graph
problems
which
are
easy
to
solve
theplanar.
graph
planar.
Wesolve
will
pro
et
al.
2001).
There
are
many
graph
problems
which
are
easy
to
solve
ifif the
isisare
planar.
We
will
4.1.1
Number
of
edges
ving
two
edges
each
other
(West
3edges
ry
0 can

kal.
et
2001).
There
many
graph
problems
which
are
easy
to
solve
ifgraph
the
is
We
will
provide
examples.
mples
of
special
cases
may
occur
competitive
programming
problems.
3 Suppose
hat
be
drawn
on
atothat
at
surface
without
two
edges
crossing
each
other
(West
oblems
which
are
easy
solve
ifSthe
the
graph
isishaving
planar.
We
will
provide
several
V
4
is
VSome
not
inS
minimum
not
minimum
vertex
cover.
vertex
Then,
cover.
there
Then,
isgraph
another
there
is vertex
another
cover
vertex
V

cover
S severa
where
V
minimality.
minimality.
Suppose
example
of
special
cases
4.1.1
Number
of
edges
4.1
Planar
g
4.1.
Planar
Graphs
4.1.1
Number
of
edges
4.1
Planar
graphs
4.1.1
Number
of
edges
4.1
Planar
graphs
blems
which
are
easy
to
solve
if
graph
is
planar.
We
will
provide
several
examples.
examples.
examples.
examples.
4.1
Planar
graphs
he graph
is planar.
We
provide
several
examples.
ba2
will
graph
edges
provide
solving
Therefore,
this
problem
is cases
reduced
to ca
any
graph
are
easy
to
solve
the
is
planar.
We
will
several
InPlanar
simple
general
graph,
the
of
canBy
be
up
order
with
respect
the
4|Sedges
Some
example
ofindependent
special
ill
sum,
for
0
kimplies
ifnumber
the
|V
<
|V

S
which
<as
|V
which

S|,
implies
which
that
|S
|3 that
> of
|S|.
By
|>
lemma
|S|.
2,lemma
S
isto
an
2,a independent
Squadratic
isNumber
an
set.
Therefore,
set.
Therefore,
S to
is not
4.1.1
Number
4.1.1
Number
of
edges
4.1
4.1.1
of
edges
graphs
+ have
f |V
(a +
1Sproblems
+|same
3k)
=
f|S|,
(a
+
2graphs
+every
3k)
Planar
graph
iseach
awith
graph
that
can
bein
In
simple
general
graph,
the
number
of
edges
can
be
up
to
a
quadrat
Planar
graph
is
a
graph
that
can
be
drawn
on
a
at
surface
2
In
simple
general
graph,
the
number
of
edges
can
be
up
to
a
quadratic
order
with
respect
to
the
In
simple
general
graph,
the
number
of
edges
can
be
up
to
a
quadratic
order
respect
to
the
Planar
graph
is
a
graph
that
can
be
drawn
on
a
at
surface
without
having
two
edges
crossing
each
other
(West
4.1.1
Number
of
edges
Planar
graph
is
graph
that
can
be
drawn
on
a
at
surface
without
having
two
edges
We
will
look
at
some
common
examples
of
special
cases
that
may
occur
in
competitive
programming
problems.
We
will
provide
more
examples
of
special
cases
anar
graph
is
a
graph
that
can
be
drawn
on
a
at
surface
without
having
two
edges
crossing
other
(West
vertices
(i.e.
O(V
)).
This
is
not
the
case
for
planar
graph.
In
a
planar
graph,
we
may
show
that
Ednn
maximum
independent
independent
set. This set.
is a This
contradiction.
is a contradiction.
Therefore
Therefore
V S is Vthe
minimum
S is the minimum
vertex cover.
vertex cover. wi
4.1 maximum
Planar
graphs
2
2
4.1.1
Number
of
edges
2
4.1.1
Number
of
edges
4.1.1
Number
of
edges
4.1.1
Number
of
edges
general
graph,
the
number
of
edges
can
be
up
to
a
quadratic
order
with
respect
to
the
number
of
In
simple
general
graph,
the
number
of
edges
can
be
up
to
a
quadratic
order
with
respect
to
etis
al.
2001).
There
are
many
graph
pr
be
drawn
on
avertices
at
surface
without
having
two
edges
each
other
(West
Planar
graph
is
aet
graph
that
can
be
drawn
on
a2Therefore,
flat
surface
without
having
two
edges
vertices
(i.e.
O(V
)).
isgraph
not
case
for
planar
graph.
In
aeasy
planar
In
simple
graph,
the
number
of
edges
can
be
up
to
aO(V
quadratic
order
wi
without
having
two
edges
each
other
(West
fV(acrossing
+3graph
3k)
+
fThis
(a
+is
1general
+
3k)
=
fcrossing
(aal.
+
+
3k)
eteasy
2001).
There
are
graph
problems
are
to
(i.e.
O(V
)).
not
the
case
for
planar
In
athe
planar
graph,
we
may
show
that
E
et
2001).
There
are
many
problems
which
are
to
solve
ifgraph.
the
graph
planar.
We
will
provide
several
vertices
(i.e.
O(V
)).
This
issome
not
the
case
for
planar
graph.
Inmany
ais
planar
graph,
we
may
show
that
E
4.1.1
Number
of
edges
al.
2001).
There
are
many
graph
problems
which
are
easy
to
solve
ifwhich
graph
is plan
We
will
look
at
common
examples
of
special
cases
that
may
occur
in).the
competitive
pr
al.al.
2001).
There
are
many
graph
problems
which
are
easy
to
solve
ifThis
the
planar.
We
will
provide
several
holds
for

by
using
the
Eulers
formula.
number
of
edges
is
Naturally,
any
4.1.1
Number
of
edges
simple
general
graph,
the
number
edges
can
be
upthe
tograph.
a quadratic
order
with
respect
to
the
n
2 Number
2planar
2 of
4.1.1
of
edges
i.e.
O(VifFrom
)).which
This
is
not
the
case
for
graph.
In
a
planar
graph,
we
may
show
that
E

3V

6
be
drawn
on
aIn
at
surface
without
having
two
edges
crossing
each
other
(West
crossing
each
other
(West
etal.,
2001).
There
are
many
graph
problems
which
are
easy
vertices
(i.e.
O(V
)).
This
is
not
the
case
for
planar
In
a
planar
graph,
we
may
show
th
examples.
h solve
problems
are
easy
to
solve
if
the
graph
is
planar.
We
will
provide
several
the
From
above
the
theorem,
above
theorem,
we
conclude
we
conclude
that
a
MIN-VERTEX-COVER
that
a
MIN-VERTEX-COVER
can
be
easily
can
be
constructed
easily
constructed
if
we
have
if
holds
for
V

3
by
using
the
Eulers
formula.
Therefore,
the
number
of
vertices
(i.e.
O(V
)).
This
is
not
the
case
for
planar
graph.
In
a
planar
graph,
we
oamples.
the
graph
is
planar.
We
will
provide
several
examples.
holds
for
V

3
by
using
the
Eulers
formula.
Therefore,
the
number
of
edges
is
O(V
).
Naturally,
any
examples.
holds
for
V

3
by
using
the
Eulers
formula.
Therefore,
the
number
of
edges
is
O(V
).
Naturally,
any
examples.
that
has
O(E)
in
running
time
can
be
changed
into
O(V
).In
shortest
path
in
goaw
In(i.e.
simple
general
graph,
the
number
of up
edges
can
up
to
aofquadratic
order
with
to
2its
In
simple
graph,
the
number
edges
can
be
up
toarespect
ageneral
quadra
In
simple
general
graph,
the
number
ofgeneral
edges
can
be
upbeto
to
aaquadratic
quadratic
order
with
respect
to the
the
In
simple
general
graph,
the
number
of
edges
can
be
up
aComputing
order
with
respect
to
4.1.1
Number
of
edges
4.1
Planar
graphs
In
simple
general
graph,
the
number
of
edges
can
be
to
a
quadratic
order
with
respect
to
the
number
vertices
O(V
)).
This
is
not
the
case
for
planar
graph.
planar
graph,
we
may
show
that
E
4number
Some
exam
to
solve
graph
is
planar.
We
provide
several
examples.

3 by can
using
Eulers
formula.
Therefore,
the
number
ofits
is
O(V
).
Naturally,
any
algorithm
ofproblems
edges
can
bethe
up
toif
afor
quadratic
order
with
respect
tothe
the
number
of
hV
which
are
easy
to
solve
the
graph
is3will
planar.
We
will
provide
several
holds
V

3ifrunning
by
using
the
Eulers
formula.
Therefore,
the
number
of
edges
O(V
Naturall
MAX-INDEPENDENT-SET.
MAX-INDEPENDENT-SET.
that
has
O(E)
in
running
be
changed
into
O(V
).
Computin
holds
Vis

by
using
Eulers
formula.
Therefore,
theplanar
is O(
2path
2for
that
has
O(E)
in
time
can
be
changed
into
O(V
).
Computing
shortest
path
in
aedges
gr
2edges
that
has
O(E)
in its
its
running
time
can
be
changed
into
O(V
).
Computing
shortest
inshow
a).general
general
gE
22O(V
of
edges
be
up
to
athe
quadratic
order
with
respect
to
the
number
of
vin
GUNAWAN
Bellman-Ford
takes
O(V
E)
(Halim
&
Halim
2013),
but
only
takes
O(V
)isgraph.
in
aof
planar
graph
vertices
(i.e.
)).
This
is
not
the
case
for
planar
graph.
In
awe
planar
we
may
t
2
vertices
(i.e.
O(V
)).
This
istime
not
the
case
for
plana
vertices
(i.e.
O(V
)).
This
is
not
the
case
for
planar
graph.
Incan
a planar
planar
graph,
we
may
show
that
vertices
(i.e.
O(V
)).
This
not
the
case
for
planar
graph.
In
ait
graph,
we
may
that
4.1
Planar
graphs
atic
order
with
respect
to
the
number
ofinto
vertices
(i.e.
O(V
)).
This
is
not
the
case
for
planar
graph.
In
ato
planar
graph,
may
show
that
EIninashow
3V
E
holds
for
V

3algorithm
byup
using
the
Eulers
formula.
Therefore,
the
number
of
edges
isgraph,
O(V
).
Naturally,
any
2
2
thePlanar
number
of
edges
can
be
to
a
quadratic
order
with
respect
the
number
of
O(E)
in
its
running
time
can
be
changed
O(V
).
Computing
shortest
path
in
a
general
graph
using
case
for
planar
graph.
In
a
planar
graph,
we
may
show
that
E

3V

6
graph
is
a
graph
that
can
be
drawn
on
a
at
surface
without
having
two
edges
crossing
each
other
(West
that
has
O(E)
in
its
running
time
can
be
changed
into
O(V
).
Computing
shortest
path
a
gen
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
tp
that
has
O(E)
in
its
running
time
can
be
changed
into
O(V
).
Computing
shortest
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
)
in
a
planar
graph.
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
)
in
a
planar
graph.
4.1.1
Number
of
4.1.1
Number
of
edges
4.1.1
Number
of
edges
case
for
planar
graph.
In
a
planar
graph,
we
may
show
that
E

3V

6
the
number
of
connected
components
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
only
takes
holds
for
V

3using
byusing
thecan
Eulers
formula.
Therefore,
theatnumber
of).Therefore,
edges
is ).
O(V
Naturall
holds
for
V changed

3 Therefore,
by
using
the
Eulers
formula.
the
number
of
holds
for
in
3the
by
the
Eulers
formula.
Therefore,
the
number
of edges
edges
is O(V
O(V
).
Naturally,
an
holds
for
VV

3E
by
using
the
Eulers
formula.
the
number
of
is
Naturally,
any
4.1.1
Number
of
edges
ar graph,
we
may
show
that
graph
3V
6isformula.
holds
for that
Vbeginning

3the
byO(E)
using
Eulers
Therefore,
the
number
of
edges
is
Naturally,
any
algorithm
has
its
running
be
into
O(V
Computing
shortest
path
in
ain).
general
gr
We
will
look
some
common
examples
of
special
2).
2two
2i
4.1.1.
Number
of
Edges
his
is
not
the
case
for
planar
graph.
InHalim
aiswe
planar
graph,
we
may
show
that
Ein
asurface
3V
itO(V
62013),
Planar
atime
graph
that
can
be
drawn
on
athe
at
without
having
edges
cro
Ford
algorithm
takes
O(V
E)
(Halim
&
2013),
but
it
only
takes
O(V
)
planar
graph.
Counting
ormula.
Therefore,
number
of
edges
O(V
).
Naturally,
any
algorithm
et
al.
2001).
There
are
many
graph
problems
which
are
easy
to
solve
if
graph
is
planar.
We
will
provide
several
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
only
takes
O(V
)
a
planar
In
the
In
the
beginning
of
this
section,
of
this
section,
assume
we
we
assume
know
we
that
know
MIN-VERTEX-COVER
MIN-VERTEX-COVER
is
a
NP-hard
is
a
NP-hard
problem.
prob
It
the
number
of
connected
components
using
DFS
in
a
general
graph
takes
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
but
it
only
takes
O(V
the
number
of
connected
components
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
only
takes
4.1.1
Number
of
edges
the
number
of
connected
components
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
only
takes
of
edges
ormula.
Therefore,
the
number
ofalgorithm
edges
O(V
).
Naturally,
any
algorithm
planar
Therefore,
ifisrunning
the
problem
requires
usgeneral
to
compute
the
number
ofO(V
connected
components
that
has
O(E)
in
its
time
can
be
changed
into
O(V
).with
Computing
shortest
path
in
ausin
gen
that
has
O(E)
its
running
time
be
changed
into
O(V
).order
that
has
O(E)
in
its
running
time
can
be
changed
into
O(V
).
Computing
shortest
path
inthe
general
that
has
O(E)
in
its
running
time
can
be
changed
into
O(V
).
Computing
shortest
path
in
aabeComputi
general
g
fner
edges
is
O(V
).components
Naturally,
any
In
simple
general
graph,
number
that
has
O(E)
ingraph.
its
running
time
be
changed
into
O(V
).This
Computing
shortest
path
into
a2athe
general
Bellman-Ford
algorithm
takes
E)
(Halim
&
Halim
2013),
but
itcan
takes
)the
inin
anumber
planar
graph.
In
simple
graph,
the
number
of
edges
can
up
towe
simple
general
graph,
the
number
ofcan
edges
can
be
up
toin
abe
quadratic
order
respect
ofnumb
Ingraph,
simple
general
graph,
the
number
of
edges
can
be
up
to
ato
with
In
simple
general
the
number
of
edges
can
up
to
quadratic
order
respect
simple
general
graph,
the
number
of
edges
can
be
up
to
a).
quadratic
order
with
the
number
of
the
Eulers
Therefore,
the
edges
is
O(V
Naturally,
any
algorithm
et
al.
2001).
are
many
graph
problems
are
easy
towith
ifquadratic
graph
isthe
planar.
of
connected
using
DFS
in
aO(V
general
graph
takes
O(V
+a000,
E),
but
itonly
only
)new
a2components
be
changed
into
O(V
).
Computing
shortest
path
in
arequires
general
graph
using
examples.
the
number
of
connected
components
using
DFS
in
awhich
general
graph
takes
O(V
+
E),
but
itsolutio
only
good
to formula.
know
good
as
to
many
know
NP-hard
as
many
problem
NP-hard
as
possible.
as
possible.
This
isus
necessary
is
necessary
so
that
if
so
we
that
encounter
ifthe
we
encounter
problem
agraph
new
X,
prob
planar
graph.
Therefore,
if
the
problem
requires
us
to
number
of
connected
components
using
DFS
in
arespect
general
graph
takes
O(V
+
E)ii
4.1.1
Number
of
edges
2solve
planar
graph.
Therefore,
ififThere
the
problem
to
compute
the
number
of
connected
planar
graph.
Therefore,
the
problem
requires
us
to
compute
the
number
of
connected
components
22compute
be
changed
into
O(V
).
Computing
shortest
path
in
a
general
graph
using
2
graph,
even
though
the
constraint
states
that
V

100,
E

100,
000
,
standard
DFS
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
)
in
a
planar
2
2
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
)
in
a
planar
graph
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
)
in
a
planar
graph
2
2&
path
in
awith
general
graph
vertices
(i.e.
)).
This
isgraph.
not
the
mber
of(i.e.
edges
can
be
up
to
aonly
quadratic
order
respect
to
number
of
2the
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
Halim
but
itto
only
takes
O(V
)and
inaO(V
athus
planar
graph.
Countin
oing
a shortest
quadratic
order
respect
to
the
number
of
the
number
of
connected
components
using
DFS
in
ato
general
graph
takes
O(V
+
E),
it3V
only
takes
vertices
(i.e.
O(V
)).
This
is
not
case
for
planar
IO
2planar
vertices
O(V
)).
This
not
the
case
for
planar
graph.
In
athe
planar
graph,
we
may
show
that
E

3V

6conne
to
number
of
vertices
(i.e.
).
This
is
not
case
for
planar
graph.
In
planar
vertices
(i.e.
O(V
)).
This
is2013),
the
case
for
planar
graph.
In
a100,
planar
graph,
wealso
m
22the
rtices
O(V
)).
This
is
not
the
case
for
graph.
In
a
planar
graph,
we
may
show
that
Ebut

6100,
ning
time
can
be
changed
into
O(V
).using
Computing
shortest
path
in
aof
general
graph
using
examples.
P
aph.
Therefore,
if2013),
the
problem
requires
us
to
compute
the
number
connected
components
in
athe
planar
(Halim
&(i.e.
Halim
but
itisthe
takes
O(V
inwith
planar
graph.
Counting
planar
graph.
Therefore,
the
problem
requires
us
compute
the
number
of
connected
compon
can
use
any
can
of
use
the
any
NP-hard
of
problems
NP-hard
problems
that
we
know,
we
reduce
know,
itthe
reduce
problem
it
to
X,
problem
and
thus
X,compute
prove
that
prove
X
is
that
also
X
NP-hard
is
graph,
even
though
the
constraint
states
that

000,
E
4.1
00
2if
planar
graph.
Therefore,
ifusing
the
problem
requires
us
to
number
of
graph,
even
though
the
constraint
states
that
Vnot
100,
000,
E

100,
000
the
standard
DFS
solution
even
though
the
constraint
states
that
V

100,
000,
E

100,
000
,, V
the
standard
DFS
solution
2 graph,
Halim
&
Halim
2013),
but
it
only
takes
O(V
))Therefore,
in
aathat
planar
graph.
Counting
under
one
second
(in
competitive
programming,
we
assume
that
1number
million
operations
can
be
done
in
the
number
of
connected
components
DFS
in
aedges
general
graph
takes
O(V
+
E),
but
it
only
the
number
of
connected
components
using
DFS
in
a
general
graph
take
the
number
of
connected
components
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
only
takes
the
number
of
connected
components
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
only
takes
mber
of
edges
can
be
up
to
a
quadratic
order
with
respect
to
the
number
of
y
takes
O(V
)
in
a
planar
graph.
Counting
holds
for
V

3
by
using
the
Eulers
f
t
the
case
for
planar
graph.
In
a
planar
graph,
we
may
show
that
E

3V

6
the
number
of
connected
components
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
only
takes
O(V
)
in
2
In
a
planar
graph,
we
may
show
that
E

3V

6
planar
graph.
Therefore,
if
the
problem
requires
us
to
compute
the
of
connected
components
i
holds
for
V

3
by
using
the
formula.
Therefore,
the
n
2
graph,
we
may
show
that

holds
for

by
using
the
Eulers
holds
for
V

3
by
using
the
Eulers
formula.
the
number
of
is
O(V
).
Naturally,
any
algorithm
2 still
holds
for
V
3though
by
using
the
Eulers
formula.
Therefore,
the
number
of
edges
2 isDFS
olds
for
the
by
using
the
Eulers
formula.
Therefore,
the
of
is programming,
O(V
).
Naturally,
any
algorithm
akes
O(V
E)
& Halim
2013),
but
it+
only
takes
O(V
)number
inthat
awe
planar
graph.
Counting
en though
constraint
states
that
V even

100,
000,

100,
000
,assume
the
standard
DFS
solution
runs
using
DFS
in3(Halim
aunder
general
graph
takes
O(V
E),
but
itEthe
only
takes
O(V
) edges
in
athat
graph,
even
though
the
constraint
states
V
100,
000,

100,
000
, of
the
standard
s
under
one
second
(in
competitive
we
assume
that
1O(V
mill
graph,
constraint
states
V

100,
000,
E

100,
000
,the
the
sta
4.1.1
Number
of
edges
under
one
second
(in
competitive
programming,
that
11E
million
operations
can
be
done
in
one
second
(in
competitive
programming,
we
assume
that
million
can
be
done
in
1V
1 We
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
only
takes
O(V
)
in
a
(Halim
&
Halim
2013)).
planar
graph.
Therefore,
if
the
problem
requires
us
to
compute
the
number
connected
compon
We
say
that
problem
say
that
X
problem
is
reducible
X
is
to
reducible
problem
to
Y
problem
Y
2 operations
planar
graph.
Therefore,
if
the
problem
requires
us
to
compute
num
planar
graph.
Therefore,
if
the
problem
requires
us
to
compute
the
number
of
connected
components
planar
graph.
Therefore,
if
the
problem
requires
us
to
compute
the
number
of
connected
components
Planar
graph
is
a
graph
that
can
be
drawn
on
a

the
case
for
planar
graph.
In
a
planar
graph,
we
may
show
that
E

3V

6
es
O(V
+
E),
but
it
only
takes
O(V
)
in
a
that
has
O(E)
in
its
running
time
can
ers
formula.
Therefore,
the
number
of
edges
is
O(V
).
Naturally,
any
algorithm
planar
ifthat
the
problem
requires
us
to
compute
the
number
of
connected
components
in
a plana
Therefore,
the
number
edges
is
.that
Naturally,
any
algorithm
that
has
Computing
in
its graph
number
of
edges
isTherefore,
O(V
).
Naturally,
any
algorithm
graph,
even
though
the
constraint
states
that
V

100,
000,
E

100,
000
,athe
standard
DFS
solution
has
O(E)
in
its
running
time
can
changed
into
O(V
).d
hat
has
O(E)
inits
its
running
time
can
be
changed
into
O(V
).2013)).
Computing
shortest
path
in
ageneral
general
using
has
O(E)
in its
running
time
can
be
changed
into
O(V
).
shortest
has
O(E)
in
running
can
be
changed
into
O(V
Computing
shortest
path
using
components
using
DFS
in
atime
general
graph
takes
O(V
+
E),
but
takes
O(V
)we
in
eat
second
(in
competitive
programming,
we
assume
that
1).
million
operations
can
be
done
inbe
second
m
requires
usgraph.
to
compute
the
number
of
connected
components
init
aonly
planar
under
one
second
(in
competitive
programming,
we
assume
that
1ain
million
can
bepa
4.1.1
Number
of
(Halim
&
Halim
under
one
second
(in
competitive
programming,
assume
that
1 graph
million
operati
21 operations
(Halim
&
Halim
2013)).
(Halim
&
Halim
2013)).
22 edges
m
requires
us
to
compute
the
number
of
connected
components
in
aV
planar
graph,
even
though
the
constraint
states
that

100,
000,
E
with
100,
,standard
the
standard
DFS
2There
graph,
even
though
the
constraint
states
that
Vthe

100,
000,
E 2013),

100,
graph,
even
though
the
constraint
states
that

100,
000,
E

100,
000
,000
the
standard
DFS
solutio
graph,
even
though
the
constraint
states
that
VV

100,
000,
E

100,
000
,graph
DFS
solutio
2
et
al.
2001).
are
many
graph
problems
which
2
rs
formula.
Therefore,
the
number
of
edges
is
O(V
).
Naturally,
any
algorithm
In
simple
general
graph,
the
number
of
edges
can
be
up
to
a
quadratic
order
respect
to
the
number
of
mber
of
connected
components
in
a
planar
Bellman-Ford
algorithm
takes
O(V
E)
eellman-Ford
can
be
changed
into
O(V
).
Computing
shortest
path
in
a
general
graph
using
running
time
can
be
changed
into
.
Computing
shortest
path
in
a
general
us2
graph,
even
though
the
constraint
states
that
V

100,
000,
E

100,
000
,
the
standard
DFS
solution
still
run
).
Computing
shortest
path
in
a
general
graph
using
under
one
second
(in
competitive
programming,
we
assume
that
1
million
operations
can
be
done
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
b0si
2
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
)
in
a
planar
graph.
Counting
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
takes
O(V
E)
& Halim
2013),
but itcomponents
only
takes O(V
) in a planar graph. Counting )in
ifHalim
the
problem
requires
compute
the
number
ofDFS
connected
in a planar
2013)).
tes
that
V
algorithm
100,
000,
Eus
to
100,
000(Halim
, the
standard
solution
still runs
runs
(Halim
&
Halim
22013)).
(Halim
& competitive
Halim
2013)).
2
2
es
that
V
100,
000,
E
100,
000
,
standard
DFS
solution
still
2
under
one
second
(in
programming,
we
assume
that
1
million
operations
can
be
2
under
one
second
(in
competitive
programming,
we
assume
that
1
mil
under
one
second
(in
competitive
programming,
we
assume
that
1
million
operations
can
be
done
under
one
second
(in
competitive
programming,
we
assume
that
1
million
operations
can
be
done
4.1.2
Maximum
Clique
examples.
In
simple
general
graph,
the
number
of
can
be
upgeneral
tomay
ait of
quadratic
order
with
can
changed
into
O(V
).
Computing
shortest
path
agraph.
general
graph
using
vertices
(i.e.
O(V
)).
This
is
not
the
case
for
In
aedges
planar
graph,
we
show
that
E
)in
3V
res
6gdibi
000
,(Halim
the
standard
DFS
solution
runs
the
connected
components
E)
&connected
Halim
2013),
itstill
only
takes
O(V
in
aincomponents
planar
graph.
Counting
under
second
competitive
programming,
we
assume
that
1O(V
million
operations
can
be
done
1in
2
but
itbe
only
takes
O(V
)(in
in
abut
graph.
(Halim
&
Halim
2013)).
the
number
connected
components
using
DFS
in
general
he
number
of
connected
components
using
DFS
ageneral
general
graph
takes
O(V
E),
but
only
takes
O(V
aE),
the
number
ofCounting
connected
using
DFS
inproblem
anumber
graph
takes
O(V
+
eonstraint
number
ofone
components
using
DFS
inin
a4.1.2
graph
takes
++
E),
but
itMaximum
only
takes
O(V
)ain
asecon
states
that
V

100,
000,
E

100,
000
,)planar
the
standard
DFS
solution
still
runs
gramming,
we
assume
that
1planar
million
operations
can
be
done
in
1of
second
4.1.2
Clique
probl
Maximum
Clique
problem
4.1.2
Maximum
Clique
problem
2
2
gramming,
we
assume
that
1
million
operations
can
be
done
in
1
second
(Halim
&
Halim
2013)).
(Halim
&
2013)).
(Halim
&
2013)).
(Halim
&
Halim
2013)).
vertices
(i.e.
O(V
)).
isifplanar
not
the
case
forofplanar
In
planar
graph,
we
may s
E)
(Halim
&&
Halim
2013),
but
it
takes
O(V
) to
in
aHalim
graph.
Counting
holds
for
VO(V
incan
3+
by
using
the
Eulers
formula.
Therefore,
the
number
edges
is O(V
). aNaturally,
any
algorithm
llion
operations
be
in
1only
second
planar
graph.
Therefore,
the
problem
ents
using
DFS
aMaximum
general
graph
takes
O(V
+
E),
but
it
only
takes
O(V
) of
in
aset
(Halim
Halim
2013)).
graph
takes
E),
but
itproblem
only
takes
) us
inThis
aoperations
planar
graph.
Therefore,
if graph.
the
problem
us
to
compute
planar
graph.
Therefore,
ifHalim
the
problem
requires
compute
the
number
connected
components
planar
planar
graph.
Therefore,
the
problem
requires
us
to
compute
the
number
of
connect
anar
graph.
Therefore,
ifdone
the
requires
us
to
compute
the
number
of
connected
components
inin
aifasuch
planar
mpetitive
programming,
we
assume
that
1O(V
million
can
be
done
in
1
second
The
Clique
problem
requires
us
to
nd
the
maximum
of
vertices
inrequires
a graph,
that
ev
4.1.2
Maximum
Clique
problem
4.1.2
Maximum
Clique
problem
4.1.2
Maximum
Clique
problem
2
2
holds
for
V

3
by
using
the
Eulers
formula.
Therefore,
the
number
of
edges
is
O(V
).sta
N
4.1.1
nts
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
only
takes
O(V
in
a
that
has
O(E)
in
its
running
time
can
be
changed
into
O(V
).
Computing
shortest
path
in
a
general
graph
using
graph,
even
though
the
constraint
oblem
requires
us
to
compute
the
number
of
connected
components
in
a
planar
2)
The
Maximum
Clique
problem
requires
us
to
nd
the
maximum
set
of
ve
te
the
number
of
connected
components
in
a
planar
graph,
even
though
the
constraint
states
that
V

100,
000,
E
The
Maximum
Clique
problem
requires
us
to
nd
the
maximum
set
of
vertices
in
a
graph,
such
that
eve
graph,
even
though
the
constraint
states
that
V

100,
000,
E

100,
000
,
the
standard
DFS
solution
still
runs
The
Maximum
Clique
problem
requires
us
to
nd
the
maximum
set
of
vertices
in
a
graph,
such
that
ev
4.1.2
Maximum
Clique
problem
graph,
even
though
the
constraint
states
that
V

100,
000,
E

100,
000
,
the
stand
aph, even though
the in
constraint
thatconnected
V 100,by
000,
100,
, the standard
DFS
solution
still runs cliqu
vertices
the set isstates
directly
an E
edge.
By 000
reduction
from vertex
cover,
the maximum
2
2
2
4.1.2
Maximum
Clique
problem
4.1.2
Maximum
Clique
prob
4.1.2
Maximum
Clique
problem
4.1.2
Maximum
Clique
problem
that
has
O(E)
in
its
running
time
can
be
changed
into
O(V
).
Computing
shortest
path
in
Clique
problem
requires
us
to
nd
maximum
set
of
vertices
inproblem
aconnected
graph,
such
that
every
of
oblem
requires
us
to
compute
the
number
of
connected
components
in
astill
planar
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
)can
abe
planar
graph.
Counting
The
Maximum
Clique
problem
requires
us
to
nd
the
maximum
set
of
vertices
in
acompetitive
such
th
under
one
second
(in
pro
tmum
that
V
100,
E

100,
000the
,connected
the
standard
DFS
solution
runs
vertices
incompetitive
the
is
directly
by
an
edge.
By
reduction
from
The
Maximum
Clique
problem
requires
us
to
nd
the
maximum
set
of
vertices
incliqu
ave
Estates

100,
000
,
the
standard
DFS
solution
still
runs
under
one
second
(in
competitive
programming,
assume
tg
vertices
in
the
set
is
directly
connected
by
an
edge.
reduction
from
vertex
cover,
the
maximum
under
one
second
(in
competitive
programming,
we
assume
that
1In
million
operations
done
in
1we
second
vertices
in000,
the
set
is
directly
by
an
edge.
By
reduction
from
vertex
cover,
the
maximum
cliqu
4.1.2
Maximum
Clique
under
one
second
(in
programming,
we
assume
that
1pair
million
operation
nder
second
(in
competitive
programming,
we
assume
that
1By
million
operations
can
be
done
in
1graph,
second
on
general
graph
is
NP-hard.
However,
it
isset
easy
to
solve
this
problem
inin
planar
graph.
Consider
th
simple
general
graph,
the
number
of
edges
ca
.1.2 one
Maximum
Clique
problem
The
Maximum
Clique
problem
requires
uscan
to
nd
the
maximum
set
of+vertices
in
aonly
graph,
such
that
eve
2
2
Maximum
Clique
problem
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
)
in
a
ne.1.2
the
set
is
directly
connected
by
an
edge.
By
reduction
from
vertex
cover,
the
maximum
clique
problem
states
that
V

100,
000,
E

100,
000
,
the
standard
DFS
solution
still
runs
the
number
of
connected
components
using
DFS
in
a
general
graph
takes
O(V
E),
but
it
takes
O(V
vertices
in
the
set
is
directly
connected
by
an
edge.
By
reduction
from
vertex
cover,
the
maximum
(Halim
&
Halim
2013)).
programming,
we
assume
that
1
million
operations
be
done
in
1
second
on
general
graph
is
NP-hard.
However,
it
is
easy
to
solve
this
problem
vertices
the
set
is
directly
connected
by
an
edge.
By
reduction
from
vertex
cover,
that
1
million
operations
can
be
done
in
1
second
(Halim
&
Halim
2013)).
on
general
graph
is
NP-hard.
However,
it
is
easy
to
solve
this
problem
in
planar
graph.
Consider
th
blem
on
general
graph
is
NP-hard.
However,
it
is
easy
to
solve
this
problem
in
planar
graph.
Consider
th
Halim & Halim 2013)).

is aPlanar
graph graph
that can
drawn
on can
a at
edgesNumber
crossing
each
other
(Westeach other (West
is abegraph
that
besurface
drawn without
on a athaving
surfacetwo
without
having
two
crossing
4.1.1
ofedges
edges
canSuppose
be
partitioned
two
ofedges
equal
sum..
There
many Number
graph
which
easy toProof.
solve
ifare
the
graph
is4.1.1
planar.
We
will
several
Number
ofNote
4.1.1
edges
4.1.1
Number
of
edges
et are
al.
2001).
Thereproblems
areof
many
graphare
problems
which
easy
to
if F
the
graph
isprovide
planar.
We
severa
F solve
(N
)into
=
(N
)multisets

f (1).
thatwill
F provide
(N ) contains
In simple general graph, the number
of
edges
can
be
up
to
a
quadratic
order
with4.1.1
respectN

4.1.1
Number
of
edges
examples.
haveN
number
1 03.(mod
3).
By
lemma
3,
F a(N
) can be
partitioned
int
2order
Iffor
N
1to
(mod
Fto
) graph
cannot
partitioned
int
general
graph,
the
edges
can
be3),
up
quadratic
order
with
res
ber of edges can
be up
toIna simple
quadratic
withisTheorem
respect
theof
number
of
In simple
general
graph,
the
of
can
be
up
agraph.
quadratic
order
with
to show
the
Planar
isbe
arespect
graph
that
can
vertices
(i.e.
O(V
)).number
This
notedges
the to
case
planar
In
a(Nplanar
graph,
we may

sum
of
all
elements
in
F
(N
)
is
even.
However,
the
sum
of
all
eleme
2
simple
general
the
of
edges
can
In
simple
upfor
graph,
order
the
with
number
respect
of edges
to
the
ca
vertices
O(V
)).
This
is not
the be
case
graph.
In2001).
aofplanar
graph,
we
may
the case for In
planar
In
graph,
we
may
show
that
E
3Vtoplanar
ageneral
vertices
(i.e.
O(V
)).
isnumber
not
the
case
for
planar
graph.
In6quadratic
athe
planar
graph,
we
may
show
En
et
There
are
many
gra
holds
foragraph,
V2planar
(i.e.
3This
by
using
the
Eulers
formula.
Therefore,
edges
is O(V
).that
J.I.
94 graph.
Gunawan
Proof.
Suppose
F (N
) =f F
(Nis)number
al.
f (1).
Note
that
F (N
)Natur
cont
4.1.1
Number4.1.1
of
edges
because
F
(N
) is
even
while
(1)
Therefore,
there
isO(V
no
way
2
2odd.
Number
of
edges
vertices
(i.e.
vertices
(i.e.
O(V
)).
This
is
not
the
case
for
planar
graph.
In
a
O(V
planar
)).
graph,
This
is
we
not
may
the
show
case
that
for
pla
E
holds
for
V

3
by
using
the
Eulers
formula.
Therefore,
the
number
of
edges
is
).
s formula. Therefore,
the
of in
edges
is O(V formula.
).
Naturally,
any algorithm
holds forthat
V number
3 by
using
the
Eulers
the number
edges is O(V
). Naturally,
examples.
has
O(E)
its running
time
canTherefore,
be
).of
Computing
in any
aN
g
haveN
1 changed
0 (modinto
3). O(V
By lemma
3, F (Nshortest
) can be2path
partitioned
holds
for
VO(E)

3edges
by
using
the
Eulers
Therefore,
holds
the
for
number

3F
by
ofbut
using
edges
the
isbe
O(V
Eulers
).O(V
Naturally,
formula.
any
Ther
has
O(E)
in
its
running
time
can
be
changed
into
O(V
).
Computing
shortest
can In
be
changed
into
).that
Computing
shortest
path
a 4.
general
graph
using
neral
graph,
the
number
of
can
be
up
toTheorem
aformula.
quadratic
order
with
respect
to
the
number
ofto
that
hasO(V
in
its
running
time
can
beinchanged
).V Computing
shortest
path
in a)number
general
gi
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
itcan
only
takes
in of
apath
plan
simple
general
graph,
the
number
of
edges
can
be
up
to
a
quadratic
order
with
the
of
ing
Bellman-Ford
algorithm
takes
(Halim
and
Halim,
2013),
itrespect
only
takes
If
Ninto
2O(V
(mod
3).
)but
partitioned
into
two
sum
of all
elements
in F 2013),
(N
) is(N
even.
However,
the
sum
2 allgre
2 takes
2
2 6takes
2
that
has
O(E)
in
its
running
time
can
be
changed
into
that
O(V
has
).
O(E)
Computing
in
its
running
shortest
time
path
can
in
a
be
general
changed
Bellman-Ford
algorithm
O(V
E)
(Halim
&
Halim
2013),
but
it
only
O(V
)
in
a
E)
&
Halim
2013),
but
it
only
)
in
a
planar
graph.
Counting
O(V(Halim
)).
This
is
not
the
case
for
planar
graph.
In
a
planar
graph,
we
may
show
that
E

3V

Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
it
only
takes
O(V
)
in
a
planar
graph
the
number
of
connected
components
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
on

in
a
planar
graph.
Counting
the
number
of
connected
components
using
DFS
in
vertices (i.e. O(V )). This is not the case for planar
graph.
In
planar
graph,
weis may
show
that E 3Vis
6
because
F f(N
) to
isa even
while
f (1)
odd.
Therefore,
no
2f (1) = fthere
A
(2)
toO(V
B.
Since
(2),
we
ar
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&edges
Halim
Bellman-Ford
but
algorithm
only
takes
takes
O(V
O(V
) of
inbut
E)
a planar
(Halim
graph.
&comp
Ha
the
number
of
connected
components
using
DFS
in
general
graph
O(V
E),
but
using
DFS
in
anumber
graph
takes
O(V
+ E),
but
itof
only
takes
)and
inNaturally,
afitaplanar
nts
3 by
using
Eulers
formula.
Therefore,
the
number
is
O(V
).
any
algorithm
of
connected
components
using
DFS
in(1)
a 2013),
general
graph
takes
O(V
+takes
E),
it +
only
takes
takes
,Therefore,
but
itAssign
only
takes
graph.
Therefore,
graph.
Therefore,
ifProof.
the
problem
requires
us
to
compute
the
number
connected
holds
forthe
Vthe
3general
byplanar
using
the
Eulers
formula.
the
number
of
edges
is
).
Naturally,
any
algorithm

simple
general
graph,
the
nu
f (2).
Fshortest
)requires
will
have
N

2EIn
elements.
Nit
only
2 (mod
3O
2bebut
the
number
of
connected
components
using
DFS
in
ato
the
general
number
graph
of
connected
takes
+
E),
using
DFS
takes
in
planar
graph.
Therefore,
ifrequires
the
problem
us
compute
the
number
of
connected
blem
requires
us time
to
compute
the
number
ofthe
components
in
a
) inthat
its
running
can
be
changed
into
O(V
).f (1)
Computing
path
in
ato
general
graph
using
if in
the
problem
requires
toconnected
compute
the
number
components
in
aSince
planar
graph.
Therefore,
ifus
the
problem
us
compute
the
number
of
connected
components
Theorem
4.(N
Ifof
N
2100,
(mod
3).
FO(V
(N
)components
can
partitioned
into
graph,
even
though
constraint
states
that
Vconnected
planar
000,

100,
000
, the
standard
DFS
has O(E)
its
running
time
can
be
changed
into
O(V
).
Computing
shortest
path
in
aplanar
general
graph
using
2
by the
construction
of
the
function.

2
vertices
(i.e.
O(V
)).
This
is
n
2
2
2
3,
F
(N
)
can
be
partitioned
into
two
multisets
of
equal
sum,
which
2 Eof
graph.
Therefore,
the
problem
us
planar
compute
graph.
the
Therefore,
number
if
connected
the
problem
requires
in
graph,
even
though
the
constraint
states
that
Vruns

000,
000
,components
the
standard
graph,
even
though
theif
constraint
that
the
standard
states
thattakes
Vplanar
O(V
100,
000,
E

100,
000
,2013),
the
standard
DFS
algorithm
E)
(Halim
&second
Halim
but
itrequires
only
takes
O(V
)only
in
aEassume
planar
graph.
Counting
graph,
even
though
the
constraint
states
that
Vsolution
to
100,
000,
100,
100,
000
,
the
standard
DFS
solutio
under
one
(in
competitive
programming,
we
that
million
operations
can us
be
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&states
Halim
2013),
but
itstill
takes
O(V
) 1,in
a100,
planar
graph.
Counting
by
the
construction
of
the
function.
2to for
Proof.
Assign
fassume
(1)
to
A
and
fmillion
(2)
B.
Since
fby
(1)
=
fdone
(2),
w
holds
V
a3
using
the
Eu
graph,
even
though
the
constraint
states
that
V

100,
graph,
000,
even
E

though
100,
000
the
,
constraint
the
standard
states
DFS
that
solution
V

DFS
solution
still
runs
under
one
second
(in
competitive
programming,
we
assume
that
under
one
second
(in
competitive
programming,
we
assume
that
1
million
operations
ca
we
assume
that
1
million
operations
can
be
done
in
1
second
fprogramming,
connected
components
using
DFS
in
a
general
graph
takes
O(V
+
E),
but
it
only
takes
O(V
)
in
under
one
second
(in
competitive
programming,
we
that
1
operations
can
be
in
Theorem
2.
If
N
is
divisible
by
three,
then
F
(N
)
can
be
partitioned
into
two
multise
(Halim components
& Halim 2013)).
the number of connected
using DFSTherefore,
in a general
graph
takes
O(V +
E),
but it
takes whether
O(V ) inN
a
this
solving
problem
isthat
reduced
toonly
checking
f
(1)

f
(2).
F
(N
)
will
have
N

2
elements.
Since
N

2
(mo
has
O(E)
in
its
running
tim
1million
operations
can
be
done
in
1
second
(Halim
and
Halim
2013)).
under
one
second
(in
competitive
programming,
we
under
assume
one
that
second
1
million
(in
competitive
operations
programming,
can
be
done
in
(Halim
&
Halim
2013)).
Theorem
2. Ifproblem
N&isHalim
divisible
then
F (N
)number
can
be partitioned
into
two
multisets
of
equal sum.in a planarw
Therefore,
if (Halim
the
requires
usthree,
to compute
the
of
connected
components
in
a
planar
planar graph.
Therefore,
if 2013)).
thebyproblem
requires
us
to
compute
the
number
of
connected
components
three, then
We will
more
special
the
sectio
Proof.
N is000,
divisible
Fexamples
(N ) isHalim
a2of
prex
of Fcases
within
length
multiples
of
3,byFprovide
(N
)2can
bestandard
partitioned
into
two
multisets
of following
equal
sum,
wh
Bellman-Ford
algorithm
takes
O(
(Halim
&states
Halim
2013)).
2013)).
hough
the constraint
that
V If100,
E
000
, the
DFS
solution
still
runs
graph,
even
though
the constraint
states
that
V 100,
100,
000,
E(Halim
100,&000
, the
standard
DFS
solution still runs
4.1.2
Maximum
Clique
problem
Proof. If N is4.1.2.
divisible
bycan
three,
thenProblem
F (N ) into
is a two
prex
of F with
lengthsum..
multiples
of
three. ofByconnected
lemma 3,compo
F (N )
be
partitioned
multisets
of
equal
the
number
Maximum
Clique
cond
(in competitive
weprogramming,
assume that
1wemillion
operations
can problem
be
done
1can
second
4.1.2
Maximum
Clique
problem
4.1.2
Maximum
Clique
problem
4.1.2
Maximum
problem
under
one
secondprogramming,
(in competitive
assume
that
1Clique
million
operations
betodone
in 1 second
Therefore,
solving
this
isinreduced
checking
wheth
can be partitioned
into Maximum
two multisets
of equal
sum..
planar
graph.
Therefore,
ifMaxi
the
p
The
problem
requires
us to
the4maximum
set
of
vertices
in4.1.2
a graph,
such
The Maximum
CliqueClique
problem
requires
usMaximum
to find
thend
maximum
set
of
vertices
in
a graph,
4.1.2
Clique
problem
im 2013)).
Some
example
of
spe
(Halim & Halim 2013)). Theorem 3. If N 1We
(mod
3),
F
(N
)
cannot
be
partitioned
into
two
multisets
of
equs
will
provide
more
examples
of
special
cases
in
the
following
The
Maximum
Clique
problem
requires
us
to
nd
the
maximum
set
of
vertices
in
a
graph,
uires us to ndThe
thesuch
maximum
set
of
vertices
in
a
graph,
such
that
every
pair
of
Maximum
Clique
requires
us
maximum
set an
of edge.
vertices
in
a though
graph,
that
ev
that every
of vertices
in the
settois nd
directly
connected
by
By
reduction
graph,
even
the
vertices
in pair
the problem
set
is directly
connected
bythe
an edge.
By reduction
from
vertex
cover,such
theconstrai
maxim
TheoremThe
3. Maximum
If N 1 vertices
(mod
3),
Fthe
(Nset
) cannot
be
partitioned
into
two
multisets
of equal
sum.
Clique
problem
requires
us
to
nd
the
The
maximum
Maximum
set
of
Clique
vertices
problem
in
a
graph,
requires
such
us
to
that
nd
eve
t
in
is
directly
connected
by
an
edge.
By
reduction
from
vertex
cover,
the
m

cted by an edge.
By
reduction
from
vertex
cover,
the
maximum
clique
problem
from
vertex
cover,
the
maximum
clique
problem
on
general
graph
is
NP-hard.
However,
vertices
in
the
set
is
directly
connected
by
an
edge.
By
reduction
from
vertex
cover,
the
maximum
cliqu
under
one
second
(in
competiti
on
general
graph
is
NP-hard.
However,
it
is
easy
to
solve
this
problem
in
planar
graph.
Con
examples
special N
cases
may oc
Suppose
FWe
(Nwill
)problem
= look
F (Nat
) some
f (1).common
Note that
F (N )ofcontains
1that
elements.
4.1.2 Proof.
Maximum
Clique
4.1.2
Maximum
Clique
problem
vertices
set
directly
connected
by
an
By
vertices
reduction
in
the
from
set
is
directly
cover,
the
maximum
by
an
edge.
clique
general
graph
NP-hard.
However,
isvertices
easy
solve
this
problem
in
graph.
the
edge.
N
it solve
isFinof
easy
to
solve
inthat
planar
graph.
Consider
the
colouring
a1planar
wever,
it is Suppose
easy
this
problem
in
planar
graph.
Consider
the
on to
general
graph
NP-hard.
However,
it
is
easy
to
solve
this
problem
inof
planar
graph.
Consider
th
(Halim
& connected
Halim
2013)).
a)this
graph
such
that
two
have
the
same
colour.
Note
that
ifwe
Proof.
(Ncolouring
)on
= haveN
Fisis
(N

f1problem
(1).
Note
F
(N
)adjacent
contains
1to
elements.
Since
N
two
(mod
3),

0is
(mod
3).no
By
lemma
3,it
Fproblem
(N
)
can
be vertex
partitioned
into
multisets
of
4problem
Some
example
of
st
on
general
graph
is
NP-hard.
However,
it
is
easy
to
on
solve
general
this
graph
problem
is
NP-hard.
in
planar
graph.
However,
Consider
it
is
easy
the
of
colouring
a
graph
such
that
no
two
adjacent
vertices
have
the
same
colour.
Note
tha

graph
such
that
no
two
adjacent
vertices
have
the
same
colour.
Note
that
if
there
is
a

adjacent
vertices
have
the
same
colour.
Note
that
if
there
is
a
clique
of
mtwo
Clique
problem
requires
us
to
nd
the
maximum
set
of
vertices
in
a
graph,
such
that
every
pair
of
of
colouring
a
graph
such
that
no
two
adjacent
vertices
have
the
same
colour.
Note
that
if
there
is
size problem
k insum
a graph,
vertices
insideset
the
must
coloured
with
kevery
colours.
Th
The
Maximum
requires
toofnd
ofclique
vertices
in abegraph,
such
thatTherefore,
pair
of
haveN
1 0 Clique
(mod
3).
By
lemma
3, us
Fset(N
)inthe
can
bemaximum
into
two
multisets
equal
sum.
of
all the
elements
Fthe
(N
)partitioned
is even.
However,
the
sum
ofof
all
elements
in
F
(N
) =the
F
4.1
Planar
graph
ofsize
colouring
aby
graph
such
that
no
two
adjacent
vertices
ofodd.
colouring
have
the
aFsame
graph
colour.
such
that
Note
no
that
two
ifadjacent
there
ve
a
clique
of
size
in
in
graph,
ofWe
the
vertices
the
clique
must
be
coloured
size
kthe
aset
graph,
the
set
of
the
inside
the
clique
with
kproblem
colour
be
be
with
clique
coloured
kset
colours.
Therefore,
the
entire
ertices
setvertices
isinside
directly
connected
an
edge.
By
reduction
from
vertex
cover,
the
maximum
clique
problem
ksetinisamust
graph,
of
the
vertices
inside
the
clique
must
coloured
with
kspecial
Therefore,
will
look
at
some
common
ofcoloured
cases
that
ma
inthe
the
directly
by
edge.
By
reduction
from
vertex
cover,
the
maximum
clique
sum
of all
elements
in
F
(N
)connected
is
even.
However,
the
sum
of
all
elements
inbe
(Nexamples
)must
=
Fis
(N
)way
+colours.
fwith
(1),
which
isFis
odd
because
F
(N
)the
isan
even
while
fvertices
(1)
isinside
Therefore,
there
no
to
partition
(N

colours.
Therefore,
the
entire
graph
requires
at
least

colours.
By
the
four
colour
theaeven
graph,
setto
ofodd.
the itvertices
inside
the
clique
sizeproblem
k
must
intoa partition
be
graph,
coloured
set
with
of kthe
colours.
vertices
Therefore,
inside
the
graph
Planar
graph
is planar
graph
that
can
be drawn
aConsider
at
surface
without
aphbecause
is general
NP-hard.
it isthe
easy
solve
this
problem
in
graph.
Consider
the
problem
on
NP-hard.
However,
is
easy
to there
solve
in
planar
graph.
the
problem
Fsize
(NkHowever,
) in
is is
while
f (1)
is
Therefore,
isathis
no
way
F (N
).on
Jonathan
Irvin
GUNAWAN
graph
requires
at
least
kmultisets
colours.
Bysolve
therf
The
Maximum
Clique
problem
orem,
any
planar
graph
can
be
coloured
with
at
most
four
colours.
(Gonthier,
2005).
Since
Theorem
4.
If
N

2
(mod
3).
F
(N
)
can
be
partitioned
into
two
of
equal
et
al.
2001).
There
are
many
graph
problems
which
are
easy
to
a graph
such
that
no
two
adjacent
vertices
have
the
same
colour.
Note
that
if
there
is
a
clique
of
of colouring
a graphIrvin
such
that no
twoGUNAWAN
adjacent vertices have the same colour. Note that4.1
if there
is a cliquegr
of
Jonathan
Irvin
Jonathan
GUNAWAN
colours.
the
four
colour
theorem,
any
can be
coloured
with
at most
four
the four By
colour
theorem,
any
planar
graph
can
begraph
with
at most
four
colours.
2005).
Since
at most
vertices
inentire
setPlanar
is directly
con
most
colours
are
required
to
colour
a planar
there
does
not
exist
athe
clique
4.
If vertices
N

2four
(mod
3).
F
(Nplanar
) can
becoloured
partitioned
into
two
multisets
of (Gonthier
equal
sum.
examples.
aph,Theorem
the kset
of
theat
inside
thevertices
clique
must
be
coloured
with
kgraph,
colours.
Therefore,
the
size
in
a
graph,
the
set
of
the
inside
the
clique
must
be
coloured
with
k
colours.
Therefore,
the
entire
Jonathan
Irvin
GUNAWAN
Jonathan
Irvin
GUNAWAN
Proof.
Assign
fcolour
(1)
toawe
Aplanar
and
fgraph,
(2)
tonot
B.
Since
(1)
=
f (2),
wethan
are
now
trying
to pa
orem,
anyatcolours
planar
graph
can be
coloured
with
at
most
four
. Since
most four
colours
are
required
does
exist
most
four
are required
tofour
colour
a to
planar
graph,
there
does
exist
athat
clique
with
more
vertices.
H
on
graph
is NP-hard.
with
more
than
vertices.
Hence,
can
solve
the
problem
byfnot
checking
whether
there
Planar
graph
is athere
graph
can
begeneral
drawn
on
a four
at
surface
with
Since f (1) = f (2), we are now trying to partition F (N ) = F (N )
Proof.
Assign
f
(1)
to
A
and
f
(2)
to
B.
f
(1)

f
(2).
F
(N
)
will
have
N

2
elements.
Since
N

2
(mod
3),
we
obtain
N
w2
es.
required
to
colour
a
planar
graph,
there
does
not
exist
four
vertices.
Hence,
wethe
can
solve
by
checking
whether
there
is
a
clique
Hence,
we can
problem
by problem
checking
whether
there
is
a
clique
with
four
vertices.
If
there
is
no
clique
of
colouring
a
graph
such
that
is solve
a clique
with
fourthe
vertices.
If there
is
no
clique
with
four
vertices,
we
check
whether
et al. 2001). There are many graph problems which
are easy
to so
Number
oftheore
edg

2 elements. Since N 2 (mod 3), we obtain N 4.1.1


n GUNAWAN
fno
(1)

f (2).
F
(Nchecking
) vertices,
will
have
N

(mod
3). our
By
lemma
Jonathan
Irvin
GUNAWAN
3,whether
Fwith
(Ncheck
) can
beispartitioned
two multisets
of equal
sum,
which
implies
solve
theclique
problem
by
there
a clique
re
iswith
with
four
we
whether
therewith
isinto
a clique
withisthree
vertices.
ue
four
vertices,
we
whether
there
three
vertices.
Finding
whether
there
is
a the
clique
with
k
there
is
acheck
clique
three
vertices.
Finding
whether
there
a clique
with
vertices
can
size
k2in
a0graph,
set
of
the
examples.
k
kthree
4of edgeswhich
F (N
)whether
can
besolved
partitioned
into
multisets
of equal
sum,
which
our
theorem.
s,a we
check
there
is
a clique
with
clique
with
k vertices
can
be
solved
naively
inInvertices.
O(V
).the
Therefore,
theimplies
whole
solution
th
k 3,vertices
can
be
naively
in two
O(V
).. Therefore,
Therefore,
the
whole
solution
simple
general
graph,
the
number
up to a qua
naively
in
whole
solution
takes
is
takes
O(V
) time, can be
is polynomial.
Therefore,2 solving this2 problem is2 reduced to checking whether N 1 (mod 3). W
k
solved
in
O(V
).improved
Therefore,
the
whole
solution
is polynomial.
The
solution
can solution
betoimproved
to
O(V of).
Instead
of
having
four
nested
polynomial.
The
improved
to
having
four
nested
loopsindependently,
ial.
Thenaively
solution
can
be
O(Vcan
).be
Instead
having
nested
vertices
(i.e.
O(Vfour
)).
Thisloops
isof
not
the
case
forvertices
planar
graph. In of
a pl
to
nd
four
. Instead
4.1.1
Number
Jonathan
Irvin
GUNAWAN
Therefore, solving
this
problem
is reduced
checkingofwhether
N
1in(mod
3). We can
solve
this in O(1).
We
will provide
moretoexamples
special
cases
the following
section.
2
an
be
improved
to
O(V
).
Instead
of
having
four
nested
totwo
find
four
independently,
we
can
two
nested
loops
over
the edges
instead
sntly,
independently,
cannested
havevertices
two nested
loops
overinstead
the
edges
and
test
whether
we can havewe
loops
over
the
edges
and
test
whether
holds
for
V have
3instead
by using
the
Eulers
formula.
Therefore,
number
the
four
vertices
(which
are thethe
endpoint
We will provide more examples of special cases in the following
section.
2 the the
2 takes
wo
nested
over
the
edges
instead
testthat
whether
In
simple
general
graph,
of
can
be up
to a
and
the
four
vertices
(which
are
the
endpoint
twoasnumber
edges)
a clique.
re the
of
thetest
twowhether
edges)
form
aand
clique.
This
solution
),same
which
isO(V
the
oint
of endpoint
the loops
two edges)
form
a clique.
This
solution
takes
O(E
),
which
is of
the
has
O(E)
in
itsO(E
running
time
can
be2form
into
O(V
). Comp
)changed
in edges
planar
graph.
2
2
isvertices
the
same
as

in
planar
graph.
s)graph.
form a clique. This solution takes
takes O(E ),, which
the4
(i.e.
O(V
)).
This
is
not
the
case
for
planar
graph.
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
&
Halim
2013),
but
itIno
Some example of special cases
holds
for
V

3
by
using
the
Eulers
formula.
Therefore,
the
num
the number of of
connected
components
using DFS in a general graph
t
4 Some example
special
cases
4.1.3.
Problem
Example
that
has examples
O(E)
in its
time that
can
be
changed
into
O(Vthe
). C
We willexample
look at some
common
of ifrunning
special
cases
may
occur
in
competitive
planar
graph.
Therefore,
the problem
requires
us
to compute
n
4.1.3 example
Problem
4.1.3 Problem
We
use
a that
past
programm
Wesome
will common
use a pastexamples
competitive
programming
problem
illustrate
the
importance
of
the
Bellman-Ford
algorithm
takes
O(V
E)
(Halim
& 100,
Halim
2013),
will look at
of special
cases
that
may
occur
in will
competitive
programming
problems.
lemWe
example
graph,
even though
theto
constraint
states
Vcompetitive

000,
E but
10
etitive programming
illustrate
theThe
importance
of
the
properties
in
a
planar
ramming
problemproperties
to problem
illustrate
the
importance
of Traffic
the
properties
in
a
planar
in ato
planar
graph.
problem
from
Central
European
Olympiad
in
graph.
The
Trac
problem
from
Centra
the
number
of
connected
components
using
DFS
in
a
general
gra
under one second (in competitive
programming,
we assume that 1
4.1 this
Planar
graphs
ontral
illustrate
the importance
of
the properties
in a2011
planar
lem
from
Central
EuropeaninOlympiad
in (CEOI)
Informatics
(CEOI)
2011this
illustrates
concept
European
Olympiad
Informatics
illustrates
concept
Informatics
(CEOI)
2011
illustrates
this
concept
well.
In thiswell.
problem,
there
isrequires
a directed
In problem
this
problem,
there
directed t
planar
graph.
Therefore,
if the
us is
toacompute
(Halim
& Halim
2013)).
4.1
Planar
graphs
mpiad
Informatics
2011
this
concept
ere
isgraph
aindirected
graph
up
to000
Villustrates
=
300,is000
vertices
given
a
2D
plane.
There
are
graph
with
up
to
vertices
in
a
2D
plane.
There
are
two
vertical
lines
cted
with up
to(CEOI)
Vwith
= 300,
vertices
given
ingraph,
athat
2D
plane.
There
are
two
vertical
lines
denoted
as
left
and
rig
Planar
graph
a graph
can
be
drawn
on
a
at
surface
without
having
two
edges
even though the constraint states that V 100, 000,
E
Vleft
= 300,
000
vertices
given
a contained
2D
plane.
There
are
denoted
as that
left
and
right.
All
are
contained
within
the
left
and
right
lines,
as
andgraph
right.
Allgraph
vertices
are
within
the
left
and
right
lines,
with
some
dto
right.
All
vertices
contained
within
theThere
left
and
right
lines,
with
some
vertices
possibly
lying
on
these
two
lines.
Planar
is aare
can
be
drawn
onvertices
a under
at
surface
without
having
two
edges
crossing
each
other
(West
etin
al.
2001).
are
many
graph
problems
which
are
easy
to
solve
if
the
graph
is
plan
one second (in competitive
programming,
we
assume
tha
4.1.2
Clique pr
2 the Maximum
2of visitable
with
some
vertices
possibly
lying
onsome
these
two
lines.
The ifproblem
requires
contestant
are
contained
within
the
left
and
right
lines,
with
these
two2001).
lines.
The
problem
requires
the
contestant
to
print
the
number
ines.
The
problem
requires
the
contestant
to
print
the
number
of solve
visitable
vertices
lying
on the
line from
eve
et
al.
There
are
many
graph
problems
which
are
easy
to
the
graph
is planar.
Weright
will provide
severa
examples.
(Halim
&
Halim
2013)).
2
2 lying on the right line from every vertex lying
to vertex
print
number
of(which
visitable
vertices
the contestant
tothe
print
the
number
htevery
line
from
every
lying
on
the
left of
line
(which
we
shall
call problem
left
vertices
andus for
mrequires
vertex
lying
on the
left
line
wevisitable
shall
call
left
vertices
and
The
Maximum
Clique
requires
to nd
the maximum
set o
right
vertices
simplicity).
An instanc
examples.
on
the
left
(which
we
shall
call
left
and
rightconnected
vertices forbysimplicity).
An reduction from
on the
(which
we
shall
call
left
vertices
and
ity).
An
instance
for
this
problem
can
be
seen
gure
tance
forleft
this line
problem
can
beline
seen
on gure
5. on
vertices
in5.vertices
the set is
directly
an
edge.
By
4.1.1 Number of edges
Maximum Clique
for this problem can beon
seen on Fig.
5. is NP-hard. However, 4.1.2
em can be seen oninstance
gure 5.
graph
it is easy to solve this prob
4.1.1general
Number
of edges
simple
general
graph,
number
of
edges
upadjacent
to
a to
quadratic
withsa
The bruteInforce
solution
for of
this
problem
is
runClique
DFS
from
every
left
vertex
which
Thethe
Maximum
problem
requires
us
nd the order
maximum
colouring
a to
graph
such
thatcan
no be
two
vertices
have
the
2 . Itcan
In simple general
the number
edges
be
up
to
a
quadratic
order
with
respect
to
the
number
of
givesgraph,
us a running
time
ofof
is
very
difficult
to
find
a
solution
(if
any)
faster
than
vertices
(i.e.
O(V
)).
This
is
not
the
case
for
planar
graph.
In
a
planar
graph,
we
vertices
in
the
set
is
directly
connected
by
an
edge.
By
reduction

size k in a graph, the set of the vertices inside the clique must be m
co
forThis
this
However,
there
is
an
important
constraint
on
the
problem.
The
vertices (i.e. O(V 2 )).
isproblem.
not
case
planar
graph.
In
a
planar
graph,
we
may
show
that
E

3V

holds
for the
V
3 byforusing
the
Eulers
formula.
Therefore,
the
number
of
edges
is
O(V
on general graph is NP-hard. However, it is easy to solve this6)
given the
in
this
problem
is
planar
graph.
Wechanged
first
relabel
the
right
vertices
holds for V graph
3 by using
Eulers
formula.
the
of edges
isno
O(V
).).adjacent
Naturally,
any
algorithm
that
has
O(E)
inalways
its Therefore,
running
time
can
be
into
O(V
Computing
shortest
of acolouring
anumber
graph
such
that
two
vertices
havepat
th
Jonathan
Irvin
GUNAWAN
2
in
ascending
order
according
to
the
y-coordinate.
The
planar
properties
ensures
that
for
that has O(E) in its running
time can be
changed
into
O(V
). Computing
pathbut
in
a general
graph
using
Bellman-Ford
algorithm
takes
E)
(Halim
& Halim
it
only
O(V
) in
size
k inO(V
a graph,
the set
ofshortest
the 2013),
vertices
inside
thetakes
clique
must
b
2
Bellman-Ford algorithm takes
E) (Halim
& Halim
2013), butusing
it only
takes
) in graph
a planar
graph.
the O(V
number
of connected
components
DFS
in aO(V
general
takes
O(V Counting
+ E), b
the number of connected
components
DFS in ifa the
general
graph
takes O(V
E), but the
it only
takesofO(V
) in a
planar graph.using
Therefore,
problem
requires
us to+compute
number
connect
2
vertex v is visitable from vertex u if thereJonathan
is a path from
u to vGUNAWAN
Irvin
2 in a planar
planar graph. Therefore, ifgraph,
the problem
requires
us
to
compute
the
number
of
connected
components
even though the constraint states that V 100, 000, E 100, 000 , the stand
graph, even though the constraint
that(inV competitive
100, 000, programming,
E 100, 0002 ,we
theassume
standard
DFS
solutionoperations
still runs
under onestates
second
that
1 million
under one second (in competitive
(Halim &programming,
Halim 2013)).we assume that 1 million operations can be done in 1 second
(Halim & Halim 2013)).

Understanding Unsolvable Problem

95

Fig. 5. An instance of problem Traffic. In this example, the expected output is {4, 4, 0, 2},
since the top left vertex can visit 4 right vertices, the second top left vertex can2 visit 4
of O(V ). It is very dicult to nd a
right vertices, the third top left vertex cannot visit any right vertex, and the bottom left
important constraint on the problem.
vertex can visit 2 right vertices.

the right vertices in ascending order


left
the sequence
left
the
of
visitable
left
is is anof right vis
2
2 vertices from thatvertex,
2right
or
this
It is
problem.
very
However,
to nd
there
a solution
an sequence
(if any)
faster
O(V
) forHowever,
this problem.
there
cult
r).this
problem.
to
nddicult
aevery
solution
However,
(ifvertex,
there
any)
isisfaster
an
than
O(V
) forthan
this
problem.
thereHowever,
is an vertex
we
have
removed
all
right vertices w
agraph.
contiguous
sequence,
assuming
we problem
have
removed
all aright
vertices
arerelabel
ways
constraint
planar graph.
on
the graph
problem.
We rst
rst
relabel
The
given that
inis this
is always
planar
graph.
We rst
ways
nntthe
aaproblem.
planar
The
We
given
relabel
in graph
this
problem
always
a planar
graph.
We
rst
relabelwhich
not visitable from any left vertex. With this property, there is a O(V log V ) solution
solution (CEOI 2011 Solu
ht
anar
vertices
properties
in ascending
ensures that
that
order
foraccording
every
to theThe
y-coordinate.
The planar
properties
anar
scending
properties
order
ensures
according
to for
the
every
y-coordinate.
planar properties
ensures
that forensures
every that for every
(CEOI 2011 Solutions, n.d.).
tex,
contiguous
sequence
sequence,
of right
assuming
visitable
that
vertices
vertex issequence,
a contiguous
sequence,
aace
contiguous
ofthe
right
visitable
sequence,
vertices
assuming
fromthat
that
left from
vertexthat
is aleft
contiguous
assuming
that assuming that
evertex.
removed
With
allthis
this
right
property,
vertices
there
which
a from
not any
visitable
anyWith
leftthis
vertex.
Withthere
this property,
there is a
ight
ertex.
vertices
With
which
property,
are notthere
visitable
isis aare
left from
vertex.
property,
is a
g V ) solution
(CEOI
2011
Solutions
n.d.).
CEOI
2011 Solutions
n.d.).
4.2. Bipartite Graph
Bipartite graph is a graph in which th

edges connect a vertex from U and a


the problem statement does not explic
Bipartite graph is a graph in which the vertices can be partitioned into two disjoint sets
used as an introduction for this pape
and
such
such
that
all edges
from
and Va vertex
from
Somethat all
oaph
edisjoint
disjoint
graph
issets
sets
a graph
and
inVVwhich
such
that
canconnect
be partitioned
into
two
sets U
andallV .such
in which
the
UU and
vertices
canthe
that
bevertices
partitioned
all
into
twoa vertex
disjoint
sets
U disjoint
and
such
that
instatement
subtask 5does
of this
problem implicit
problems
have
a
bipartite
graph
as
an
input
although
the
problem
not
onnect
bipartite
a
vertex
graph
from
as
an
U
input
and
a
although
vertex
from
V
.
Some
problems
have
a
bipartite
graph
as
an
input
although
bipartite
from U and
graph
a vertex
as an input
from Valthough
. Some problems have a bipartite graph as an input although
graph
problems
that
are
NP-hard for g
explicitly
state
that
the
graph
must
be bipartite.
problem
that
we usedthat we
blem
ust
bestatement
bipartite.
does
The
not
problem
explicitly
thatgiven
state
we given
thatinput
the
given
input
graph
must
beThe
bipartite.
The
ust
does
be
not
bipartite.
explicitly
The
state
problem
that
that
the
we
input
graph
must
be bipartite.
The
problem
that
weproblem
bipartite
graph
and bipartite matchin
as an
for
paper,
IOIis
2014
Friend
is aconstruction
very goodThe
example.
The
construcmple.
Thepaper,
construction
for
this
ofpaper,
the graph
graph
IOI
2014
Friend
a very
good
example.
of the graph
mple.
nanforintroduction
this
The
construction
IOIintroduction
2014
of
the
Friend
isthis
a very
good
example.
The
ofconstruction
the graph
that
this
type
of
problem may be con
tionensures
of
the
graph
in
subtask
5 ofthe
this
problem
thatseveral
the There
final graph
ask
ways
5be
be
ofimplicitly
this
bipartite.
problem
There
implicitly
are several
several
ensures
that
nal
graph
will
alwaysensures
be bipartite.
are several
ways
oblem
bipartite.
There
are
that
the
nal graph
will
always
be implicitly
bipartite.
There
are
will
always
be
bipartite.
There
are solvable
several time
graph
that
NP-hard
general Since
al
roblems
time ififthat
the
are
graph
NP-hard
bipartite.
forbut
general
Since
graph
in polynomial
time
ifare
the
graph
isforbipartite.
el time
NP-hard
the
forgraph
general
isis bipartite.
graph
Since
solvable
in but
polynomial
if problems
the graph
is bipartite.
Since
4.2.1
Vertex Cov
graph
but
solvable
in
polynomial
time
if
the
graph
is
bipartite.
Since
bipartite
graph
andexpect
ellabus
graph(Forisek
(Forisek
and bipartite
2015),
matching
we can
can expect
expect
was recently
in IOI(Forisek
2015 syllabus
2015), we can
partite
labus
matching
2015),
was recently
we
included
in IOI included
2015 syllabus
2015),(Forisek
we can expect
bipartite
matching
was
recently
included
in
IOI
2015
syllabus
(Foriek,
2015),
we
can
slll take
type
take
abe
look
problem
at several
several
mayinbe
examples.
conceived
in the
nearWe
future
IOI.a We
take a look
at several
examples.
em
mayaof
look
conceived
at
examples.
the
near future
of IOI.
will of
take
lookwill
at several
examples.
As we
discussed
in an earlier section, b
expect that this type of problem may be conceived in the near future of IOI. We will
are NP-hard. However, both of these
take a look at several examples.
aximum
4.2.1
matching)
Vertex
Cover and Independent
Set (and
maximum matching)
aximum
Vertex
matching)
Cover
and Independent
Set (and maximum
matching)
theorem, the size of the minimum ve
matching (Bondy & Murty 1976), and
Cover
Independent
(and Maximum
Matching)
iscussed
MAX-INDEPENDENT-SET
in an 4.2.1.
earlierofVertex
section,
problems
both and
of the
MIN-VERTEX-COVER
and MAX-INDEPENDENT-SET
problems
MAX-INDEPENDENT-SET
arlier section,
both
the MIN-VERTEX-COVER
problems
andSetMAX-INDEPENDENT-SET
problems
number ofand
the vertices minus the size
Asproblems
we
discussed
in
an earlier
section,
ofon
thebipartite
MIN-VERTEX-COVER
time
on
However,
bipartite
both
graph.
of these
By
Konigs
problems
solvableboth
in polynomial
time
on bipartite
graph.MAXBy Konigs
time
,hard.
both
on
ofbipartite
these
graph.
By
areKonigs
solvable
in are
polynomial
time
graph.
By Konigs
nding
the size of the maximum bip
INDEPENDENTSET
problems
NP-hard.
However,
bothsize
of to
these
m,
to
the size
size of
ofvertex
the
minimum
maximum
cover
in bipartite
graph
equal
to the
of
the problems
maximum are
bipartite
he
o the
minimum
the
maximum
cover in vertex
bipartite
bipartite
graph
is are
equal
to the issize
of the
maximum
bipartite
maximum
matching
in bipartite graph
solvable
in
polynomial
time
on
bipartite
graph.
By
Konigs
theorem,
the
size
of
the
gset
set
(Bondy
in bipartite
bipartite
&and
Murty
graph
1976),
equal
and
to
thethe
the
size of independent
the maximum
in bipartite
graph
urty
in
1976),
graph
the
size
isis of
equal
the to
maximum
setindependent
in bipartite set
graph
is equal to
the is equal to the
tomaximum
solve, as compared
to using Edmon
minimum
vertex
in bipartite
graph
ismatching.
equalboth
to the
size of the
herefore,
of the the
vertices
both
problems
minus
the
are
size
equivalent
ofcover
the maximum
bipartite
Therefore,
both
problemsbipartite
are equivalent
minus
erefore,
both
sizeproblems
of
the maximum
are
equivalent
bipartite
matching.
Therefore,
problems
are
equivalent
5thindependent
subtask of IOI
2014 Friend.
3
3
matching
(Bondy
and
Murty,
1976),
and
the
size
of
the
maximum
set
in
3
3
ng
n O(V
the size
ofbipartite
the
maximum
bipartite
whichincan
be solved
O(V
time.
Finding
the size
size
of
thematching,
O(V )the
time.
he
maximum
matching,
which
can be solved
)) time.
Finding
the
of
the
O(V
) time.inFinding
sizeFinding
of the the size of the
imum-Flow
m
matching
algorithm
in
bipartite
is
much
graph
simpler
using
Hopcroft-Karp
algorithm
or
Maximum-Flow
algorithm
mum-Flow
bipartite graph
algorithm
using is
Hopcroft-Karp
much simpleralgorithm or Maximum-Flow algorithm is much simpleris much simpler
h.
, as
This
compared
actually
to using
the solution
solution
Edmonds
of the
Blossom
the on general
algorithm
on general
graph. This
is actually
h.
to
This
using
isisEdmonds
actually
the
Blossom
algorithm
of
graph.
This is actually
the solution
of the solution of the
4.3
of IOI 2014 Friend.
4ask
Friend.

4.2

4.2 Graph
Bipartite Graph
Bipartite

A directed acyclic graph is a directed g

that
graph
problems
NP-hard
forthe
general
graph
but
inmatching
polynomial
if the included
graph is in
bipartite.
hat are
NP-hard
graph
but time
solvable
in graph
polynomial
timesolvable
if Since
the graph
is bipartite.
Since
polynomial
time
iffor
thegeneral
graph
is are
bipartite.
Since
neral
graph
but solvable
inthat
polynomial
if
is bipartite.
bipartite
graph
and
bipartite
wastime
recently
IOI 20
4.2.1
Vertex
Cover
and
Independent
Set
(and
maximum
matching)
bipartite
graph
and
bipartite
matching
was
recently
included
in IOI
weIOI.
can W
and
bipartite
matching
recently
included
in
IOI
2015
syllabus
(Forisek
2015),
wesyllabus
can expect
I 2015
syllabus
(Forisek
2015),
wesyllabus
can
expect
was
recently
included
inwas
IOI
2015
(Forisek
2015),
we
expect
that
this
type
of can
problem
may
be2015
conceived
in (Forisek
the near 2015),
future of
that
this
typeof
ofIOI.
problem
may
be aconceived
in the
near
future
ofatIOI.
We examples.
will take a look at several examp
problem
may
be
conceived
in
the
near
future
of
IOI.
We
will
take
a
look
several
OI.
We
will
take
a
look
at
several
examples.
ived
in
the
near
future
We
will
take
look
at
several
examples.
e discussed in an earlier section, both of the MIN-VERTEX-COVER and MAX-INDEPENDENT-SET problems
4.2.1 Vertex
Independent
NP-hard. However,
both of these problems are solvableJ.I.inGunawan
polynomial
time onCover
bipartiteand
graph.
By Konigs Set (a
96matching)
4.2.1
Vertex
Cover
and
Independent
Set
(and
maximum
matching)
Vertex
Cover
and
Independent
Set
(and
maximum
matching)
tr.2.1
(and
maximum
and
Independent
Set
(and
maximum
matching)
em, the size of the minimum vertex cover in As
bipartite
graph in
is equal
to the
size of
theofmaximum
bipartite
we discussed
an earlier
section,
both
the MIN-VERTEX-COVER
hing
(Bondy
&
Murty
1976),
and
the
size
of
the
maximum
independent
set
in
bipartite
graph
is
equal
to thein polyno
bipartite
graph
is equal
to theare
number
of MIN-VERTEX-COVER
the
vertices
minusofthe
size
of
the maximum
in
Assection,
we discussed
in
an earlier
section,
both
of the
andproblems
MAX-INDEPENDENT-SET
pro
nh an
earlier
both of
the
MIN-VERTEX-COVER
and
MAX-INDEPENDENT-SET
problems
VER
and
MAX-INDEPENDENT-SET
problems
of the
MIN-VERTEX-COVER
and
MAX-INDEPENDENT-SET
problems
NP-hard.
However,
both
these
are solvable
ber
of theboth
vertices
minus
the
size are
ofboth
the
maximum
bipartite
Therefore,
problems
are
equivalent
bipartite
matching.
Therefore,
both
problems
are
equivalent
toboth
finding
the
size
of
the graph.
are solvable
NP-hard.
However,
ofon
these
problems
are
solvable
in polynomial
time
on
bipartite
owever,
of
problems
solvable
in
polynomial
time
bipartite
graph.
By
Konigs
lynomial
time
onthese
bipartite
graph.
By
Konigs
problems
are
in
polynomial
time
bipartite
graph.
By
Konigs
theorem,
thematching.
size
ofon
the
minimum
vertex
cover
in
bipartite
graphBy
is eK
3 time. Finding the size
maximum
bipartite
which
can
bebe
solved
in
nding
the minimum
size
of size
the
maximum
bipartite
matching,
which
caninto
solved
in
)equal
time.
Finding
ofmaximum
the indepe
eisofequal
the
vertex
cover
in bipartite
graph
is cover
equal
the
size
of O(V
the ismaximum
bipartite
theorem,
the
size
the
minimum
vertex
bipartite
graph
to
the
ofsize
the
bi
to
the
of
the
maximum
bipartite
ex
cover
in
bipartite
graph
isof
equal
tomatching,
the
size
of
the
maximum
matching
(Bondy
&bipartite
Murty
1976),
and the
size size
ofthe
the
maximum
of
the
maximum
matching
in
bipartite
graph
using
Hopcroft-Karp
algorithm
or
Maximum
matching
in
bipartite
graph
using
Hopcroft-Karp
algorithm
or
Maximum-Flow
algorithm
is
much
simpler
(Bondy
& Murty
1976),
and
the graph
size
of isthe
maximum
setmaximum
in bipartite
graph ismatchin
equal
yhe&size
Murty
1976),
and
theindependent
size
ofisthe
maximum
independent
set
in bipartite
graph
to
the bipartite
dependent
set
in
bipartite
graph
equal
of matching
the
maximum
setto
in the
bipartite
equal
tominus
the independent
number
of the
vertices
the
sizeisofequal
the
mum-Flow
algorithm
is much
simpler
toTherefore,
solve,
asgraph.
compared
using
Edmonds
Bloslve,
asminus
compared
to
Edmonds
Blossom
algorithm
on
general
This to
is bipartite
actually
the
solution
of the
ertices
number
of using
the
vertices
minus
the
size
of
the
maximum
bipartite
matching.
Therefore,
both
problems
rtices
the
size
of problems
the
maximum
bipartite
both
problems
are
equivalent
ching.
Therefore,
both
are
equivalent
the maximum
bipartite
matching.
Therefore,
both
problems
are
tomatching.
nding
the
sizeequivalent
of
the
maximum
matching,
which
canare
beequ
sol
so
algorithm
on
general
graph.
This
is
actually
of
IOI
3the solution of the 5th subtask
3
3 som
3the
ubtask
IOI
2014
Friend.
toO(V
nding
the
size
of
the
maximum
bipartite
matching,
which
can
be
solved
in
O(V
)
time.
Finding
the
size
e solved
of matching,
theofin
maximum
bipartite
matching,
which
can
be
solved
in
O(V
)
time.
Finding
the
size
of
the
ertite
)
time.
Finding
the
size
of
which can be solved in O(V ) time.
Finding
the sizeinofbipartite
the
maximum
matching
graph using Hopcroft-Karp algorithm or
2014
Friend.
ingorin
bipartite
graph
using
Hopcroft-Karp
algorithm
orHopcroft-Karp
Maximum-Flow
algorithm
much
simpleralgorithm
maximum
matching
bipartite
graph
algorithm
or isMaximum-Flow
algorithmonis general
much s
m
Maximum-Flow
algorithm
much simpler
sing
Hopcroft-Karp
algorithm
orinisMaximum-Flow
algorithm
is much simpler
to using
solve,
as
compared
to
using
Edmonds
Blossom
th
th
to
solve,
toalgorithm
usingThis
Edmonds
Blossom
algorithm
on general
is actually the solution
pared
to using
Edmonds
Blossom
on
general
graph.
This
is
thegraph.
solutionThis
of the
graph.
This
is as
actually
the graph.
solution
of
the
seral
Blossom
algorithm
oncompared
general
is 5actually
theofsolution
of actually
the
subtask
IOI
2014
Friend.
5th subtask
IOI 2014
Friend.
OI 2014 Friend.
4.3
Directed
Acyclic Graph
4.3. of
Directed
Acyclic
Graph

ected acyclic graph is a directed graph that does not contain any cycle. Similar to planar and bipartite graphs,
4.3acyclic
Directed Acyclic
are several graphAproblems
that aregraph
muchiseasier
to solve
if the
is a contain
directed
directed acyclic
a directed
graph
thatgraph
does not
any cycle.graph.
Similar to

4.3 Directed
Acyclic Graph
4.3 Directed
Graph
c Graph
Directed Acyclic
Graph Acyclic

planar and bipartite graphs, A


there
are several
thatgraph
are much
easiernot
to contain any c
directed
acyclicgraph
graph problems
is a directed
that does
Minimum
Path
Cover
A
acyclic
graph
is4.3.1
anot
graph
that
does
not graphs,
contain
cycle.
to
planar
solve
if the
graph
isSimilar
a directed
directed
acyclic
graph.
cnygraph
a directed
graph
that
does
contain
anyare
cycle.
Similar
to
planarany
andthat
bipartite
graphs,
cycle.
Similar
planar
and
bipartite
graphs,
aph
that isdoes
notto
contain
any
cycle.
tothere
planar
and
bipartite
several
graph
problems
areSimilar
much
easier
to and
solvebipartite
if the gr
g
there
are
several
graph
problems
thatif are
much
easier
to solveacyclic
if the graph
is a directed acyclic graph.
graph
problems
that
are
much
easier
to
solve
the
graph
is
a
directed
graph.
he
graph
is
a
directed
acyclic
graph.
re
much
easier
to
solve
if
the
graph
is
a
directed
acyclic
graph.
-PATH-COVER is a problem that requries us to nd the minimum number of vertex-disjoint paths needed
4.3.1. Minimum Path Cover
4.3.1
Minimum
Path Cov
over all of the vertices in a graph. By a simple reduction from Hamiltonian Path, this
problem
is NP-hard.
MIN-PATH-COVER
is a Path
problem
that requires
us Path
to findCover
the minimum number of
4.3.1
Minimum
Cover
4.3.1
Minimum
Cover
4.3.1
Minimum
Path
Cover
aph has a Hamiltonian Path if and only if we MIN-PATH-COVER
only need one path to
all ofthat
the vertices.
However,
is cover
a problem
requries
us
to rend this
the minimu
vertex-disjoint paths needed to cover all of the vertices
in a graph.
By a simple
em
can
be
solved
in
polynomial
time
for
a
directed
acyclic
graph.
For
a
graph
G
=
(V,
E),
we
create
a new from
VER
is
a
problem
that
requries
us
to
nd
the
minimum
number
of
vertex-disjoint
paths
needed
is
anumber
problem
that
requries
to isnd
the minimum
number
of vertex-disjoint
pathsHn
imum number
of duction
vertex-disjoint
paths
needed
requries
usMIN-PATH-COVER
to nd
the minimum
of Path,
vertex-disjoint
needed
to cover
all us
ofpaths
the
vertices
in Aa graph
graph.
ByaaHamiltonian
simple
reduction
from
Hamiltonian
this
problem
NP-hard.
has

hhe
G
(Vout

,all
E this
),
where
Voutifis=
= VA
and
E
=
{(u,
v)

Vout

Vthe
:ifvertices.
(u,
v)isonly
NP-hard.
E}.
Then
it can
beone path
in
in
toincover
of
the
inVin
aonly
graph.
By
ahas
simple
reduction
from
Hamiltonian
this
problem
is NP
vertices
a VPath,
graph.
a vertices
simple
reduction
from
Hamiltonian
Path,
problem
m
Hamiltonian
problem
NP-hard.
By
a=simple
reduction
from
Hamiltonian
Path,
this
problem
is
NP-hard.
graph
a to
Hamiltonian
Path
and
ifPath,
we
only
need
Path
ifBy
and
only
we
need
one
path
cover
allthis
of
However,
this

n
bytoKonigs
Theorem
that
G
has
a
matching
of
size
m
if
and
only
if
there
exist
|V
|

m
vertex-disjoint
graph
has
avertices.
Hamiltonian
Path
if
and
only
if
we
only
need
one
path
to
cover
all
of
the
vertices.
Howeve
amiltonian
Path
ifproblem
and
only
if
we
only
need
one
path
to
cover
all
of
the
vertices.
However,
this
ath
all
of
the
However,
this
only
if cover
weAonly
need
one
path
to
cover
all
of
the
vertices.
However,
this
problem
can
be
solved
in
polynomial
time
for
a
directed
acyclic
graph.
can be solved in polynomial time for a directed acyclic graph. For a graph
For
ssolved
that
cover
all ofacyclic
vertices
indirected
G.
for, awe
graph.
aout
graph
=
E), we
create
ainnew
problem
can
begraph.
solved
in
polynomial
time
for
a we
directed
For
a=graph
(V,
create
aph.
apolynomial
graph
Gthe
=time
(V,
E),
we
create
anew
new
me
forFor
aindirected
For
a graph
Ggraph
=
(V,G
E),
create
aG,new
graph
=
(V
Vacyclic
E (V,
),,graph.
where
Vout
Vin
=GV=and
E =we{(u,
v)
create
aacyclic
where
andE),
in
out
in
out

graph G = (V

inV=
E and
),it
V{(u,
V
=Then
Vand
E
=be
{(u,
v)by
Konigs
Vhas

V
(u, v)
E}.mThen
it
V
EV
),
V=
=
Vv)
v)
VitTheorem
: (u,
v)
E}.
Then
itmatching
can

V,out
where
V
v){(u,
E}.
Then
can
be
.out
can
be
shown
Theorem
that
=
Vin
=
and
V,Vout
where
VEin =
: (u,
v)=
by
E}.
Then
it
can
shown
Konigs
that
G
ofsize
if and
out
in
out
inV
out a
in :be
out
in
in :E(u,
ttv)
in

Konigs
by
Theorem
that
athat
of of
size
|V | m vertex-d
has
matching
size
has
and
only
there
exist
vertex-disjoint
vertex-disjoint
s
that
G
has
matching
of
sizeGexist
m
ifif and
only
ifif there
exist
|Vif |and
monly
and
only ifshown
there
exist

monly
vertex-disjoint
4.4
Miscellaneous
s aTheorem
matching
of size
m|Vifa| and
ifof
there
|V
| matching

m
vertex-disjoint
paths
cover
all
themvertices
in
G.if there existpaths
that
cover all
all of
of the
the vertices in
that
in G..
vertices
in cover
G.
.all of the paths
4.4.1 Special case of CNF-SAT problem

4.4

Miscellaneous

will
use Google
Code Jam 4.4
2008 Round
1A Milkshake
for this example. This problem requires the
Miscellaneous
4.4problem
Miscellaneous
ous
4.4
Miscellaneous
4.4. Miscellaneous
4.4.1
Special
case with
of CNF-SAT
estant to nd a solution with the minimum number of true variables that satisfy
a CNF-SAT
problem
up
4.4.1
Special
case
of
CNF-SAT
problem
4.4.1
Special
case
of
CNF-SAT
problem
SAT
problem
Special
case of CNF-SAT problem
We will
use Google Code Jam 2008 Round 1A Milkshake problem fo
4.4.1. Special Case of CNF-SAT
Problem
gle
Code
Jam
2008
Round
1A
Milkshake
problem
for
example.
Thiswith
problem
requires
We
will
use
Google
Code
Jam
2008
Round
1Athis
problem
for
example.
This of
problem
requir
m
for1A
this
example.
requires
und
Milkshake
problem
this
example.
This
requires
the
contestant
toMilkshake
nd
aMilkshake
solution
thethis
minimum
number
true variable
than
Irvin
GUNAWAN
WeThis
will problem
use for
Google
Code the
Jam
2008problem
Round
1A
problem
for
this the
example.
contestant
to
nd
a problem
solution
with
the
minimum
number
of atrue
variables
that satisfy
a CNF-SAT
problem w
dinimum
a solution
withofThis
the
minimum
number
ofthetrue
variables
satisfy
CNF-SAT
withnumber
up
ables
that
satisfy
a true
CNF-SAT
up
number
variables
that satisfy
a CNF-SAT
problem
with
upwith
problem
requires
contestant
tothat
find
a solution
theproblem
minimum
of

true variables that satisfy a Jonathan


CNF-SATIrvin
problem
with up to 2,000 variables (Google
GUNAWAN
Code
2008 Round 1A, Milkshake problem, n.d.). The CNF-SAT is a satisfiability
IrvinJam
GUNAWAN
UNAWANJonathan
problem given in a conjunctive normal form (i.e. conjunction of disjunction of literals)
which was proven to be NP-hard (Cook, 1971). Therefore, it is unlikely that there is an
algorithm to solve a CNF-SAT problem with 2,000 variables in less than 8 minutes3.
However, there is a special property in this problem, in which at most one unnegated
literal exists in each clause. Therefore, all clauses can be converted into Horn clauses.
With this property, a linear time algorithm exists. (Google Code Jam 2008 Round 1A,
Milkshake solution, n.d.).

In Google Code Jam, contestants are given 8 minutes to produce the output upon downloading the input.

Understanding Unsolvable Problem

97

5. Conclusion
In conclusion, we can use a well-known reduction technique to prove that a problem that
we are currently attempting to solve is impossible (or at least it is very hard such that no
people has been able to solve it for more than 40 years). In competitive programming
(including IOI), understanding this technique is essential so that we will not be stuck at
trying to solve an impossible problem, thus prompting us to find another way to solve
the problem. To prove that a problem is NP-hard, it is good to know as many NP-hard
problems as possible, so that we can reduce from any one of the problems that we know
to the new problem. Some of the classic NP-hard problems include 3-SAT, Vertex Cover,
Independent Set, and Subset Sum. After realizing that the problem is NP-hard, we must
be able to find the special case that makes the problem solvable. We must be able to find
a special property that breaks the reduction proof. Having a lot of practice on these kind
of problems will help us to familiarize with the possibilities of a special case. Some of
the common special cases include planar, bipartite, and directed acyclic graph.

References
ACM ICPC World Finals 2010 Problem Statement (n.d.). Available via internet:
http://icpc.baylor.edu/download/worldfinals/problems/2010WorldFinalProblemSet.pdf
ACM ICPC World Finals 2010 Solutions (n.d.). Available via internet:
http://www.csc.kth.se/~austrin/icpc/finals2010solutions.pdf
Bondy, J.A., Murty, U. S. R. (1976). Graph Theory with Applications, Vol. 290, London: Macmillan.
CEOI 2011 Solutions (n.d.). Available via internet:
http://ceoi.inf.elte.hu/probarch/11/ceoi2011booklet.pdf
CEOI 2011. Traffic Problem (n.d.), available via internet:
http://ceoi.inf.elte.hu/probarch/11/trazad.pdf
Cook, S.A. (1971). The complexity of theorem-proving procedures. In: Proceedings of the Third Annual ACM
Symposium on Theory of Computing. ACM, 151158.
Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C. (2009). Introduction to Algorithms (3rd ed.). MIT Press.
Foriek, M. (2015). International olympiad in informatics 2015 syllabus. Available via internet:
https://people.ksp.sk/~misof/ioi-syllabus/ioi-syllabus.pdf
Gonthier, G. (2005). A computer-checked proof of the four colour theorem. Available via internet:
http://research.microsoft.com/en-us/people/gonthier/4colproof.pdf
Google Code Jam 2008 Round 1A, Milkshake Problem (n.d.). Available via internet:
https://code.google.com/codejam/contest/32016/dashboard#s=p1
Google Code Jam 2008 Round 1A, Milkshake solution (n.d.). Available via internet:
https://code.google.com/codejam/contest/32016/dashboard#s=a&a=1
Halim, S., Halim, F. (2013). Competitve Programming 3. lulu.com
IOI 2008, Island Problem (n.d.). Available via internet:
http://www.ioinformatics.org/locations/ioi08/contest/day1/islands.pdf
IOI 2014, Friend Problem (n.d.). Available via internet:
http://www.ioinformatics.org/locations/ioi14/contest/day2/friend/friend.pdf
West, D. B. etal. (2001). Introduction to Graph Theory, Vol. 2. Prentice hall Upper Saddle River.

98

J.I. Gunawan

J.I. Gunawan is an undergraduate student studying Computer Science


in National University of Singapore. He participated a lot of programming contests, including IOI 2012 and 2013 and ACM ICPC World
Finals 2014 and 2015. He is also the lead of the Scientific Committee
of Indonesian Computing Olympiad team (TOKI) training Indonesian
teams for IOI in 20152016.

Olympiads in Informatics, 2016, Vol. 10, 99109


2016 IOI, Vilnius University
DOI: 10.15388/ioi.2016.07

99

Homo Informaticus
Why Computer Science Fundamentals are
an Unavoidable Part of Human Culture
and How to Teach Them
Juraj HROMKOVI
Department of Computer Science, ETH Zrich
e-mail: juraj.hromkovic@inf.ethz.ch

Abstract. The goal of this article is on one hand to introduce informatics as a scientific discipline
in the general context of science and to outline its relationships especially to mathematics and engineering, and on the other hand to propose a way how to integrate computer science into school
education.
Keywords: teaching, computer science, mathematics.

1. Introduction
The development of human society is mainly determined by the ability to derive knowledge and to find efficient ways of applying it. Let us explain this claim more carefully.
Human beings sample experiences by observations and experiments and use them to
generate knowledge by combining their experience with logical thinking. The derived
knowledge is used to develop procedures in order to reach concrete goals. A crucial point
in our considerations is that to use such procedures one usually does not need to fully
understand the knowledge used to obtain such procedures. To an even higher extent, one
does not need to understand the way in which this knowledge was derived and verified.
Let us illustrate this on a simple example.
The famous theorem of Pythagoras claims c2 = a2 + b2 in any right triangle, where
c is the length of the longest side (hypotenuse). This theorem was used to fix the right
angles when building houses and temples in the classical antiquity. The workers only
needed to build a triangle of sizes 5 units, 4 units, and 3 units in order to get a right
angle, and for sure they did not need to understand how the theorem of Pythago-

100

J. Hromkovi

ras was discovered and how it was proven. Hence, to successfully apply the derived
knowledge, one did not need to master the high qualification of an investigator. In this
way, scientists changed and still change society and became a crucial factor in human
development.
Computer science was created as a natural step forward in the above described development, when the following two conditions were satisfied:
1. Using the exact language of mathematics, one was able to discover and describe
procedures in such a way that no intellect was needed to apply them. Executing
them step by step, everything was unambiguous, and no educated or trained person was needed to find the right interpretation of the particular instructions of the
procedure executed.
2. The technology enabling to execute the discovered procedures by machines was
developed, and languages providing the opportunity to explain universal machines what they have to do were designed.
In this context, we speak about automation. We let the machine execute not only
physical work, but also such human work considered as intellectual work in the past.
This is the reason why computer science is a mixture of mathematics and engineering.
On the one hand, one uses the concepts, methods, and the language of mathematics in order to understand the considered entities and their relations so exactly that
algorithms as unambiguously interpretable procedures can be developed in order to
solve a variety of problems everywhere in science, technology, and everyday life. Here,
mathematics is the instrument that has to be mastered together with the specific area in
which one tries to solve problems.
On the other hand, developing and improving the enabling technology is mostly
engineering. This is not only about hardware, but especially about software enabling
us to conveniently communicate with computers in high-level programming languages.
We see that computer science is a part of the natural development of science, and
it became a discipline that is crucial for the performance of the human society. This
contextual view is important when thinking about what computer science actual is, and
how to teach computer science in schools. We are asked not to teach specific isolated
facts, methods, and other final products of scientific work, but the way how they were
discovered, i. e., the paths from the motivation coming from the general context of science to the final products of the research work and engineering. As in its fundamentals
computer science is very strongly related to mathematics as its basic research instrument, we start with the question What is mathematics and how to teach it? in the
next section, and use the derived point of view in the final section to propose the way
of teaching computer science in schools. Before the final section, however, we discuss
engineering as a missing subject in schools in Section 3. Again, we use this discussion
in order to show in the final section how teaching computer science can contribute to
understanding some basic concepts of engineering and how it integrates them in the
school curriculum.

Homo Informaticus. Why Computer Science Fundamentals are an ...

101

2. Mathematics as the Language of Science and Consequences


of this View for Teaching It
What is mathematics? If you pose this question, you can get a lot of different answers;
frequently, even the response that this question is too hard to be answered satisfactorily.
A mathematician or a university student can tell you with high probability that she or
he proves theorems and thus investigates the structure and the properties of artificial
mathematical objects, which can be useful to model reality, or the relationships between
different such objects. A high-school student can tell you that mathematics consists of
calculations that can be used to solve some classes of mathematical tasks (also called
problems) such as solving quadratic equations or systems of linear equations or analyzing the properties of a curve. Obviously, you can also get a response that mathematics
is something that is hard to understand, and that every normal human being can exist
and be successful without it. This is a frequent answer, and unfortunately it is more of a
rule than an exception.
Mathematics is the most powerful instrument humans ever have developed in order
to investigate the world around us. But it is taught in such a way that the students do
not realize this fact. Especially in high schools, they learn methods (algorithms) to solve
some given problems (for instance, to find a maximum of a function). This may be also
viewed positively as an intellectual challenge, because several methods are not easy to
manage. But the bad news is that they can learn to successfully apply methods for solving different problems without really understanding why these methods work properly.
High-school students often do not have a good intuition of what infinity or limits are
about, but they use these concepts in a fuzzy way in order to analyze artificial functions
without seeing any relation to reality. What are we doing wrong? A lot. We have to start
to think first about what mathematics is, and then to try to find a way how to teach mathematics in a proper way.
From my point of view, the best way to view mathematics is as a special language
developed for science, i. e., for knowledge generation. Going a few thousand years
back, people wanted to discover objective knowledge. The important word here is
the word objective. If you want to reach that, first of all you need a language in which
each statement has an unambiguous interpretation for everybody who mastered this
language. How to reach this? First of all, you need to give an absolutely exact meaning
to the words (notions) you use, because the words are semantically the corner stones of
each language. In this context, mathematicians speak about axioms. Many people have
the wrong impression that axioms are claims in whose truthfulness we believe, but of
which one is not able to prove that they are true. This is mostly not the case. Axioms
are the precise definitions of basic notions that describe our intuition about the meaning of these notions. Probably the first concepts people tried to fix were notions such as
number, equality, infinity, point, line, distance, etc. What is very important to observe is
that people needed hundreds and in some cases thousands of years to come up with such
definitions that the community of philosophers and later mathematicians has accepted.
Why was all of this done? First of all, the language of mathematics is able to describe

102

J. Hromkovi

objects, structures, properties, and relationships in an unambiguous way. In this context


we speak about the descriptional power of mathematics. Thus, people were able to
formulate exact claims this way, and so to express our knowledge unambiguously. But
this was only one side of the language of mathematics. The language of mathematics
was also used to derive new knowledge from the given knowledge, i. e., as a knowledge
generator. Leibniz formulated this role of mathematics in a very nice way. He wanted to
omit all political discussions and fighting in different committees by simply expressing
the real problems in the language of mathematics, and then using calculations and logical derivations to obtain the right solution. Interestingly, he called this automation
of the human work. By now we know that this dream of Leibniz cannot be achieved.
There are two reasons for that. First of all, because of its exactness, the language of
mathematics is restricted in its descriptional power, and so we cannot translate all realworld problems into this language. Secondly, one of the most important discoveries of
the last century made by Gdel tells us that the argumentational power of the language
of mathematics is smaller than its descriptional power. This means that one can formulate claims in current mathematics for which there do not exist proofs of whether they
are true or not.
What do scientists learn from that? The development of the language of mathematics is similar to the development of natural languages. You need to create new words
and describe their meaning in order to increase its descriptional power, and to be able
to speak about things you were not able to speak about before. Moreover, you need new
concepts and words to be able to argue about matters you were not able to argue before,
i. e., in order to strengthen your capability of deriving new knowledge by thinking. A
very important point is that the process of developing the language of mathematics is
infinite. As long the number of basic, axiomatic words of the language of mathematics
is finite, one can always formulate claims that are not provable within this mathematical
language, and one has to introduce new words in order to be able to prove them and so
to make new discoveries.
A very nice example is the notion of infinity. Nobody saw anything infinite in the
real world, and even most physicists believe that the universe is finite. This means that
infinity is something artificial, simply an artificial product of mathematics. But without
this concept, most of the current science would not exist. Without the notion of infinity,
there would be no concept of limits and so we would not be able to exactly express notions like actual speed or actual acceleration. Our science simply would be somewhere
before the discoveries of Newton. Hence, without the artificial concept of infinity,
one is strongly restricted in the ability to discover our finite, real world.
Another example of a crucial notion is the concept of probability. Most of the sciences, even the non-exact ones such as didactics, psychology, medicine, and economy,
heavily use this concept to model and investigate reality, and if they would make predictions without this concept, they would have serious trouble to convince society that their
results are trustable to some extent and not only expert opinions.
Why did we focus on the view of mathematics presented above? Because it is the
nature of mathematics that shows us which changes are necessary in order to improve

Homo Informaticus. Why Computer Science Fundamentals are an ...

103

the education in mathematics for everybody. Based on this, we recommend to adopt the
following concepts:
1. Focus more on the genesis of the fundamental notions (concepts) of mathematics.
To define them took centuries, to prove most of the theorems took a few years.
Each new concept enabled to investigate so many things that no single discovery
can compete with introducing a fundamental concept. The strengthening of mathematics as a research instrument is the main job of mathematics, and deriving
new concepts (not necessarily on the axiomatic level) in mathematics provides
the best, true picture of its nature. Without this, nobody can really understand its
role and usefulness. And only if one understands the genesis of mathematics as
the development of a language of science and as a research instrument, one can be
able to apply it regularly to all areas of our life. Teaching mathematics this way
can completely change the behaviour of the members of our society. Instead of
memorizing and sampling facts provided, one would start to verify the degree of
trustability of claims sold as knowledge and to understand to which extent and
under which conditions one is allowed to take them seriously.
2. Concrete examples first, abstraction as a final discovery. One first has to touch
concrete problem instances and objects in order to get some intuition about their
properties. Then, one can formalize her or his intuition into a formal concept.
One has to follow the natural way of discovering that usually goes from concrete
to abstract. To sell methods and theorems as final products is as poor as teaching
manuals for washing machines or Microsoft office instead of teaching discoveries of physics, mechanics, and computer science that enabled to develop these
products.
3. Teach algorithmics instead of training calculation methods. Pupils learn in schools
to multiply arbitrarily large integers in decimal representations, to solve quadratic
equations and systems of linear equations, or to analyze functions, etc. In all cases, most pupils learn to apply given methods, but most of them do not understand
why they work. It is more of a challenging memorizing than a deep understanding
of the nature of the algorithms used. One has to start to introduce problems instead
of presenting methods solving them, and ask the pupils and students to solve concrete problem instances first and finally to discover an algorithm as a robust procedure that is able to solve any of the infinitely many concrete problem instances
of the given problem. Discovering algorithms as well-functioning calculation procedures offers another quality of education in mathematics than executing a given
calculation method, which any pocket calculator can do faster and more reliable.
Teach programming as the art of exactly describing the methods discovered in an
unambiguously interpretable way in the language of the machines, and strengthen
the ability of exact communication this way.
4. Teach the principles of correct argumentation. Teach the notions of implication
and quantifiers, and train direct and indirect proofs. Do not believe that the pupils
in high schools cannot learn to verify and to derive simple proofs. They did not
manage this in the past, because there was no effort made to teach proving claims,
or most effort in this direction was done in a wrong way.

104

J. Hromkovi

5. Guarantee the opportunity to the pupils to deal with the subjects as many time as
needed at an individual speed. Mathematics is one of the sciences that needs a
large number of iterative touchings of particular topics until one is allowed to say
Eureka, and gets a reasonable understanding of what it is about. The trouble is
that no teacher can assure this by herself or himself for everybody in the class.
Another problem is that most textbooks of mathematics are good collections of
exercises, but explanations are written more for teachers than for pupils. One way
out is to change the style of the textbooks. The textbooks should be written in
such a way that pupils and students would be able to learn from them by their own
with a minimal support from outside. Partitioning the discoveries into a number
of small, natural steps written in the language mastered by the pupils at the corresponding age, and regularly giving the opportunity to verify whether one understands the topic up to now properly are some of the basic principles used to create
good textbooks for mathematics.
Finally, one can ask how to reach the new teaching style for mathematics described
above. For sure, one cannot ask the high-school teachers to make this change without
showing them how to do this in detail. One also cannot ask educationalists, who do not
have a sufficiently deep contextual knowledge of mathematics to master these changes.
The movement has to start at the universities, where the teaching style has to change
first. In order to speed up this process in Switzerland, in our department at ETH Zrich
we develop new textbooks for teaching different topics of mathematics and computer
science for all school levels. Our experiments prove that mathematics can become one
of the most favorite subjects of pupils and students if taught in the way described
above. Students can successfully master topics that were considered to be too hard for
them before, and the marks in mathematics can be significantly higher than the average
marks over all topics.
For me, it is not a question of whether the proposed evolution of the education in
mathematics will come. It is only the question of the time at which particular countries
will need to adopt it. Since this is a service for the future generation, the earlier the
better.

3. Why Engineering is Not Allowed Not to Be a Part of Basic Education


As mentioned in the introduction, human society uses the knowledge discovered in order
to reach different goals more efficiently by developing various procedures or different
products. This is highly creative work that is beyond the pure learning of facts and making calculations that can be completely automatized. The whole process of engineering
work starts with a description of the goals to be achieved. After that, one starts to combine experience and fundamental knowledge of science in order to design a solution that
has to be implemented as a prototype. Next, one has to test this prototype, modify, and
improve it until an acceptable product is produced.

Homo Informaticus. Why Computer Science Fundamentals are an ...

105

In todays schools, we find almost nothing about the concept of iterative specifying,
testing, modifying, and improving the product of our work, let alone about fundamental
constructive ways of creating original products. But this is fundamental to human activities since the beginning of time. The current school systems ignore this fact to a high
extent and are more about teaching to memorize than teaching to work in a creative
way. One can explain this educational misconception by the fact that, in contrast to
basic scientific models of reality, the engineering work is heavily dependent on experience that is often hard to formalize and thus to teach. The creative work of engineers
as human experts cannot be described by an algorithm (a method). However, this must
not be a reason to remove engineering from education, because students also have to
learn to build their own experience over a longer period of time in order to become an
expert for a special area.
The crucial fact we want to point out is that computer science mastered to formalize
several basic concepts of engineering and made them available to our schools as a result.
Teaching computer science is a chance to introduce engineering as a highly creative,
constructive activity to our educational system.
Let us consider some concrete illustrations. Probably the most fundamental concept of technical sciences is modularity. One builds some simple units with clear and
well verifiable functionalities and calls them modules. Then one uses these modules
as fundamental building blocks to construct more complex systems that are again
considered basic modules for constructing even more complex systems. There is no
upper bound on the growth of the complexity of systems built in such a way. Unbelievably many human activities can be described by this modular concept. This
includes learning. Ones learns some simple facts and methods and their applications
in a restricted framework. After that, one masters them perfectly in such a way that
one can use them as elementary operations in attacking more complex tasks. All spiral
curricula run in a well-designed modular way. Thinking in a modular way when trying to reach given goals is the most fundamental instrument of creative human work.
And it does not matter whether you apply it top-down or bottom-up. If one applies a
top-down approach, then everything is clear and one designs only a transparent and
well-verifiable plan for constructive work. More typical is the bottom-up approach
where one builds more and more complex modules without knowing what the final
product will be about.
Programming is an excellent instrument to teach modularity. Writing programs to
automate solving different tasks provides modules for attacking much more complex
tasks. Children of age between 10 and 12 are able to put five loops into each other without being disturbed by or even observing the complexity of their final product due to
modularity. One simple program containing a loop gets a name and so becomes a new
instruction. This instruction is used in the body of another loop that also becomes a new
instruction used in another loop, etc. Here, one can train both, the top-down approach as
well as bottom-up approaches devoted to open-end tasks. To practice the ability to bring
a clear structure into complex processes is at least as important as any of the fundamental concepts of sciences or humanities contained in the school curricula.

106

J. Hromkovi

Another important concept is teaching to test or verify products of our work. Typically, children verify their own products by asking teachers or adults to tell them whether
their work resulted in what they were asked to reach. But this way, they cannot sufficiently build their self-confidence because they need a strong dependency on their supervisor. They have to learn to trust their solutions by being taught to verify the products of
their work by themselves. Programming is again a wonderful instrument for this purpose
using the platform or editor that fits the educational requirements. One can learn to test
the functionality of programs by running them on several data sets as well as by the verification approach based on a transparent structuring of the program into small modules
whose correct behavior can by easily verified.
In general, constructive engineering work within the educational system changes the
behavior of young people in an essential way. They move from the role of customers
searching for products with some desired property to the role of creative inventors for
designing and developing products with new, original functionalities. The never-ending
story of improving any human products with no limits on what can be approached in the
future would be the most important, great consequence of embedding the creative way
of thinking of engineers into school systems.

4. Teaching Computer Science as a Fundamental Step in the Evolution


of Our Educational Systems
In the two previous sections, we already outlined, with respect to improving teaching
of mathematics and introducing engineering, the principal contributions that could be
offered by teaching computer science in schools in a proper way. This word proper is
crucial for us, and thus we start by listing what we are not allowed to do if we want to
avoid a disaster when introducing computer science to schools. In what follows, we present the most frequent mistakes that already caused frustrations in different countries.
1. To teach how to work with concrete software products and call it computer science. This activity destroyed the image of computer science as a scientific discipline in the past.
2. To let computer science be taught as a part of social media by teachers educated
in human sciences only, and focusing on social, emotional and psychological aspects of communication by new technologies.
3. To choose the topic to be taught by committees of experts offering their favorite
topic without looking at the whole context of science as presented above in Section 2.
4. To sell computer science as the ability to work with computers.
5. To sell computer science as a special branch of mathematics.
6. To sell computer science as a pure engineering discipline.
7. To try to teach the newest achievements of computer science. Think about what
would happen if physics would try to do that instead of following the history, and
thus developing step by step our view of the physical world.

Homo Informaticus. Why Computer Science Fundamentals are an ...

107

8. To try to sell computer science as a joy much easier than mathematics and physics
by avoiding any depth and thus a spiral curriculum, and instead presenting one
simple application after the other.
9. Going too much into technical details about concrete programming languages,
software systems, or hardware.
While 1, 2, and 4 have been the main reasons for destroying the image of computer
science in the society in the past, currently the points 7 and 8 are the major danger for
establishing computer science as a school subject.
After listing what we are not allowed to do, it is now time to switch to positive
recommendations and conceptual work. We do not want to make a proposal for the
content of a computer science curriculum, because our goal is not to go too much into
detail, and because, for sure, there are various possibilities for good implementations of
the computer science subject in schools. What we try here is to recommend a strategy
and principles that are useful for designing a computer science curriculum that can be
accepted as a fundamental part of education in its generality for everybody, and that essentially contributes to:
1. The understanding of our world (in this case with the focus on the artificial world
created by humans).
2. Developing our way of thinking in a dimension that cannot be compensated by
teaching other school subjects.
3. Providing knowledge that is useful and sometimes even expected as prior knowledge for the study of a variety of specialized scientific disciplines later (university
studies, etc.).
As a byproduct, we have to aim to improve teaching overall, especially by strengthening the subjects mathematics and natural sciences. We already presented the basic
strategy how to design a computer science curriculum in Section 2 about mathematics.
We have to follow the genesis of computer science and think about motivations and
fundamental concepts introduced and discovered by computer scientists from the point
of view of science as a whole. For sure, we have to think about or even discover which
concepts are available to which extent in which age, and to follow all the ideas for creating good teaching materials as presented in Section 2. Let us be more concrete and
present a few examples.
One can decide to introduce programming at the age between 8 and 14. The first
step is to deal with abstractions that enable us to unambiguously describe the problem
instances. Then we teach to sample experience by trying to find solutions to concrete,
special problem instances, whose size and complexity may grow with growing experience. After some time, one can develop a strategy that works successfully for a small
collection of problem instances that we subsequently call a problem. Having a solution
strategy, one has to learn to communicate it, i. e., to unambiguously describe it for anybody else. After that, we are allowed to start teaching proper programming by describing
our strategy as a program in a suitable programming language. We are not allowed to
teach the list of all instructions (fundamental words) of a programming language. We
have to start with very few (10 to 15) fundamental instructions, and use modularity to

108

J. Hromkovi

create new words (instructions) in order to make our communication with the computer
more convenient. After writing programs, we let them run in order to verify their correct functionality and learn to correct, improve, and modify our programs in order to get
a final product with which we are satisfied. Let us list some of the added values when
teaching the introduction to programming in the way described above:
1. Training and strengthening the abstraction in representing real situations by drawing graphs, writing lists or tables with different kinds of elements.
2. Contributing to teaching mathematics by searching for a solving strategy, instead
of simply learning a method as a given product of the work of others.
3. Strengthening the ability to express matters and procedures in an exact way, and
so to improve the way used to communicate.
4. Recognizing that a language is not a given final product of human work, but that
any language is continuously developed, and that in case of a programming language one can develop the language on her or his own with respect to her or his
personal demand.
5. Defining new instructions by describing the meaning of the new words by subprograms, one learns the principle of a modular design that is common and fundamental in engineering.
6. Introducing the concepts of testing, verifying, modifying, and improving is the
first contact with the creative, constructive work of engineers.
A really good teaching sequence for introductory programming can be created if one
focuses on the above listed added values and not on technical details of programming
languages and other software used or on a specific class of tasks.
Another nice example is teaching cryptography. Cryptography can be viewed as
the history of developing the notion secure cryptosystem. One can start with the
historical examples in order to introduce the basic terms decryption, encryption, key,
and cryptosystem with a lot of creative work by designing and breaking new, own
cryptosystems. After defining the concept of security by Kerckhoff, one can build
the bridge to probability theory. The concept of probability was used to design new
cryptosystems and later to break them. One can wonderfully understand the importance and the usefulness of the concept of probability studying the history of secret
communication in this way. Then one can introduce the formal mathematical definition of absolutely secure cryptosystems with respect to the concept of probability, and
recognize that such system cannot be built for practical purposes. Finally, the concept
of computational complexity offering public-key cryptosystems is the way out, leading
to the recent e-commerce.
What we try to repeatedly present as the key strategy is to follow the history of the
discoveries of particular concepts, methods, and ideas, and not to try to sell finalized
products of science. The creative work is the most (and may be even the only really)
exciting part of the study. Let us teach creativity by repeatedly discovering things that
were already discovered, up to the point where one is able to discover something completely new. Forget about teaching facts, teach how to verify the trustability of claims
made by others. We are lucky, because we are allowed to create a curriculum for a

Homo Informaticus. Why Computer Science Fundamentals are an ...

109

completely new subject. We can implement principles, which the other subjects still
did not recognize, and so contribute to the evolution of the system of education. For
those who would like to see detailed implementations of the design principles presented
above, we recommend to following textbooks from our production (Bckenhauer and
Hromkovi, 2013; Freiermuth et al., 2014; Hromkovi, 2011; Hromkovi, 2014) or
the book Algorithmic Adventures from Knowledge to Magic (Hromkovi, 2008;
Hromkovi, 2009).

References
Bckenhauer, H.-J., Hromkovi, J. (2013). Formale Sprachen. Springer Vieweg.
Freiermuth, K., Hromkovi, J., Keller, L., Steffen, B. (2014). Einfhrung in die Kryptologie. 2nd Edition.
Springer Vieweg.
Hromkovi, J. (2011). Berechenbarkeit. Vieweg+Teubner.
Hromkovi, J. (2008). Sieben Wunder der Informatik Eine Reise an die Grenze des Machbaren.
Vieweg+Teubner.
Hromkovi, J. (2009). Algorithmic Adventures From Knowledge to Magic. Springer.
Hromkovi, J. (2014). Einfhrung in die Programmierung mit LOGO. 3rd Edition. Springer Vieweg.

J. Hromkovi is professor of informatics with a special added focus on computer science education at ETH Zurich. He is author of
about 15 books published in 6 languages (English, German, Russian,
Spanish, Japanese, and Slovak) and about 200 research articles. He is
member of Academia Europaea and the Slovak Academic Society.

Olympiads in Informatics, 2016, Vol. 10, 111124


2016 IOI, Vilnius University
DOI: 10.15388/ioi.2016.08

111

Examples of Algorithmic Thinking in


Programming Education
Juraj Hromkovi, Tobias Kohn, Dennis Komm, Giovanni Serafini
Department of Computer Science, ETH Zrich
Universittstrasse 6, 8092 Zrich, Switzerland
e-mail: {juraj.hromkovic, tobias.kohn, dennis.komm, giovanni.serafini}@inf.ethz.ch
Abstract. Algorithmic thinking and problem solving strategies are essential principles of computer science. Programming education should reflect this and emphasize different aspects of these
principles rather than syntactical details of a concrete programming language. In this paper, we
identify three major aspects of algorithmic thinking as objectives of our curricula: the notion of a
formal language to express algorithms, abstraction and automation to transfer proven strategies to
new instances, and the limits of practical computability.
The primary contribution of this paper are three examples that illustrate how general aspects
of algorithmic thinking can be incorporated into programming classes. The examples are taken
from our teaching materials for K-12 and university non-majors and have been extensively tested
in the field.
Keywords: algorithmic thinking, K-12, spiral curriculum, programming education, Logo, Python.

1. Introduction
Algorithmic thinking constitutes one of the core concepts of computer science. It has
proven a versatile and indispensable tool for problem solving and found applications far
beyond science. Hence, sustainable computer science education should be built upon
algorithmic thinking as its primary objective, thus unfolding benefits for a broad and
general education. However, how do we bring algorithmic thinking to computer science
education? In this paper, we identify a number of principles that we want to deliver to
students at different levels. As the main contribution, we describe concrete examples of
how to teach these paradigms, which have been proven successful in the past.
Our work is part of ubiquitous efforts towards establishing sustainable computer science
in K-12 education. Particularly noteworthy and inspiring are CS unplugged approaches
as proposed by Bell etal. or Gallenbacher, which do completely away with computers
and solely focus on the underlying algorithmic principles (Bell et al., 2012; Gallenbacher,
2008). By incorporating such ideas into programming education, we effectively combine
the strengths of the two approaches, resulting in a truly sustainable education.

112

J. Hromkovi et al.

1.1. The Setting


The examples presented in this paper stem from teaching materials we have developed
for primary school, high school, and university, respectively (Gebauer et al., 2016;
Bckenhauer et al., 2015a; Bckenhauer et al., 2015b; Kohn, 2016). The goal of our
endeavours is to create a spiral curriculum that starts as early as fifth grade in primary
school with iterations throughout mandatory school, and including computer science
classes for non-majors at university level.
We use both Logo and Python in our classes and found that the simplicity of Logo
is especially well-suited for primary school and complete beginners. At high school
and university level, Python then allows us to discuss topics in more depth and to better
link our programming classes to mathematics and the sciences. We have also extended
our Python interpreter and included Logos repeat-loop into Python. This allows us
to introduce iteration at an early stage without the need for variables, getting the best
of both worlds.
Our curricula and examples make heavy use of turtle graphics, both in Logo as well
as in Python. Apart from the obvious benefits of direct visualization, the turtle is also a
source of powerful didactical metaphors. In particular, the examples as presented in this
paper all rely on turtle graphics to convey or visualize an algorithmic principle.

1.2. Objectives
Computer science is a vast field with algorithmic thinking at its core. Our curricula
hence focus on the study of algorithms and its various aspects. Our approach comprises
three major aspects of algorithmic thinking, as described in the following paragraphs:
the notion of the programming language as a formal language to express algorithms, abstraction and automation as central problem solving strategies, and the limits of practical
computability as a motivation for improving existing algorithms. More on the authors
goals, motivation, and approaches can be found in a complementing paper (Hromkovi
etal., 2016).
Concept of a Formal Language. Students are introduced to programming as a means to
convey instructions to a machine in our case the turtle. The initial set of instructions is
strongly limited and restricted to basic movements such as moving forward and turning.
Each instruction has a clearly defined syntax and semantics, avoiding any ambiguity.
At first, then, programming is the activity of writing sequences of such instructions, encoding graphical shapes. From our perspective, this is to say that students use a formal
language to combine words to sentences. Even though each valid sentence conveys the
information of a graphical shape, not every sentence makes sense in the context of the
interpretation of the resulting shape.
The initial vocabulary given to the students is not adequate to encode more complex
shapes in a human-accessible form. Students are early required to extend the vocabulary
by defining new words, i. e., by defining subroutines. In the context of the turtle, this can

Examples of Algorithmic Thinking in Programming Education

113

Fig. 1. By parametrizing programs, we gradually gain more versatile algorithms and procedures. Drawing a square of fixed size is the first step towards drawing arbitrary polygons of
various sizes (above). Likewise, loops allow us to build ever more complex and larger programs out of simple and small parts (below).

be beautifully explained as teaching the turtle new words (Papert, 1993). The semantics of the new words is expressed algorithmically as a sentence over an already existing
vocabulary. Think, for instance, of a house consisting of a triangle and a square. Both
the triangle and the square themselves might be expressed as sequences of forward- and
turning-instructions.
Hence, our objective is to provide students with a simple yet expandable base of
instructions, the means to combine these instructions to sentences, and to define new
words with associated unambiguous semantics. This way, the students are exposed to
the concepts of modularization, formal languages, and expressing semantics in algorithmic form.
Abstraction and Automation. Programming is, of course, much more than combining
instructions to form programs. Some of the most essential key concepts are abstraction
and automation. Modularization, for instance, only unfolds its full potential in combination with parameters. Having a dedicated instruction to draw a square, say, helps to
clarify the intent of a program. Allowing that very same instruction to draw squares of
various sizes makes it versatile and open to applications beyond its initial conception.
Further abstraction could even introduce a second parameter to pertain to the number
of vertices to draw, resulting in one instruction capable of drawing all regular polygons
(see Fig. 1).
Abstraction itself also requires the concept of automation. Even drawing a regular
polygon with a given number of vertices is a tedious task without the notion of a loop.
For the step to an abstract instruction encompassing all polygons, the loop becomes a necessity. Once this level of automation is mastered, students are introduced to loops with
variations, allowing for figures such as spirals where even the parameter automatically
varies (see Fig. 1).
Automation and abstraction are not just core concepts of programming but of computer science and algorithmic thinking in a much wider sense. Expressed in the context
of problem solving, abstraction corresponds to the question Can we adapt an already
known or universally available strategy to solve the problem at hand? Once we know
how to solve a single instance, we then employ the concept of automation to apply our
solution to a large set of instances.

114

J. Hromkovi et al.

Limits of Practical Computability. Finding solutions automatically is not always


feasible. Indeed, the insight that there are problems that cannot be solved algorithmically (i.e., undecidable problems), shown in 1936 by Turing in his seminal paper On
Computable Numbers, with an Application to the Entscheidungsproblem (Turing,
1936), is one of the deepest results of mathematics and laid the foundation for computer science itself. However, even computable problems can often only be solved
under certain restrictions, e. g., using an unacceptable amount of resources (time and
space), or without full precision due to numeric errors. This gives rise to numerous
interesting research questions and solutions, which can both be explained to nonprofessionals.
For education, however, we need to make computability and its limitations visible
and tangible. A prime example to serve this objective, as taken from turtle graphics,
are circles. A computer cannot draw an exact circle, it must be drawn using an approximation such as a polygon (or Bzier curve). The cost of drawing an approximating polygon increases with the number of vertices, mainly due to the fact that the
turtle needs time to turn at the vertices. Students therefore must find a compromise
between more accurate representations and faster renderings, and eventually realize
that the limitations of screen resolution quickly nullify additional precision beyond a
certain point.
When seen in the light of modern applications, intractability is of particular importance to cryptography. In this regard, the inability to design efficient algorithms has
far-reaching implications beyond computer science and its inclusion into the curriculum
is well-warranted. At the same time, we found cryptography to be very motivating and
well-suited as a subject of its own (Freiermuth etal., 2010).

2. Modular Development: Building a Town Step by Step


Our group is actively involved in introducing young students to programming as soon
as at fifth grade. To this end, we developed teaching material, hold classes, and, most
importantly, introduce teachers to our didactic approach as well as to fundamental
concepts of computer science. These school projects are based on the German textbook An introduction to programming in Logo (Hromkovi, 2014, German: Einfhrung in die Programmierung mit Logo), and on a Logo booklet (Gebauer etal., 2016)
covering the contents of its first seven chapters. The following example is taken from
this booklet.
As already mentioned, one of the main objectives of our programming classes consists in making the students confident with the modular development of programs and
teaching them how to systematically apply this problem solving strategy to complex
problems. To illustrate our approach and the achievements of the students, we present
a sequence of learning activities from the third (out of seven) unit of the courses.
At this point, the students already know how to move the turtle forward and backward on a straight line, how to rotate it as well as how to iterate over a sequence of

Examples of Algorithmic Thinking in Programming Education

115

instructions for a predefined number of times. More precisely, the current vocabulary of
the turtle comprises the following instructions as well as their abbreviations: forward
(fd), back (bk), left (lt), right (rt), clearscreen (cs), penup (pu), pendown
(pd), and repeat. Furthermore, the students are already used to giving their programs
names and to reusing available programs as subprograms within main programs in an
elementary way. In subsequent activities, they learn how to develop a table that consists
of rows of identical squares in a proper modular way.
To reinforce the concept of modular development, the students are now challenged
to write a program for drawing a small town, which consists of streets with identical
houses. While the program for drawing a house is already available in the booklet, the
students are expected to consequently apply the approach they intensively practiced.
They are therefore expected to:
Identify the next shape or pattern they can systematically reuse.
Write a sequence of instructions for drawing it.
Give this subprogram a name.
Test and iteratively improve the code until the solution meets the assignment.
Afterwards, the students should reflect on how to adjust the position of the turtle in
order to draw the pattern by simply reusing the program they developed above, to test
and to iteratively improve their approach, and to finally integrate the two modules of
their solution. In a following step, this new main program can be reused as a subprogram in other main programs of increased complexity. More specifically, the students are
given the program shown in Listing 1.1 accompanied by the following exercise, which
asks them to study the effects of each command in detail.
Exercise. Where does the turtle start drawing the house? Think about the path the
turtle follows when drawing the house using the program HOUSE. Where is the
turtle located at the end of the execution? Draw the image and describe the effect
of each command.
Next, they are told how to design a program HOUSEROW (Listing 1.2) that uses HOUSE
as a subprogram. Here, the most difficult task is to position the turtle in such a way that,
after each iteration, the new house is drawn at the correct coordinates.
Listing 1.1: Drawing a house using a simple repeat-loop.

to HOUSE
rt 90
repeat 4 [fd 50 rt 90]
lt 60 fd 50 rt 120 fd 50 lt 150
end
Listing 1.2: Drawing a row of houses.

to HOUSEROW
repeat 5 [HOUSE rt 90 pu fd 50 lt 90 pd]
end

116

J. Hromkovi et al.

A small
townthat
that consists
of 15
Fig. 2:Fig.
A 2.small
town
consists
ofhouses.
15 houses.

At this
theare
students
already
how approach
to move the
turtletoforward
and
Finally,
the point,
students
asked to
use theknow
modular
in order
draw the
town
a straight
line,This
howway,
to rotate
it as well
howtoto
iterate
a
thatbackward
consists ofon
multiple
streets.
the students
learnashow
extend
theover
language
sequence
of instructions
a predened
number
of times.
precisely,
the is
of the
computer
step by stepfor
with
more complex
programs.
TheMore
crucial
observation
vocabulary
of the
turtle comprises
the subprograms.
following instructions as well as
thatcurrent
the overall
complexity
is hidden
in the smaller
their abbreviation: forward (fd), back (bk), left (lt), right (rt), clearscreen
(cs),
penup (pu),
pendown
(pd),would
and repeat.
Furthermore,
the students
are by
Exercise.
At this
point, we
like to extend
the complex
of buildings
already
used
to
giving
their
programs
names
and
to
reusing
available
programs
additional streets. Use the program HOUSEROW as a building block to draw the
as subprograms within main programs in an elementary way. In subsequent
image shown in Fig. 2.
activities, they learn how to develop a table that consists of rows of identical
Hint:inAfter
the completion
of a row, the turtle has to be moved to the correct posisquares
a proper
modular way.
To reinforce
thenext
concept
tion
to build the
street.of modular development, the students are now
challenged to write a program for drawing a small town, which consists of streets
Modular
development
offersthe
a didactically
creative
tasks. In
with identical
houses. While
program forappealing
drawing aplatform
house is for
already
available
in the
booklet,exercises,
the students
are expected
tothat
consequently
thesuch
approach
the two
following
the students
observe
even smallapply
changes
as adding
they intensively
are houses
therefore
expected
a window,
a door, orpracticed.
a chimneyThey
to their
may
have a to:
considerable impact on the

overall
outcomethe
of the
streets
townthey
theycan
are systematically
designing.
identify
next
shapeand
or the
pattern
reuse,

write a sequence of instructions for drawing it,


Exercise. We decide to order the roof for the houses from another vendor. That
give this subprogram a name, and
weand
getiteratively
two types improve
of building
Onethe
called
ROOFmeets
and the
another
one called
is,
test
the blocks:
code until
solution
assignment.

BASE. Write two programs to draw the two building blocks. Combine those proAfterwards,
thea new
students
should
reectthat
on how
to aadjust
grams
to form
program
HOUSE1
draws
house.the position of the

turtle in order to draw the pattern by simply reusing the program they developed
above,
to testThe
andhouses
to iteratively
improve
their
andtotobenally
integrate
Exercise.
in Listing
1.1 are
veryapproach,
simple. Try
creative
and come
the up
two
modules
of
their
solution.
In
a
following
step,
this
new
main
with a new design for a house. Use your house to build an entireprogram
complex of
can be reused as a subprogram in other main programs of increased complexity.
buildings.
More specically, the students are given the program shown in Listing 1.1
accompanied
by thethat
following
which is
asks
them to study
the eects
of
The
students learn
modularexercise,
development
a systematic
and efficient
problem
each command in detail.

solving strategy. Moreover, they experience that subsequent changes in a basic module
of a properly developed complex program require no or very limited additional program5
ming effort.

Examples of Algorithmic Thinking in Programming Education

117

3. Making Approximation Errors Visible with the Pac-Man


The turtle draws a circle by approximation, actually drawing a polygon with, say, 36 vertices (in practice, students often choose 360 vertices at first, building upon their knowledge that 360 stands for a complete circle). While the resulting figure is not discernible
from a true circle on the screen, the approximation requires a couple of corrections when
the circle is combined with other shapes. Most prominent is the question of finding the
circles center and the correct value of the radius. Both are slightly, but discernibly, off
compared to a true mathematical circle.
A particularly illuminating example is drawing a Pac-Man shape. Students are asked
to write a Python program that draws a Pac-Man and typically end up with a solution as
shown in Listing 1.3 (note that the repeat-loop shown here has been added to Python in
order to support our curriculum. A further discussion can be found in the aforementioned
complementing paper (Hromkovi etal., 2016)). However, their resulting pictures show
that the shape is not closed as seen in Fig. 3: there is a small gap at the center of the
shape. This discrepancy is subsequently discussed in a dedicated section and leads to a
precise drawing of a pie chart.
Why does this gap in the center occur and how can we correct it? In a circle, any radius meets the circumference perpendicularly. This fact has been used twice in the program (Listing 1.3). For the approximation with a polygon, this does not hold anymore:
the angle between the radius leading to a vertex and the circumference requires a small
correction (Fig. 4). The correction is exactly half of the turtles turning angle at each
vertex. For our example with 36 vertices, this results in a 5-correction (Listing 1.4). The
correction of the angle can also be taken into the loop, resulting in a more symmetrical
solution (Listing 1.5).
Listing 1.3: Drawing a Pac-Man.

from turtle import *


RADIUS = 100
right(45)
forward(RADIUS)
left(90)
repeat 27:
forward(RADIUS * 3.1416 * 2 / 36)
left(10)
left(90)
forward(RADIUS)

Listing 1.4: Correcting the angle (1).

left(90 + 5)
repeat 27:
forward(RADIUS * 3.1416 * 2 / 36)
left(10)
left(90 - 5)

118

J. Hromkovi et al.

Fig. 3. An incomplete Pac-Man.

Fig. 4. As circles are approximated by polygons the radius does not


meet the circumference in a right angle but is off by an angle .
Listing 1.5: Correcting the angle (2).

repeat 27:
left(5)
forward(RADIUS * 3.1416 * 2 / 36)
left(5)
Listing 1.6: Starting the circumference not at a vertex but at the center of an edge instead.

repeat 27:
forward(RADIUS * 3.15 / 36)
left(10)
forward(RADIUS * 3.15 / 36)

Finally, an alternative solution is to have the radius meet the circumference not at a
vertex but at the center point of an edge. In this case, the radius does meet the circumference perpendicularly. The resulting code, again, has a very symmetrical form (Listing
1.6). Yet the ratio between radius and circumference now differs and requires to change
the used approximation of the value of .

4. Runtime Analysis Backed up by a Little Math


One of the authors is currently part of the team responsible at ETH Zurich for teaching
computer science basics to non-computer science students (more specifically, students
of biology, pharmacology, environmental sciences, health sciences and technology, agriculture, geology, and nutritional sciences).
We have been introducing students to Logo using the previously mentioned booklet
(Gebauer etal., 2016, see Section 2), whose main part is covered in roughly the first unit

Examples of Algorithmic Thinking in Programming Education

119

Listing 1.7: A simple square.

to QUAD :WIDTH
repeat 4 [fd :WIDTH rt 90]
end
Listing 1.8: Testing whether a given number is prime.

to PRIME :NUM
ht
make "IT 2
make "ISPRIME 1
while [:IT<:NUM] [
make "RES mod :NUM :IT
if :RES=0 [make "ISPRIME 0] []
make "IT :IT+1
]

if :ISPRIME=1 [setpc 1 QUAD 8] [setpc 0 QUAD 8]


end

of the lecture. After that, an advanced booklet is supplied that is specifically designed for
this class (Bckenhauer etal., 2015a). As part of this booklet, more involved concepts
such as variables, conditional execution, and while-loops are introduced. The students
are then given three projects, which consolidate what they have learned so far by designing small programs to solve specific tasks (Bckenhauer etal., 2015b). The lecture is
accompanied by exercise classes in which the students are asked to present and explain
their solutions to a tutor.
As a first step towards the mathematical analysis of algorithms, we give the students
the following project. The examples are taken from the project booklet (Bckenhauer
etal., 2015b) and the corresponding lecture notes. The goal is to show the students the
idea of how to mathematically analyze how long a program will run depending on the
input size. A typical example that does not need anything beyond high school mathematics is to test whether a given number is prime. Logo is especially suited to visualize the
distribution of (small) prime numbers without much overhead.
The first component is a program called QUAD (Listing 1.7) that draws a square, and
which essentially consists of a simple loop, which the students already know from previous lessons. The size of the square is determined by the value of the parameter :WIDTH.
Next, we can write a program that tests whether a given input is a prime number.
This is done in the most straightforward fashion, i. e., by testing whether there is smaller
number (except 1) that divides it. Depending on the result, either a red or black square is
drawn on the screen using the instruction setpencolor (setpc). Before that, the turtle
is hidden with the instruction hideturtle (ht). The corresponding algorithm PRIME
is shown in Listing 1.8.
The students can easily follow the steps and try out different inputs. As a next step,
we ask them to carefully check corner cases, and give them the following exercise.

120

J. Hromkovi et al.

Exercise. PRIME does not yet work correctly on all inputs as the value of :IT is
initially set to 2. However, we know that 1 is by definition not a prime number.
Thus, PRIME 1 creates an incorrect output. Extend the program such that a black
square is drawn when the input is 1. Moreover, an error message should be output
if 0 or a negative number is given.
Once the students familiarized themselves with the algorithm, we discuss its running
time. It is obvious that the time grows with larger inputs, and this seems to be unavoidable on an intuitive level. Furthermore, it is easy to see that the running time directly
depends on how often the body of the while-loop has been executed. We therefore agree
on counting the number of these executions and neglect how many instructions are executed with each iteration. The above trivial attempt needs roughly 2 iterations for inputs
of length (hence, is the number of bits used to represent the input number). Now we
show how to improve this running time using a little bit of math. The following exercise
is well-suited to be presented to the students as part of the lecture.
Exercise. We can now make our algorithm PRIME faster (more efficient) by
having it execute the while-loop less often. To this end, we make use of the
following idea.
Suppose the input is not a prime number. Then, by the definition of a prime
number, there is a number , which is neither 1 nor , that divides without
remainder. But from this it also follows that there is a second number , which
is also neither 1 nor , that also divides without any remainder. An important
point is that one of these two numbers is not larger than the square root of.
If, e. g., is larger than , then has to be smaller, since otherwise were
larger than .
We want to use this observation to improve PRIME. Write an algorithm PRIME2
which works exactly as PRIME, but in which the while-loop is modified such that
the variable :IT does not take the values of all numbers smaller than :NUM, but
only those that are smaller than or equal to :NUM .
The students are asked to verify the speedup by trying different inputs. Good candidate inputs to observe the increase in speed of course depend on the computer used.
Moreover, the students can try to make a simple running time analysis of PRIME2 themselves, which leads to the result that the loop is now executed at most (roughly) 1.41
times for inputs of length .
The above considerations give rise to another question, namely in which kind of analysis we are interested. To this end, the algorithm is modified such that the while-loop
is left as soon as a divisor of the input is found. The resulting algorithm obviously still
works correctly, but is it faster? Indeed, if the input is, say, an even number, the running
time of the new algorithm is a lot better. However, if the input is prime, both algorithms
take the same time. This is exactly the difference between a best case and a worst case
analysis of the algorithms running time.
Now we can follow the modular building of algorithms (see Section 2) and use PRIME2 as a building block to visualize the distribution of small prime numbers. More
precisely, the algorithm PRIMES shown in Listing 1.9 uses PRIME2 as a subprogram to

Examples of Algorithmic Thinking in Programming Education

121

Fig. 5. The distribution of prime numbers between 1 and 26. Instead of red and black
Fig. 2: The
distribution ofsquares,
primewenumbers
between 1 and 26. Instead of red and
use filled and unfilled ones.
black squares, we use lled and unlled ones.

Fig. 6. The distribution of prime numbers between 1 and 104.


Fig. 3: The
distribution of prime numbers between 1 and 104.
Listing 1.9: Visualizing primes.

However,
if the input
to PRIMES
:MAX is prime, both algorithms take the same time. This is exactly
the dierence
a best
case
pu lt between
90 fd 300
rt 90
pdand a worst case analysis of the algorithms
runningmake
time."TEST 1
Nowrepeat
we can :MAX
follow[the modular building of algorithms (see Section 2) and use
pu
rt
90 fd 10 lt 90 pd
PRIME2 as a building
block to visualize the distribution of small prime numbers.
PRIME2 :TEST
More precisely,
the
algorithm
make "TEST :TEST+1 PRIMES shown in Listing 1.9 uses PRIME2 as a
subprogram
to visualize the appearances of prime numbers among the rst :MAX
]
endnumbers.
natural
Listing 1.10: Visualizing primes more nicely.

Listing 1.9: Visualizing primes.


to PRIMES2 :MAX :ROW
to pu
PRIMES
MAX:ROW*10/2 rt 90 pd
lt 90 :fd
pu
lt "TEST
90 fd1 300 rt 90 pd
make
make
repeat" TEST
:MAX 1[
repeat
MAXfd[ 10 lt 90 pd
pu rt :90

PRIME2
:TEST
pu
rt 90
fd 10 lt 90 pd
make "REST
mod :TEST :ROW
PRIME2
: TEST
if :REST
= 0 :[TEST +1
make
" TEST
pu lt 90 fd :ROW*10 lt 90 fd 10 rt 180 pd
]
] [ ]
end
make "TEST :TEST+1
]

end
The result of executing PRIMES 26 is shown in Figure 5. Next, we can improve
the
appearance
by having
the squares
multiple
rows
(Listing
1.10). To
visualize
the appearances
of prime
numbersdrawn
amonginthe
first :MAX
natural
numbers.
this
end,
we
write
a
new
algorithm
PRIMES2
with
an
additional
parameter
:ROW.
The result of executing PRIMES 26 is shown in Fig. 5. Next, we can improve
the
The
turtle
moves
to
the
next
row
whenever
it
drew
a
number
of
squares
that
is
appearance by having the squares drawn in multiple rows (Listing 1.10). To this end, we
divisible by the value of :ROW. With PRIMES2 104 26 we obtain an output as
write a new algorithm PRIMES2 with an additional parameter :ROW. The turtle moves to
shown in Figure 6.
the next row whenever it drew a number of squares that is divisible by the value of :ROW.
An advanced exercise then deals with prime powers. The students should
With PRIMES2 104 26 we obtain an output as shown in Fig. 6.
solve this task at home, either alone or in small groups. The diculty of this
An advanced exercise then deals with prime powers. The students should solve this
exercise is due to the usage of a return statement, which is implemented by the
task
at home,
either alone
or in small groups. The difficulty of this exercise is due to the
output
instruction
in Logo.
usage of a return statement, which is implemented by the output instruction in Logo.
11

122

J. Hromkovi et al.

Exercise. A prime power is a natural number that has exactly one prime factor. For
instance, 27 is a prime power since it has the prime factorization
27 = 3 3 3 = 33.
Clearly, every prime number is thus also a prime power.
In this project, you design a program PRIMEPOW, which checks whether a given
number is a prime power. To this end, do the following steps:
1. Rewrite the program PRIME to obtain a program PRIMEOUT that uses the command output instead of drawing squares. If the value of :NUM is prime, the
value 1 should be returned, otherwise 0.
2. PRIMEPOW has one parameter :TEST. We want to check whether the value assigned to :TEST is a prime power (possibly with the exponent being 1).
3. First, the program checks using PRIMEOUT whether :TEST is a prime number. If so, Prime. is printed on the screen and the execution is ended using
stopall.
make "ISPRIME PRIMEOUT :TEST
if :ISPRIME=1 [pr [Prime.] stopall] []
4. Otherwise, all numbers smaller than the value of :TEST are iterated, and again
using PRIMEOUT it is checked whether the current number is a prime. If so, it is
checked whether it divides the value of :TEST without remainder.
5. If such a prime number is found, PRIMEPOW takes note of this by setting the
value of a variable :FOUND to 1. :FOUND is initialized with 0. If a second such
prime number is found, this will be noted since the value of :FOUND is already
1. In this case, More than one divisor. is printed on the screen and the execution is again ended with stopall.
6. Finally, if :FOUND is still 1 after all numbers were tested, Prime Power. Base:
and the prime number that divides the value of :TEST without remainder are
printed on the screen.
7. Check PRIMEPOW using small input values.
This introduction using Logo proved to be very valuable for the students in the succeeding lessons, where we implement more complex projects using Python. More precisely, they were able to learn important paradigms without having to worry too much
about syntactical details.

5. Conclusion
Programming education is a great opportunity to teach important core concepts of computer science on various levels and to establish algorithmic thinking as part of a broad
and general education. A necessary prerequisite is, of course, that we find ways to go
beyond teaching the specifics of a programming language and rather put emphasis on
those aspects of programming that lead to a deeper understanding of computer science.

Examples of Algorithmic Thinking in Programming Education

123

In this article, we have provided three examples of how programming education can
incorporate more general principles of algorithmic thinking. All three examples have
been taken from our well-tested teaching materials for primary school, high school, and
university level, respectively. Further details about our curricula are given in the complementing paper (Hromkovi etal., 2016).

References
Bell, T., Rosamond, F., Casey, N. (2012). Computer science unplugged and related projects in math and computer
science popularization. The Multivariate Algorithmic Revolution and Beyond, Springer-Verlag, 398456.
Bckenhauer, H.-J., Hromkovi, J., Komm, D. (2015). Programmieren mit LOGO Projekte.
http://abz.inf.ethz.ch/wp-content/uploads/unterrichtsmaterialien/primarschulen/
logo_projekte.pdf
Bckenhauer, H.-J., Hromkovi, J., Komm, D. (2015). Programmieren mit LOGO fr Fortgeschrittene.
http://abz.inf.ethz.ch/wp-content/uploads/unterrichtsmaterialien/primarschulen/
logo_heft_2_de.pdf
Freiermuth, K., Hromkovi, J., Keller, L., Steffen, B. (2010). Einfhrung in die Kryptologie. Springer.
Gallenbacher, J. (2008). Abenteuer Informatik. IT zum Anfassen von Routenplaner bis Online-Banking.
Springer, 2 edition.
Gebauer, H., Hromkovi, J., Keller, L., Kosrov, I., Serafini, G., Steffen, B. (2016). Programmieren mit
LOGO.
http://abz.inf.ethz.ch/wp-content/uploads/unterrichtsmaterialien/primarschulen/
logo_heft_de.pdf
Hromkovi, J. (2014). Einfhrung in die Programmierung mit LOGO Lehrbuch fr Unterricht und Selbststudium. Springer, 3 edition.
Hromkovi, J., Kohn, T., Komm, D., Serafini, G. (2016). Combining the Power of Python with the Simplicity of
Logo for a Sustainable Computer Science Education. Unpublished Manuscript.
Kohn, T. (2016). Python. Eine Einfhrung in die Computer-Programmierung.
http://jython.tobiaskohn.ch/PythonScript.pdf
Papert, S. (1993). Mindstorms. Basic Books, 2 edition.
Turing, A. M. (1936). On computable numbers, with an application to the Entscheidungsproblem. Proceedings
of the London Mathematical Society, 42(2), 230265.

124

J. Hromkovi et al.

J. Hromkovi is professor of informatics with a special added focus on computer science education at ETH Zurich. He is author of
about 15 books published in 6 languages (English, German, Russian,
Spanish, Japanese, and Slovak) and about 200 research articles. He
is member of Academia Europaea and the Slovak Academic Society.
T. Kohn is writing his PhD thesis in computer science at ETH Zurich.
The focus of his research is programming education, particularly in
high schools. He holds an MSc in mathematics from ETH and has been
teaching mathematics and computer science for 10 years.

D. Komm is lecturer at ETH Zurich and an external lecturer at University of Zurich. He studied computer science at RWTH Aachen
University and Queensland University of Technology. He received
his PhD from ETH Zurich in 2012. His research interests focus on
algorithmics and advice complexity.
G. Serafini is lecturer in the Computer Science Teaching Diploma
Program at ETH Zurich. He holds a MSc in computer science and
a teaching diploma in computer science from ETH Zurich. His research interests focus on the contribution of computational thinking to school education. He is a member of the board of the Swiss
Computer Science Teacher Association and a member of the Swiss
Olympiad in Informatics.

Olympiads in Informatics, 2016, Vol. 10, 125159


2016 IOI, Vilnius University
DOI: 10.15388/ioi.2016.09

125

Programming in Slovak Primary Schools


Martina KABTOV1, Ivan KALA1,2, Monika TOMCSNYIOV1
Department of Informatics Education, Comenius University
Mlynska dolina, 842 48 Bratislava, Slovak Republic
2
UCL Knowledge Lab, Institute of Education
23-29 Emerald Street, WC1N 3QS London
e-mail: martina.kabatova@gmail.com, {kalas; tomcsanyiova}@fmph.uniba.sk
1

Abstract. In our paper, we want to present the conception of elementary programming in primary
Informatics education in Slovakia and the process of its integration into ordinary classrooms.
First, we will familiarize the reader with the tradition of so called Informatics education in
Slovakia and with the various stages of the process of its integration. We will formulate the learning objectives of the elementary informatics as a school subject in Slovakia (referring to Blaho
and Salanci, 2011) and give reasons why we believe that it offers an important opportunity for
developing informatics knowledge, computational thinking and problem solving skills. We will
primarily focus on the presentation of our arguments why we consider programming (in the form
rigorously respecting the age of the primary pupils) to be appropriate and productive constituent
of learning already for this age group. Several recent research findings, presented by Ackermann
(2012) and others support our position here. In the next chapter, we will present in detail the
conception of elementary programming and how it is implemented in the continuing professional
development (CPD) of primary teachers in Slovakia. We will examine which programming environments are being used, what kind of pedagogies and which specific learning objectives our
teachers apply. We will list programming concepts and identify corresponding cognitive operations, which we find appropriate for primary pupils. Then we will present and analyse the CPD of
our in-service teachers (and the position of programming in this process) which we have recently
implemented in Slovakia. Another important element of our CPD strategy is the well-known
Bebras contest (in Slovakia it is called iBobor or Informatics Beaver). In the next chapter of
our paper, we will apply qualitative educational inquiry methods to examine how our conception of elementary programming has really penetrated into primary classes in Slovakia. We are
also interested in how it is being received by the teachers and pupils. Through interviews with
the teachers we will identify different aspects of the whole process and main risk factors, which
may complicate or hinder the implementation. In the final chapter, we will study the tendency
to develop informatics and programming at the primary level in the context of various research
projects presented in the academic research literature. We will compare various key findings of
other research projects with our own experience.
Keywords: educational programming, primary education, computing, computational thinking.

126

M. Kabtov, I. Kala, M. Tomcsnyiov

1.Introduction
In recent years many educators, education policy makers and scientists call for integration of what they call computational thinking into primary education of all pupils. In influential documents like (The Royal Society, 2012) a need to distinguish computational
thinking (or computer science, informatics or computing education) from the ICT education is declared. However, reasons for such reflections differ computer scientists and
industry leaders feel that not enough young people (and only very few women) choose to
pursue a career in computer science and they believe that if pupils become familiar with
some informatics concepts (within their primary education already) they will favour it
later in their lives and careers. Others believe that computational thinking is equally
important and key skill as literacy and mathematical thinking and they call for a redefinition of literacy and for integrating digital literacy development into primary education
for the sake of educating a fully developed citizens to live in the digital world.
While ICT oriented education is included in most national curricula, many countries
do not pay any special attention to including other (and in our opinion more interesting
and more important) informatics concepts. However, we can observe important new step
in the UK by establishing computing as a compulsory subject in every school year since
September 2014.
The situation in Slovakia is different from most of the countries. Informatics as a
separate mandatory subject was established many years ago and for many years we have
been systematically preparing teachers for teaching it. The authors of our national curriculum took a great care to include topics from core informatics along with learning of
basic ICT skills.
Since Comenius University plays a key role in building National Informatics Curriculum (2011, 2015) we have a lot of experience with integrating educational informatics both into schools (primary, lower secondary and upper secondary) and into teachers
professional development (PD). Some activities with digital technology were recently
nation-wide integrated into early childhood education (or children 3 to 6) as well: see
e.g. (