Competitive Programming Roadmap

Competitive Programming Roadmap

in

Contents :

Section 0 : Introduction Section 1 : Basic Theory Section 2 : Intermediate Section 3 : Advanced
Introduction Number Theory Advanced Maths String Hashing
Getting Started Two Pointers / Sliding Windows Range Update Queries Directed Graphs
basic prob solving Range Queries Graph Theory Basics Range Update
Time Complexity Divide and Conquer DSU + MST Sparse Table
Intro To STL Intro to Greedy Algorithms Shortest path Tree Algorithm
Sorting Dynamic Programming
Binary Search Interactive Problems
Bit Operations
Number Theory
Recursion
Complete Search

Section 0: Introduction :

SECTION 0 part 2
SECTION 0 part 1

What is CP and Why do it?

➡️Getting Started

Learn C++ :

Setting Up Environment :

We prefer VS CODE because of obvious reasons :eyes: , still feel free to use any other usable Code Editor like : sublime text , codeblocks , etc.

➡️Basic Problem Solving

Fast I/O (optional for now):

What it is :

Try this problem with Fast I/O :

Basic Math Problems


Some suggestions from the Makers :


➡️Time Complexity

:star: Expected time : 40 - 50 minutes

Solve these in O(n) :

➡️Intro to STL

:star: Expected time : 40 - 60 minutes

Basic Array / Vectors Problems

Basic String Problems

➡️Sorting

:star: Expected time : 2 - 2.5 hours

More on STL

:star: Expected time : 40 - 60 minutes

Each Data Structure in STL has its own strengths and weaknesses. Try to think what to use according to the problems.

:star: Expected time : 40 - 60 minutes

➡️Bit Operations

:star: Expected time : 1 - 1.5 hours

➡️Primary Number Theory

:star: Expected time : 1 - 1.5 hours

Binary Exponentiation

:star: Expected time : 20 - 30 minutes

Factorisation [till O(rootN)]

:star: Expected time : 20 - 30 minutes

Gcd

:star: Expected time : 20 - 30 minutes

➡️Recursion

:star: Expected time : 1.5 - 2 hours

:star: Expected time : 1.5 - 2 hours

By now, you may have realized that debugging your code efficiently is very important. For a few tips on debugging, you can go through this article / this video.

➡️Section 0 Additional Practice:

Section 1: Basic Theory

SECTION 1

➡️Number Theory

Number Sieve

:star: Expected time : 1 - 1.5 hours

Modular Multiplicative Inverse

:star: Expected time : 20 - 30 minutes

Additional Practice :

Hint

In essence, you need to apply the permutation U = (1, 3, 5 … N - 1, 2 , 4 …. N) to your initial array K times which is the same as composing f with You can use binary exponentiation). :::

➡️Two Pointers / Sliding Windows

:star: Expected time : 30 - 40 minutes

➡️Range Queries

Prefix Sums are Intensively Used in other problems to reduce Time Complexity of Solution.

:star: Expected time : 40 - 50 minutes

Additional Practice

➡️Divide and Conquer

:star: Expected time : 20 - 30 minutes

Read this to know what divide and conquer is. Watch this video to get more insight into this topic

➡️Intro to Greedy Algorithms

:star: Expected time : 1.5 - 2 hours

Moving in the direction which gives the most optimal solution at every step is a major characteristic of these algorithms.

Here are some questions :

SELF ASSESSMENT :

➡️Dynamic Programming

Basic Concepts :

Dynamic Programming , more famously known as DP is a technique in which we calculate and store subproblems in a particular problem.

There are two methods to apply dp in your code : recursion and iteration .

:star: Expected time : 1.5 - 2 hours

DP on Grids :

This tutorial has some generic problems which will develop your understanding about grids .

DP Bitmask :

:star: Expected time : 1.5 - 2 hours

DP is a topic which can be mastered only through practice.

SELF-ASSESSMENT ( Topic : DP )

Extra

There exist both dp and math based solutions , the math solution can be found if you know about recursive relations and how to find their solutions using quadratic equations , this solution has a time complexity of O(log(n)) and uses binary exponentiation

Extra

There are two dp solutions one having O(n) time complexity and the other being O(n^2) .. which one were you able to spot

➡️Interactive Problems

:star: Expected time : 15 - 20 minutes

Here is a tutorial on how to solve interactive problems .

Here are some questions :

Some more tools to help you in your journey :

CodeForces Chrome Extensions :

➡️Section 1 Additional Practice:

Section 2: Intermediate

SECTION 2

➡️Advanced Maths

:maple_leaf: Combinatorics

:star: Expected time : 15 - 20 minutes

:maple_leaf: Matrices

:star: Expected time : 1 - 1.5 hours

:maple_leaf: Probability

:star: Expected time : 1 - 1.5 hours

:maple_leaf: Extra Number Theory

:star: Expected time : 1 - 1.5 hours

➡️Range Update Queries

:star: Expected time : 1.5 - 2 hours

➡️Graph Theory Basics

:star:Expected time : 40 - 60 minutes

:maple_leaf: BFS and DFS

:star: Expected time : 30 - 40 minutes

:maple_leaf: Cycles Detection

:star: Expected time : 20 - 30 minutes

:maple_leaf: Bridges in Graphs

:star: Expected time : 30 - 40 minutes

:maple_leaf: Flood Fill

:star: Expected time : 15 - 20 minutes

:maple_leaf: Topological Sort

Sorting nodes of a directed graph in an order in which they can appear in a path.

Note : we can only find topological sorting for an acyclic directed graph.

:star: Expected time : 40 - 60 minutes

Number of topological sortings for a directed tree is discussed in Section 3 Tree Algorithms : :maple_leaf: DP on Trees

:maple_leaf: Subtree/DFS Problems

➡️DSU + MST

Disjoint Set Union

:star: Expected time : 1.5 - 2 hours

Minimum Spanning Trees

:star: Expected time : 1 - 1.5 hours

  1. PAPS Section 12.4
  2. How Do You Calculate a Minimum Spanning Tree?
  3. CPH OR
  4. Read these articles : Kruskal , Kruskal DSU , Prim's Algo OR
  5. Go through these videos : Kruskal using DSU , Prim's Algo

➡️Shortest Path Algorithms - Dijkstra, Floyd Warshall, Bellman Ford

:star: Expected time : 1 - 1.5 hours

➡️Section 2 Additional Practice:

Optional :

Section 3: Advanced

SECTION 3

➡️String Hashing

:star: Expected time : 2 - 2.5 hours

➡️Directed Graphs

:star: Expected time : 1.5 - 2 hours

:maple_leaf: Cycles in Directed graphs

Functional Graphs

:maple_leaf: Strongly Connected Components :

A part of graph (component) is said to be strongly connected if there is a path from any node to all other nodes in the component.

In Function Graphs : Every cycle alone is a SCC;

Generally : if two cycles share a vertex they both come under the same SCC.

If you make disjoint sets of vertices within a SCC and join edges connecting SCCs; you get a Condensation Graph. This graph does not contain cycles as in that case they would form another SCC. Thus it's a Directed Acyclic Graph.

:maple_leaf: 2-SAT

:maple_leaf: DP on DAGs

DAGs stands for Directed Acyclic Graphs, Trees are a particular kind of DAG.

  1. Try this simple problem to start with :
  1. Then read CPH 16.2 and DP on Trees and Graphs | CSE 421
  2. If you prefer to watch some videos :
  3. Problems :
  4. DP on Trees

➡️Range Update Queries (continued)

:star: Expected time : 1.5 - 2 hours

This topic is continued from the previous section.

:maple_leaf: Additional (optional) :

➡️ Sparse Table

:star: Expected time : 1 - 1.5 hours

➡️Tree Algorithm Problems

:star: Expected time : 2 - 2.5 hours

:maple_leaf: Tree Diameter

:maple_leaf: DP on Trees

(this section builds on from DP on DAGs)

:maple_leaf: Tree Queries

➡️Section 3 Additional Practice:

Additional Topics

Convex Hull Trick, Square Root Decomposition, DP Optimizations (Knuth, Aliens, Divide and Conquer, CHT), LiChao Tree, Mo’s Algorithm, Digit DP, Broken Profile DP, Connected Components DP, DP on Trees, Sparse Segment Trees, Persistent Data Structures, Slope Trick, FFT, Suffix Array, Tries, Heavy Light Decomposition, Centroid Decomposition

NOTE : For the topics we covered above there still exist a lot of variations which might be missed out by us or were not possible in the scope of this Roadmap.

Continue your jouney in CP with self exploration !

➡️ Some More Resources -

Books -

Problem Sets and Resources -

Blogs -

YouTube Channels and Playlists -


This roadmap could never be possible without the inspiration and background support of the Makers of the Previous Roadmap :

Contributors -
Tattwa Shiwani | tattwash23@iitk.ac.in
Khushi Ranawat | rkhushi23@iitk.ac.in
Arnav Gupta | arnavgupta23@iitk.ac.in
Yatharth Dangi | yatharth23@iitk.ac.in
Rohit Somani | rohitvs23@iitk.ac.in