Skip to content

Insights and solutions of the problems and topics covered in Algorithms Lab HS2024 held at ETH Zurich

License

Notifications You must be signed in to change notification settings

tommasocerruti/algolab-2024

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Algolab 2024

Table of Contents

  1. Introduction
  2. What is this course about?
  3. How is it erogated?
  4. Outline
  5. My Perspective
  6. What Will You Find in This Repo?
  7. Solutions per Week
  8. Solutions per Topic
  9. General Advices
  10. My Notes
  11. How to Compile or Run
  12. Disclaimer on Problem Statements
  13. Credits
  14. License

Introduction

This repository contains my personal solutions and explanations for the Algorithms Lab (Algolab 2024). The course is taught in a style similar to the International Olympiad in Informatics (IOI), focusing on solving algorithmic problems from textual and story-like descriptions.


What is this course about?

The main objective of the course is to learn how to solve algorithmic problems that require:

  • Dynamic Programming (DP)
  • Greedy Algorithms
  • Basic Graph Algorithms (MST, Shortest Path, Matching, etc.)
  • Flow Graph Algorithms (MaxFlow, MinCut, MinCostMaxFlow, etc.)
  • Geometry (Delaunay triangulations, advanced computational geometry)
  • Linear Programming (LP)
  • and more!

Over time, the level of difficulty ramps up—toward the end, you must determine which strategy (Greedy, DP, LP, MaxFlow, etc.) is most efficient.


How is it erogated?

  • Weekly Format:
    Each week, there are 4 problems closely related to the topic introduced that week. Additionally, there is a Problem of the Week (POW) that simulates exam conditions (limited time, hidden tests, etc.).

  • From Week 10:
    The final four weeks present more challenging problems where it’s not just about coding a known algorithm but also figuring out which approach is correct.


Outline

Outline


My Perspective

This course was very fun and interesting, and it boosted my problem-solving skills significantly. It also helped me improve coding-interview skills.
However, if you do not have a competitive programming background (as in my case), be prepared to work very hard. I personally put in about three times the usual effort for an 8-ECTS course.
Of course, this can vary from person to person, but I believe doing all the exercises and understanding deeply the solutions should be enough for passing the exam, regardless of the background you come from.


What Will You Find in This Repo?

  1. Solutions per Week: Organized by weekly assignments, including the POW.
  2. Solutions per Topic: Organized by theme (DP, MST, Flow, etc.).
  3. General Advices: Tips for tackling problems and structuring your code.
  4. My Notes: Personal takes on topics like DP, geometry, network flow, etc.

For each problem, there is:

  • solution.cpp: The fully working code always scoring 100/100 points.
  • explanation.md: A verbose explanation of my reasoning and approach.

Solutions per Week

Week POW Problem 1 Problem 2 Problem 3 Problem 4
Week 1 None Dominoes Even pairs Even matrices Build the Sum
Week 2 POW 2: Deck of cards Beach bars Burning coins Defensive line The great game
Week 3 POW 3: James Bond’s sovereign First steps with BGL Buddy Selection Ant Challenge Important Bridges
Week 4 POW 4: The Iron Islands Hit First Hit Antenna Hiking Maps
Week 5 POW 5: Tracking Moving Books Asterix the Gaul Severus Snape Boats
Week 6 POW 6: Motorcycles Tiles Coin Tossing Tournament Knights Kingdom Defense
Week 7 POW 7: Octopussy Bistro H1N1 Germs Clues
Week 8 POW 8: Attack on King's Landing Maximize it! Diet Inball Casterly Rock
Week 9 POW 9: Idefix Placing Knights Real Estate Market Canteen Algocoon
Week 10 POW 10: Hermione Granger Asterix and the Tour of Gaul Rubeus Hagrid San Francisco The Hand’s Tourney
Week 11 POW 11: Ceryneian Hind Asterix in Switzerland Lernaean Hydra Sith Wordcup
Week 12 POW 12: Pied Piper Alastor Moody Nemean Lion Rapunzel Return of the Jedi
Week 13 POW 13: Schneewittchen Asterix and the Chariot Race Car Sharing Fighting Pits of Meereen Suez
Week 14 POW 14: Ludo Bagman - - - -

Solutions per Topic

Topic Problems
INTRO Build the Sum
PREFIX Even pairs, Even matrices
DP Burning coins, Defensive line, The great game, San Francisco, Lernaean Hydra, POW 12: Pied Piper, Asterix and the Chariot Race, Fighting Pits of Meereen
SW POW 2: Deck of cards, Beach bars
SP First steps with BGL, Ant Challenge, POW 5: Tracking, POW 8: Attack on King's Landing, Alastor Moody, Return of the Jedi
MST First steps with BGL, Ant Challenge, Return of the Jedi
MM Buddy Selection, Tiles, POW 8: Attack on King's Landing
SCC Important Bridges
GC Hit, First Hit, Antenna, Hiking Maps, POW 6: Motorcycles
GREEDY Moving Books, Boats, POW 7: Octopussy, Rubeus Hagrid
S. & L. Asterix the Gaul
GREEDP Severus Snape
MF Coin Tossing Tournament, Knights, Kingdom Defense, Placing Knights, Algocoon, POW 11: Ceryneian Hind, Asterix in Switzerland, Alastor Moody
MCMF Real Estate Market, Canteen, Asterix and the Tour of Gaul, Car Sharing, POW 14: Ludo Bagman
LP Maximize it!, Diet, Inball, Casterly Rock, POW 10: Hermione Granger, Wordcup, POW 13: Schneewittchen, Suez
UF POW 9: Idefix, The Hand’s Tourney, Sith
TRI Bistro, H1N1, Germs, Clues, POW 10: Hermione Granger, Nemean Lion
SW+ POW 4: The Iron Islands, Rapunzel
MC Algocoon, POW 11: Ceryneian Hind

Legend:
DP = Dynamic Programming | SW = Sliding Window | SP = Shortest Paths | MST = Minimum Spanning Tree | MM = Maximum Matching | SCC = Strongly Connected Components | GC = Computational Geometry |
GREEDY = Greedy Algorithms | S. & L. = Split and List | GREEDP = Greedy + DP | MF = Maximum Flow | MCMF = Min Cost Max Flow | LP = Linear Programming | UF = Union-Find | TRI = Triangulation | SW+ = Sliding Window + More | MC = Min-Cut


General Advices

  1. Keep a Standard Template

    #include <bits/stdc++.h>
    using namespace std;
    // Additional typedefs, CGAL/BGL libraries, etc.
    
    void solve() {
        // The function containing the main logic of your solution
    }
    
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        int t; cin >> t;
        while(t--) solve();
        return 0;
    }

    This lets you minimize repetitive code.

  2. Practice with POWs
    Each weekly POW is a great way to simulate the exam. Work on your time management and get comfortable with partial points.

  3. Get Familiar with BGL and CGAL
    They may look intimidating initially, but you have code snippets and the full documentation available at the exam. Make sure you know how to read official docs for extra features not covered in the snippets.

  4. Partial Points
    Don’t be afraid to go for partial solutions. Some test sets are easier and can give you a good chunk of points even if you don’t have the complete solution.

  5. Explore Additional Repositories
    If you finish early, there are many repos of previous years containing extra practice problems (however due to the high volume of the exercises it's likely you will not have the time to do them).


My Notes


How to Compile or Run

All solutions in this repository use C++ (usually C++17 or above). You can compile with any modern C++ compiler:

# Example: compile and run Dominoes problem from Week 1
cd src/week01/dominoes
g++ -std=c++17 solution.cpp -o dominoes
./dominoes < input.txt

Make sure you have installed BGL and CGAL correctly installed on your system.


Disclaimer on Problem Statements

We are not allowed to share the official problem statements for each exercise. Therefore, the texts are not included in this repository. The solutions here refer to those statements, but I often included a quick summary or personal interpretation. If you want to solve these problems independently, please see the official course materials or other official references.


Credits

Algolab is a challenging course without always providing official solutions. The following repositories (and their authors) helped me a lot to come up with these solutions:

A huge thanks to them for sharing their work!


License

This project is licensed under the MIT License — see the LICENSE file for details.


Enjoy this fun course and Good Luck!
Whatever your starting point, you can do it.

Outline

-- Prof. John Ousterhout, Stanford University

About

Insights and solutions of the problems and topics covered in Algorithms Lab HS2024 held at ETH Zurich

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages