Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSES Introductory Problems in C++

Optimal solutions with algorithmic insights and complexity analysis

C++17 • Algorithms • Competitive Programming • Problem Solving


Table of Contents


Overview

This repository contains my solutions to the CSES Introductory Problems implemented in modern C++17.

Rather than serving as a simple collection of accepted solutions, the repository is designed as a structured study of algorithmic problem solving. Every solution emphasizes the underlying algorithmic idea, mathematical reasoning, implementation strategy, and complexity analysis.

The objective is to develop a deeper understanding of classical algorithms, combinatorial reasoning, mathematical observations, and problem-solving techniques commonly encountered in competitive programming, technical interviews, and algorithmic research.


Repository Philosophy

The purpose of this repository is not only to provide accepted solutions to the CSES Problem Set, but also to document the reasoning process behind each algorithm.

Rather than focusing solely on implementation, every problem is approached as a learning opportunity, emphasizing the algorithmic intuition, mathematical foundations, and complexity analysis that lead to an optimal solution.

Each solution follows a consistent methodology:

  • Understanding the problem
  • Identifying the core idea
  • Designing the algorithm
  • Explaining the mathematical insight
  • Analyzing time and memory complexity
  • Producing a clean and efficient implementation

Features

  • Clean and optimized C++17 implementations
  • Algorithmic explanation for every problem
  • Core Idea for each solution
  • Algorithm Template
  • Mathematical / Algorithmic Insight
  • Time and Memory Complexity analysis
  • Competitive programming best practices
  • Incrementally expanding collection of solutions
  • Individual Markdown summaries for every solved problem

Study Methodology

Each problem is analyzed using the same structured methodology.

1. Problem Understanding

Understand the statement and identify the exact computational task.

2. Core Idea

Identify the key observation that leads to an optimal solution.

3. Algorithm Design

Design the algorithm before implementation.

4. Mathematical Insight

Explain the mathematical reasoning whenever applicable.

5. Complexity Analysis

Analyze both time and memory complexity.

6. Implementation

Produce a clean, readable and efficient C++ implementation.


Techniques Covered

As the repository grows, it covers a wide range of classical algorithmic techniques, including

  • Simulation
  • Greedy Algorithms
  • Constructive Algorithms
  • Mathematics
  • Combinatorics
  • Number Theory
  • Pattern Recognition
  • Backtracking
  • Breadth-First Search (BFS)
  • Divide and Conquer
  • Frequency Counting
  • Modular Arithmetic

Repository Statistics

Documentation

  • One summary for every solved problem

Language Standard

  • ISO C++17

Every solution includes

  • Core Idea
  • Algorithm Template
  • Key Idea
  • Mathematical / Algorithmic Insight
  • Time Complexity
  • Memory Complexity

Repository Structure

cses-introductory-problems-cpp/
│
├── summaries/
│   ├── apple_division.md
│   ├── bit_strings.md
│   ├── ...
│   └── weird_algorithm.md
│
├── src/
│   ├── apple_division.cpp
│   ├── bit_strings.cpp
│   ├── ...
│   └── weird_algorithm.cpp
│
├── README.md
├── LICENSE
└── .gitignore

Running a Solution

Requirements

  • C++17 compatible compiler

Compile

g++ -std=c++17 -O2 bit_strings.cpp

Run

./a.out

The same procedure applies to every solution contained in the repository.


Problem Summaries

Every solved problem is accompanied by a dedicated Markdown summary that explains the underlying algorithm, mathematical intuition, and complexity analysis.

Each summary includes:

  • Problem
  • Problem Type
  • Core Idea
  • Algorithm Template
  • Key Idea
  • Common Mistakes
  • Time Complexity
  • Memory Complexity
  • Reference Implementation

Use the table below to open the summary for any solved problem.

Problem Technique Summary
Weird Algorithm Simulation View
Missing Number Mathematics View
Repetitions Linear Traversal View
Increasing Array Greedy View
Permutations Constructive Algorithm View
Number Spiral Mathematics View
Two Knights Combinatorics View
Two Sets Constructive Algorithm View
Bit Strings Combinatorics View
Trailing Zeros Number Theory View
Coin Piles Mathematical Observation View
Palindrome Reorder Frequency Counting View
Gray Code Constructive Algorithm View
Tower of Hanoi Recursion View
Creating Strings Backtracking View
Apple Division Backtracking View
Chessboard and Queens Backtracking View
Digit Queries Mathematical Observation View
String Reorder Greedy View
Grid Coloring I Greedy View
Mex Grid Construction Constructive Algorithm View
Knight Moves Grid Breadth-First Search (BFS) View
Raab Game I Constructive Algorithm View
Grid Paths Description Backtracking View

Progress

Introductory Problems

  • Weird Algorithm
  • Missing Number
  • Repetitions
  • Increasing Array
  • Permutations
  • Number Spiral
  • Two Knights
  • Two Sets
  • Bit Strings
  • Trailing Zeros
  • Coin Piles
  • Palindrome Reorder
  • Gray Code
  • Tower of Hanoi
  • Creating Strings
  • Apple Division
  • Chessboard and Queens
  • Raab Game I
  • Mex Grid Construction
  • Knight Moves Grid
  • Grid Coloring I
  • Digit Queries
  • String Reorder
  • Grid Paths Description

The repository is continuously updated as additional problems from the CSES Problem Set are solved and analyzed.


References

  • CSES Problem Sethttps://cses.fi/problemset/
  • Steven Halim et al., Competitive Programming
  • Thomas H. Cormen et al., Introduction to Algorithms (CLRS)
  • Donald E. Knuth, The Art of Computer Programming

License

This project is licensed under the MIT License.


Maintained by Anastasis Zachariou

About

Clean C++17 solutions to the CSES Introductory Problems.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages