All material for the course Algorithms and Data Structures II (course
1DL231) including slides, lecture plan, assignments and exam
information. Management of groups, handing in of assignments, and
discussion forums will be handled by
studium. All slides and other material
can be found on this website.
Subsections of AD2 1DL231
Syllabus
This page is an elaboration of the learning outcome of course
plan
Specifically we will cover the following topics and sections of the
book (for a CLRS4 reading guide see the individual lecture pages):
Topic
CLRS3 Textbook
Reminder, growth of functions, big-Oh notation, recurrences and divide and conquer.
In Lectures you can find a more detailed
lecture plan with links to additional resources. The timing of the
assignments has been done quite carefully. By the time you are to
start the each assignment we should have covered the material in the
assignments.
Lectures
Lecture, help sessions and grading sessions information
There is a menu item for each lecture where you can find a reading
guide for the textbook, and links to additional material.
Please note that this timetable is still preliminary and is subject to
change. The official timetable is in
timeedit.
For the lecture locations please look at
timeedit
timeedit schedule is always correct. If there are any discrepancies
between this page and timeedit, then please inform me.
How is the course structured? How do the assignments, help sessions
and labs work?
What does it mean to analyse an algorithm?
What is worst case performance?
What is the definition of $O(f(n))$, $\theta(f(n)$, and
$\Omega(f(n))$?
What are some of the basic properties of $O()$,$\theta()$, and
$\Omega()$.
Lecture 2
Guest Lecture by Frej Knutar Lewander
Today’s topic: Graphs revision
Revision on Digraphs/Digraphs: Slides
1-24
Although some of this will be revision, you should pay attention to
how the graph representation effects the time complexity.
All of Chapter 15 of
CLRS3 or all of
Chapter 14 of
CLRS4.
The textbook does not say that much about pseudo-polynomial time and
the 0-1 Knapsack problem, even though it is an important
concept. There there is plenty of material on the internet. I suggest
that you start with the Wikipedia entries on Pseudo-polynomial
time and the
Knapsack
problem. You also
might find these
notes
useful.
What should I know by the end of this lecture?
Yet more dynamic programming examples
How to decompose a problem using Dynamic Programming
Optimal substructure
The difference between polynomial and pseudo-polynomial time. Ask
yourself why isn’t the dynamic program for 0-1 Knapsack polynomial
time?
We will look a greedy algorithm for the coin-change problem. This only
works with certain denomination coins. You should understand the
proof of why it works, and when it works.
Interval scheduling. Again we met a dynamic programming solution
before, here we will look at a simple greedy algorithm and
understand why it is correct.
When I do these lectures live, it normally takes me 3 lectures to go
through the material slowly and do lots of examples. This is a list
of topics that are needed to under network flows. You goal should be
to understand each topic.
Definition of flow network.
The minimum-cut problem.
The maximum flow problem.
The definition of a residual network.
An Augmented path.
The statement of the Min-cut, max-flow theorem.
The Ford–Fulkerson algorithm.
How to use the max-flow algorithm for maximum bipartite matching.
Alternative mathematical API. Flows that are Skew Symmetric flows,
that is $f(u,v)= -
f(v,u)$. We’ll do this on the blackboard, but skew symmetric flows
are a bit counter intuitive, but they make the proofs and
implementation easier. Take a look at the presentation at
Wikipedia. This
is not examined, and I won’t go into much detail.
Min-Cut Max-Flow duality slides 25-36 of
NetworkFlow
I
Choosing the wrong paths: Exponential worst case slides 37-41 of NetworkFlow
I
Summary of complexity results 73-74 of NetworkFlow
I
These notes
contain useful information on greedy algorithms in general and section
5.1.4 is on Union Find. The best source is the textbook Chapter 21
(excluding section 21.4) of
CLRS3
or
Chapter 19 (excluding 19.4) of CLRS4.
Link to online lectures for further study.
Both William
Fist and
Josh Hug
cover the same material, although Josh Hug takes it much more slowly.
William Fist has a number of useful lectures on Union-Find
What should I know by the end of this set of lecture?
What is the union-find API?
What are some of the applications of union-find?
How can I use trees to represent sets?
How do I represent sets of trees as a forest?
What are the different strategies for combining trees? Link by Size
and Link by Rank.
What is path compression? How does this improve the complexity of
union-find? Note that if you go deeply into the analysis of
union-find you will come to amortised analysis. This is the
analysis of the complexity of an algorithm over
multiple-runs. Amortised analysis is not part of this course, but
it is part of AD3 -
1DL481
that is normally taught by Pierre
Flener
Lectures 10 and 11
Today’s topic: P vs NP
This will be a not so formal introduction to P and NP. Every computer
scientist should know something about NP complete problems. If you
know that a problem is NP complete, then you know that it is very hard
to find an optimal solution.
The definition of P and NP
The definition of Reduction and NP Hardness
NP Completeness
Some NP Complete Problems.
What now? What courses should I take to learn more about algorithms
and optimisation?
What should I know by the end of this set of lecture?
The definition of NP? What has guessing a solution got to do with
complexity?
How do reductions work?
What is a complete problem for a complexity class?
You should know some NP-complete problems and have enough idea about
how reductions work so that you can decide if your problem is
NP-complete or not.
Assignments
Overall Structure
There are 3 mandatory assignments, to be done in
alone, worth 2 higher-education credits (ECTS
credits) in total.
The main objective of the assignments is to exercise the theoretical
knowledge gained in the lectures. You are to hand in the code and
a report. The code should follow the coding convention and the report must follow the structure and content
of the demo report
For each assignment, the assistants
supervise 3 help sessions for troubleshooting in the preparation of
your reports.
Each assignment has 2 independent problems, each yielding a problem
score in $0..5$, hence there is a maximum of 30 points to earn. For
each problem, a skeleton code in Python
3 with test
cases is provided. Insufficiently good reports can be defended orally
to an assistant in scheduled grading sessions. Solutions are
discussed by the assistants in solution sessions.
Submission Requirements
You must submit :
Your report
All relevant python files. You must not change the API or function
signatures. If you do this, then we cannot run the automated testing
and you will receive a mark of 0.
The skeleton code comes with an extensive set of test cases. Your
submitted code must pass all test cases. If you code does not pass
all test cases, then we will not read your report and you will receive
a mark of 0 for that part of the assignment. Your implementation
should be correct, and if it is correct then you should be able to
pass all the provided test cases.
Help Sessions
The objective of a help session is only for the assistants to help
you prepare an acceptable solution for the assignment with the closest
upcoming deadline. Also, the necessary course material will normally
have been presented in lectures at least a week prior to the first
help session. You are thus able and even strongly encouraged to
prepare your solution as far as possible until the help sessions and
to attend them, in order to make best use of that reserved time span
of personal attention by the assistants.
Solution Session
The objective of a solution session is only for the assistants to
discuss acceptable solutions to the assignment of the previous
deadline. No code will be handed out. The first two solution
sessions are merged with the initial help sessions to the next
assignment. For timetable reasons, the third assignment has no
solution session.
Comments on your submitted report can be found on Studium; more
detailed comments can be obtained orally from the assistants upon
appointment.
Submission and Deadlines
All assignment reports, with imposed
structure
must be submitted electronically via Studium, whose clock may be
different from yours. Submission deadlines are hard. Grading will
only start after a deadline, so you can submit multiple times until
then.
We reserve the right to give different assignment scores to the
teammates of a team, depending on the performance at the grading
session.
Please report any problems within a team to the head teacher, who
will handle the case in confidence, in the best interest of both
teammates, keeping the ethics dimension in mind.
Expected Effort
One higher-education credit (ECTS credit) translates under Swedish
university law into an expected 26.67 hours of work for the average
student. Hence 133.33 hours are expected on this 5-credit course.
The assignments are worth 2 credits in total. Not counting the
19.5 hours spent on the 13 lectures, the 3 assignments are
calibrated to take an average of 30 hours each, for the average
student, for each teammate, including the corresponding help, grading,
and solution sessions, and this time counts
also as exam preparation.
All this does not clash with other courses you are taking, as
university studies are legally defined to take 400 hours of work per
study period (normally 10 weeks), and the standard 15 credits targeted
in a study period are calibrated to reach that total.
Do not expect the 3 assignments to be equally labour-intensive, and
do not expect the 2 problems of each assignment to be equally
labour-intensive. Assignment 3 is calibrated somewhat shorter due to
the proximity of the exam.
Former Students
Students from previous academic years who have not yet been awarded
the credit point(s) for the assignments contact the head teacher.
Subsections of Assignments
Coding Convention
Software
All assignments are to be written in Python
3. Your assignments
will be partially tested by an automated system, and the exact version
of Python that will be used will be specified on the assignments.
The learning of sufficient Python skills is within your time budget
for this course, and this should not take more than a couple hours.
We highly recommend you learn or use
LaTex for typesetting your assignment
reports in a professional way, but this is optional. The learning of
LaTeX is outside your time budget for this course, but very
well-invested as you will find out during the course or
later.
Example
A program for insertion sort that is fully annotated according to the
coding convention is given on page 3 of the AD2 demo report which
also contains examples of all LaTeX2e commands you need for this
course.
Coding Convention and Checklist before submitting
The first two pages of the AD2 demo
report
contain a checklist that you must follow before submitting and the
coding convention that you must follow.
Demo Report
The main objective of the assignments is to exercise the theoretical
knowledge gained in the lectures, on carefully selected problems of
our choice. We are not just interested in sufficiently correct and
efficient programs, but also in explanations and a runtime analysis,
hence a report is also required for each assignment and its quality
has an impact on the score for your assignment.
See the demo
report
and LaTeX
source
for the imposed document structure and an indication of the expected
quality of content. Our expectations are higher than at the exam, as
the aims are to learn something and to prepare for the exam: we expect
at least a high degree of correctness, completeness, and
compliance with the coding convention of this course.
Exam
There is an individual, written, closed-book exam at the end of the
course.
One higher-education credit (ECTS credit) translates under Swedish
university law into an expected 26.67 hours of work for the average
student. Hence 133.33 hours are expected on this 5-credit course.
The exam is worth 3 credits. In addition to the exam preparation
performed while working (during 90 hours) for the 2 credits for the
assignments the remaining
preparation and the taking of the exam are expected to take 24 hours.
Recall that 19.5 hours are spent on the 13 lectures.
All this does not clash with other courses you are taking, as
university studies are legally defined to take 400 hours of work per
study period (normally 10 weeks), and the standard 15 credits targeted
in a study period are calibrated to reach that total.
Exam Grade
The exam grade is determined by a published scale depending on the exam
score.
Recommended exercises from the CLR3 book for exam preparation. Don’t
forget the book is available online at
the University library. All these exercises are from the third
edition. I don’t have the answers to the questions, and some of the
exercises are non-trivial but will give you a deeper understanding of
the material in book.
Chapter 15
15.1-2
15.1-3
15-2-2
15.4-1
15.4-2
15.4-3
Chapter 16
16.1-1
16.1-2
16.1-3
16.1-4
Chapter 21
21.3-1
Chapter 23
The exercises in this chapter are bit more theoretical than the
questions that I have on the exam, but you really should make sure
that you understand the material in the chapter.
Chapter 23, 26.1-26.2
Again the exercises in this chapter are bit more theoretical than the
questions that I have on the exam, but you really should make sure
that you understand the material section 26.1-26.2
Chapter 32
32.1-1
32.2-1
Grades and Credits
Assignments
The three assignments are worth 2 higher-education credits (ECTS
credits). The assignment grade is as follows when $a_i$ is your
final score (out of 10) on Assignment $i \in 1..3$, and $a = a_1 +
a_2 + a_3$ is your total score. Each assignment is
divided into two Problems with sub parts. On each of the problems you
must have a score of at least 1 (out of 5) to pass the course. If you have a 0 on
any of the two problems any assignment, then you will fail the
assignments.
You must earn at least 3 points (of 10) on each of the assignments.
Grade
Condition
5
$a \in \\{25\ldots 30\\}$
4
$a \in \\{20\ldots 24\\}$
3
$a \in \\{15\ldots 19\\}$
Exam
The exam is worth 3 higher-education credits (ECTS
credits). The exam is marked out of 20. The exam is constructed in
such a way to have no marks that are fractions of a point.
The following table
gives your grade assignment. Let $e$ be your total exam score:
Grade
Total Score
5
$e \in \\{17 \ldots 20\\}$
4
$e \in \\{14\ldots 16\\}$
3
$e \in \\{10\ldots 13\\}$
U
$e \in \\{0\ldots 9\\}$
Overall Grade
There is no longer a bonus point scheme combining the assignment and
the exam mark for the final grade. Your final grade is now your exam
grade. You are strongly encouraged to aim for a 5 on the
assignments. In the past there is a strong correlation between
students who got a 5 no the assignments and a 5 on the exam. There is
an overlap on material examined in the assignments and material
examined in the exam. Aiming for a 5 on the assignments is good
preparation for some of the exam.
Resources
Text Book
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and
Clifford Stein. Introduction to
Algorithms
(fourth edition) The MIT Press, 2022. This will be referred to as
CLRS4.
The second edition
errata or third can also
be used. The third edition will be referred to as CLRS3.
Note that it is now possible to access library resources online
without being on the University network or using a VPN. You will be
prompted for you CAS login. You need to go through the library search
system. For the fourth edition follow this
CLRS4
and for the third edition
follow this CLRS3.
Even when the book is available for free via the University library I
recommend that you buy the book. It is one of the best textbooks on
algorithms available.
At the moment most of the reading guides refer to the third edition,
but I will update the reading guide for the fourth edition as I go
along.
Reference Book
The following book, underlying most of the slides that have been used
in previous years, can also be used but does not cover Section 4.3 and
Chapters 21 and 32 of CLRS3:
Jon Kleinberg and Éva Tardos. Algorithm
Design
Addison-Wesley, 2006.
The learning of sufficient skills on the Python programming language
is within your time budget for this course, but this should not take
more than a couple hours. To the best of our knowledge, almost no
student on this course has officially learned Python at UU, so nobody
is at a disadvantage.
Python programming language:
official website; the skeleton codes for all the assignment problems
are written in Python 3.
LaTeX and Demo Report
We highly recommend you learn or use LaTeX for typesetting your
assignment reports in a professional way, but this is optional. The
learning of LaTeX is outside your time budget for this course, but
very well-invested as you will find out during the course or later.
Here are some LaTeX resources:
The demo
report
and LaTeX
source,
which also contain examples of all LaTeX commands you need for this
course.
Don’t know the LaTeX code for that mathematical symbol you need?
Draw it by hand at
Detexify, and the
applet will find the code for you.
clrscode3e
package for typesetting algorithms as in CLRS3.
Extra Slides for Revision
When Pierre Flener taught the
course he used slides by Kevin
Wayne. For some of the lectures I
use Kevin Wayne’s slides, but for lectures where I do not, you are
still encouraged to look at Kevin Wayne’s slides. They contain a
number of useful examples.
Before contacting anyone for help, please check whether your
question has an answer in the FAQ list below. If not:
If you have a question about the lecture material or course
organisation, then contact the head
teacher.
If you have a question about the assignments or
infrastructure, then contact the assistants at a help or solution
session for an immediate answer. Short clarification questions
(that is: not about programming issues) that are emailed to the AD2
helpdesk are answered as soon as possible
during working days and hours. No answer means that you should go to
a help session: almost all the assistants’ budgeted time is allocated
to grading and to the help, grading, and solution sessions.
Ethics Plagiarism
The legislation on plagiarism and
cheating
and Pierre Flener’s
summary of Uppsala
University will be rigorously applied, without exceptions. This
disallows using a public repository (such as GitHub), where you should
use a free private student
repository for code management.
We reserve the right to use plagiarism detection tools and point out
that they are extremely powerful.
Ethics The use of LLMs and Code Assistants
On this course you are not allowed to use LLMs or coding assistants
when doing your assignments. Explicitly: LLM coding assistants when
writing your code, and no use of generative AI for your report. You
are allowed to use tools such as grammar checkers to improve your
report. All the the work should be completely your own.
The only way to master material in the course is to think and
implement the solutions yourself. LLMs are useful only when you can
understand the code that they produce.
Frequently Asked Questions (FAQ) and Answers
How do I best use my time, and yours, in order to solve
an assignment? Prepare your solution as far as possible until
the corresponding help sessions, in order to make best use of that
reserved timespan of personal attention by the assistants. This is
much more effective than going to a help session, printing out the
assignment (which was published at least a week before the first help
session and often does not require any material taught in the
meantime), and not meeting all the difficulties until the end of the
two session hours.
Why is there not more email support for the assignments? We have
scheduled almost all the standard time budget for the lectures, help
sessions, grading sessions, solution sessions, grading, and
preparation. This is why we can only answer to emailed short
questions that trigger brief reply times, and this is a more personal
and rational way of spending the standard time budget: more email
support would inevitably result in fewer help sessions.
I am lost! Why do the assignment instructions not tell us how
to solve the questions? Stating only what output has to be
computed from the inputs is a pedagogical choice. In real-life
engineering problems, you are not asked to solve a problem by using
method m on page p of textbook t. Come to some of the help
sessions of an assignment in order to get advice on what is wrong with
your current solution or get hints on how to proceed.
Why are the assignment questions neither in sync with the lecture
contents, nor closer to them?
They are. The lecture schedule is carefully planned so that the
relevant material has been covered in time for you to start the
assignment. Quite often in a lecture I will work through a similar
problem to one of the assignment questions. Come to the lectures.
Why are the assignments to be programmed in Python rather than in
any language of my choice? We have no resources for offering
skeleton programs and simple test cases for more than one programming
language. A lot of students prefer those features over the freedom of
choice of a programming language. Besides, our semi-automated grading
system is language-specific for the same reason: it allows us to grade
assignments faster and to dedicate more of the standard time budget to
actual teaching.
Why do we need to hand in reports in addition to programs? This
is an algorithms course and the algorithms underlying your programs
have to be analysed, hence a report is needed, as we are not just
interested in knowing the complexity you claim your algorithm has, but
also in how you made that claim. Also note that this course was
chosen in order to fulfil the curriculum goal of the ability to
communicate in writing: see the course goals
Why do we not get more finegrained feedback on our assignment
reports and programs? Our solution sessions are a more rational way
to use the standard time budget: we give collective feedback instead
of finegrained team-wise feedback. More detailed comments can be
obtained orally from the assistants upon appointment.
Why do I need to spend so much time on the assignments when they
are only worth 2 credits? Any time spent on the assignments reduces
the amount of time needed to prepare for the exam, so it pays
off.
When will the exam be graded? It was a multiple-choice exam, so
why are “the” answers not published right away? The head teacher
will first read the starred comments, if any, about the questions in
the handed-in answer sheets and then only grade, as such comments may
affect his judgement about which answers can be acceptable with full
or partial credit. He will grade as soon as he finds the time after
getting the answer sheets. Please be patient.
Where are model answers to the questions of previous exams?
Nowhere, except for the multiple-choice exams. The head teacher does
not believe in making such answers available (on-line or otherwise)
without discussing solution processes or any alternative correct
answers in person at the same time. This is the pedagogical approach
taken also for the assignments, where you can contact the assistants
for this purpose.
Will there be algorithm design questions in the exam? Will exam
questions be similar to the assignment questions? Algorithmic
skills are mostly tested in the assignments. Any algorithms for exam
questions will be a handful lines long, but algorithm design
experience from the assignments ought to be useful for such exam
questions. Analytic skills tested in the assignments also ought to be
useful for exam questions.
Will we have multiple-choice exam questions? The head teacher
has the right for any form of examination and decides as he sees fit.
Note that a multiple-choice question saves you the time of tidying up
your answer notes explaining how you reached your chosen answer.
Further, if you think a question is unclear or wrong, then you are
free to explain on the answer sheet what your difficulty with the
question is and what assumption underlies the answer you have chosen
or the other answer you indicate. Also, partial credit can be given
to some answers in exceptional circumstances.
What will the exam questions be? What should I focus
on when preparing the exam? Try and come to the lectures, as
the head teacher makes it very clear there what the most important
elements of the course material are.
I nearly passed the exam. What can I do to avoid
taking the next exam? No make-up opportunities will be
created for near-passes, as the head teacher evaluates those cases
very carefully before announcing the exam results.
Why is there no bonus point scheme for the assignments and the
exam? There is no longer a bonus point scheme combining the
assignment and the exam mark for the final grade. Your final grade
is now your exam grade. You are strongly encouraged to aim for a 5
on the assignments. In the past there is a strong correlation
between students who got a 5 no the assignments and a 5 on the
exam. There is an overlap on material examined in the assignments
and material examined in the exam. Aiming for a 5 on the
assignments is good
preparation for some of the exam.