Skip to content

ualiurrahat/complete-data-structure-and-algorithms-using-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

261 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“˜ Complete Data Structures & Algorithms in C++

A comprehensive, well-structured, and actively maintained DSA reference repository β€” built from the ground up with clean code, educational comments, and multiple solution approaches.

Stars Forks Language License Status IEEE

⭐ If this repository helped you learn, please consider giving it a star β€” it keeps this project alive and helps others discover it!

πŸ“– About This Repository

This is a complete, structured, and ever-growing Data Structures and Algorithms reference repository written entirely in modern C++ (C++17). Every topic is organized from first principles β€” starting with the theoretical foundation, followed by clean implementations, and ending with curated problem sets ranging from easy to hard.

The goal is simple: build the strongest possible DSA foundation, whether you're preparing for technical interviews, competitive programming, university coursework, or simply want to understand how computers think at a fundamental level.

This repository covers over 260 files across 24+ topic folders β€” and is actively being expanded.


🎯 Who Is This For?

Audience How This Helps
πŸŽ“ CS / EEE Students Clear theory + implementation to complement university coursework
πŸ’Ό Interview Candidates Brute β†’ Better β†’ Optimal solution progressions mirror real interview thinking
πŸ† Competitive Programmers STL mastery, algorithmic patterns, and categorized problem sets
🌱 Beginners Step-by-step comments explaining not just what the code does, but why
πŸ”¬ Experienced Developers Clean, production-style code with time/space complexity analysis

✨ What Makes This Repository Different?

Most DSA repositories are just dumps of code. This one is different β€” it's designed to teach and demonstrate engineering quality at the same time.

  • βœ… Brute β†’ Better β†’ Optimal β€” Every non-trivial problem provides multiple solution approaches, progressing in efficiency
  • βœ… Complexity Analysis β€” Time and space complexity explained at the end of every function, not just stated
  • βœ… Doxygen-style Documentation β€” All functions documented with parameter descriptions and return values
  • βœ… Educational Comments β€” Line-by-line logic explanation inside functions, written for learning, not just reference
  • βœ… Industry-Standard Style β€” camelCase naming, logical section separators, clean headers β€” production-grade code habits
  • βœ… Problem Statements Included β€” Each file includes the problem it solves at the top, so the file is self-contained
  • βœ… STL Mastery Section β€” A dedicated deep-dive into the C++ Standard Template Library before any data structures
  • βœ… OS-Level Application β€” CPU scheduling algorithms implemented in C++ to connect DSA concepts to systems programming

πŸ—‚οΈ Repository Structure & Coverage

complete-data-structure-and-algorithms-using-cpp/
β”‚
β”œβ”€β”€ 00_STLC++/                          ← C++ STL: Vectors, Iterators, Algorithms, Pairs,
β”‚   β”œβ”€β”€ 01_Vector and Iterators/           Sets, Maps, Other Containers, and Applied STL
β”‚   β”œβ”€β”€ 02_STL Algorithms/
β”‚   β”œβ”€β”€ 03_Pair and Tuple/
β”‚   β”œβ”€β”€ 04_Sets/
β”‚   β”œβ”€β”€ 05_Maps/
β”‚   β”œβ”€β”€ 06_Other Containers/
β”‚   └── 07_Applying STLs/
β”‚
β”œβ”€β”€ 01_Pointers/                        ← Pointer basics, arithmetic, arrays, double pointers
β”œβ”€β”€ 02_Dynamic Memory Allocation/       ← Heap memory, references, static/global/const variables
β”œβ”€β”€ 03_Mathematics/                     ← GCD, primes, Sieve, power function, nCr, Fibonacci
β”œβ”€β”€ 04_Patterns/                        ← 19 classical pattern problems (loops & logic)
β”‚
β”œβ”€β”€ 05_Recursion/                       ← Basic β†’ Medium recursive problems
β”‚   β”œβ”€β”€ 01 Basic/                          (Factorial, binary search, palindrome, subsequences...)
β”‚   β”œβ”€β”€ 02 Easy/
β”‚   └── Medium/                            (Tower of Hanoi, phone keypad, subsequences)
β”‚
β”œβ”€β”€ 06_Strings/                         ← Easy β†’ Hard string problems
β”‚   β”œβ”€β”€ 01 Basic Problems/                 (Reverse, palindrome)
β”‚   β”œβ”€β”€ 02 Easy/                           (Roman numeral, pangram, anagram rotation)
β”‚   β”œβ”€β”€ 03 Medium/                         (Sliding window, large factorial, sorting vowels)
β”‚   └── 04 Hard/                           (KMP β€” LPS array, min chars to palindrome)
β”‚
β”œβ”€β”€ 07_Sorting Algorithms/              ← Selection, Bubble, Insertion, Quick, Merge,
β”‚                                          Count Sort, DNF, Wave Sort (recursive variants too)
β”‚
β”œβ”€β”€ 08_Arrays/                          ← 38 problems: Easy β†’ Hard
β”‚   β”œβ”€β”€ 01_Easy/                           (Rotation, sliding window, two pointers, prefix sum)
β”‚   β”œβ”€β”€ 02_Medium/                         (Kadane's, next permutation, spiral matrix, set zeros)
β”‚   └── 03_Hard/                           (Pascal's triangle, 3Sum, 4Sum, XOR subarrays, merge intervals)
β”‚
β”œβ”€β”€ 09_OOP/                             ← 41 files covering all OOP pillars in C++
β”‚                                          (Classes, constructors, operator overloading,
β”‚                                           inheritance, polymorphism, virtual functions,
β”‚                                           friend class/function, abstract classes)
β”‚
β”œβ”€β”€ 10_Binary Search/                   ← Binary search fundamentals
β”‚
β”œβ”€β”€ 11_Linked List/                     ← 33+ Singly LL + 6 Doubly LL + 6 Advanced problems
β”‚   β”œβ”€β”€ 01_Singly Linked List/             (Detect/remove cycles, merge K sorted, clone with random ptr)
β”‚   β”œβ”€β”€ 02_Doubly Linked List/
β”‚   └── 03_Others/                         (Circular LL, browser history design, flatten LL)
β”‚
β”œβ”€β”€ 12_Stacks/                          ← Stack implementations + Infix/Prefix/Postfix
β”‚   β”œβ”€β”€ 01 Learning/                       conversions + Monotonic Stack problems
β”‚   β”œβ”€β”€ 02 Prefix Infix Postfix/           (Trapping rain water, next greater element)
β”‚   └── 03 Monotonic Stack Problems/
β”‚
β”œβ”€β”€ 13_Queues/                          ← Queue theory, circular array, LL-based, STL, stack-queue
β”‚
β”œβ”€β”€ 14_Trees/                           ← General N-ary tree: traversals, height, depth, leaf count
β”‚
β”œβ”€β”€ 15_Binary Tree/                     ← 43 problems on binary trees
β”‚                                          (All traversals iterative + recursive, diameter, LCA,
β”‚                                           burn tree, Morris traversal, serialize/deserialize)
β”‚
β”œβ”€β”€ 16_Binary Search Trees/             ← 18 BST problems
β”‚                                          (Insert/delete, ceil/floor, LCA, recover BST, BST iterator)
β”‚
β”œβ”€β”€ 18_Graph Data Structure/            ← Graph intro, BFS, DFS (connected + disconnected graphs)
β”‚
β”œβ”€β”€ 19_Hashmap/                         ← Hashmap internals: bucket array, hash codes,
β”‚                                          collision handling, custom hashmap class
β”‚
β”œβ”€β”€ 20_Priority Queue And Heaps/        ← Heap theory, min-PQ, heapify, heap sort,
β”‚                                          Kth smallest/largest element
β”‚
β”œβ”€β”€ 21_Bit Manipulation/                ← 19 problems: set/clear/toggle bits, XOR tricks,
β”‚                                          power set, single number variants
β”‚
β”œβ”€β”€ 22_Sliding Window & 2 Pointers/    ← Max points from cards, longest unique substring
β”‚
β”œβ”€β”€ 23_Operating System Problems/       ← FCFS, SJF, Priority (preemptive + non-preemptive),
β”‚                                          Round Robin scheduling algorithms in C++
β”‚
└── 24_Greedy Algorithm Problems/       ← Easy: coins, cookies, lemonade change
    β”œβ”€β”€ 01 Easy/                           Medium: jump game, job scheduling, meeting rooms
    └── 02 Medium/

πŸ—ΊοΈ Roadmap β€” What's Coming Next

This repository is actively maintained and being expanded. Here's what's planned:

Topic Status
βœ… STL, Pointers, OOP, Mathematics Complete
βœ… Recursion, Strings, Sorting Complete
βœ… Arrays (Easy β†’ Hard) Complete
βœ… Linked List (Singly, Doubly, Circular) Complete
βœ… Stacks, Queues, Trees, Binary Trees, BST Complete
βœ… Graphs (BFS/DFS basics) Partial
βœ… Hashmap, Heaps, Bit Manipulation Complete
βœ… Sliding Window, Greedy, OS Scheduling Partial
πŸ”„ Graph Algorithms (Dijkstra, Bellman-Ford, Floyd-Warshall, Prim's, Kruskal's, Topological Sort) In Progress
πŸ”„ Dynamic Programming (0/1 Knapsack, LCS, LIS, Matrix Chain, DP on Trees) Coming Soon
πŸ”„ Backtracking (N-Queens, Sudoku, Rat in Maze, Word Search) Coming Soon
πŸ”„ Trie (Insert, Search, Word prefix, Auto-complete) Coming Soon
πŸ”„ Segment Trees & Fenwick Trees Coming Soon
πŸ”„ Disjoint Set Union (DSU) Coming Soon
πŸ”„ Advanced Graph (SCC, Bridges, Articulation Points) Planned

πŸ“Œ Watch / Star this repo to get notified as new content is added!


πŸ—οΈ Code Quality Standards

Every file in this repository follows a consistent, professional coding standard:

/*
 * ============================================================
 * File    : exampleProblem.cpp
 * Topic   : Arrays
 * Problem : Find the maximum subarray sum (Kadane's Algorithm)
 * ============================================================
 */

#include <iostream>
#include <vector>
#include <climits>
using namespace std;

/**
 * @brief  Brute force approach β€” check all subarrays
 * @param  arr  Input integer array
 * @return Maximum subarray sum
 *
 * Time Complexity : O(n^2) β€” two nested loops over the array
 * Space Complexity: O(1)  β€” no extra space used
 */
int maxSubarraySumBrute(const vector<int>& arr) {
    int maxSum = INT_MIN;

    // Iterate over all possible starting points
    for (int i = 0; i < arr.size(); i++) {
        int currentSum = 0;

        // Expand subarray from index i
        for (int j = i; j < arr.size(); j++) {
            currentSum += arr[j];
            maxSum = max(maxSum, currentSum);
        }
    }
    return maxSum;
}

/**
 * @brief  Optimal approach β€” Kadane's Algorithm
 * @param  arr  Input integer array
 * @return Maximum subarray sum
 *
 * Time Complexity : O(n) β€” single pass through the array
 * Space Complexity: O(1) β€” constant space
 */
int maxSubarraySumOptimal(const vector<int>& arr) {
    int maxSum     = INT_MIN;
    int currentSum = 0;

    for (int num : arr) {
        currentSum += num;
        maxSum      = max(maxSum, currentSum);

        // Reset if current sum drops below zero β€” fresh start is better
        if (currentSum < 0) currentSum = 0;
    }
    return maxSum;
}

πŸš€ How to Use This Repository

Clone the Repository

git clone https://github.com/ualiurrahat/complete-data-structure-and-algorithms-using-cpp.git
cd complete-data-structure-and-algorithms-using-cpp

Compile and Run Any File

# Using g++ (recommended: C++17)
g++ -std=c++17 -o output filename.cpp
./output

Recommended Learning Path

Beginner Path:
  03_Mathematics β†’ 04_Patterns β†’ 05_Recursion β†’ 06_Strings β†’ 08_Arrays

Intermediate Path:
  07_Sorting β†’ 11_Linked List β†’ 12_Stacks β†’ 13_Queues β†’ 14_Trees β†’ 15_Binary Tree

Advanced Path:
  16_BST β†’ 18_Graphs β†’ 20_Heaps β†’ 21_Bit Manipulation β†’ 22_Sliding Window β†’ 24_Greedy

Foundation (Parallel):
  00_STL β†’ 01_Pointers β†’ 02_Dynamic Memory β†’ 09_OOP

Recommended Setup

  • IDE: VS Code with C/C++ Extension Pack
  • Compiler: GCC / MinGW (Windows) or g++ (Linux/macOS)
  • Standard: C++17 or later (-std=c++17)

πŸ“Š Topics At a Glance

# Topic Files Difficulty Range
00 C++ STL (Vectors, Maps, Sets, Algorithms...) 35+ Beginner β†’ Intermediate
01 Pointers 7 Beginner
02 Dynamic Memory Allocation 9 Beginner β†’ Intermediate
03 Mathematics 16 Easy β†’ Medium
04 Pattern Problems 19 Easy
05 Recursion 25+ Easy β†’ Medium
06 Strings 19 Easy β†’ Hard
07 Sorting Algorithms 10 Easy β†’ Medium
08 Arrays 38 Easy β†’ Hard
09 Object-Oriented Programming 41 Intermediate β†’ Advanced
10 Binary Search 1 Easy
11 Linked Lists (Singly, Doubly, Circular) 45+ Easy β†’ Hard
12 Stacks (+ Expression Conversions + Monotonic) 15 Easy β†’ Hard
13 Queues 6 Easy β†’ Medium
14 Trees (N-ary) 17 Easy β†’ Medium
15 Binary Trees 43 Easy β†’ Hard
16 Binary Search Trees 18 Medium β†’ Hard
18 Graph Data Structure 7 Medium
19 Hashmap (Theory + Custom Implementation) 9 Medium β†’ Advanced
20 Priority Queue & Heaps 9 Medium β†’ Hard
21 Bit Manipulation 19 Easy β†’ Hard
22 Sliding Window & Two Pointers 2 Medium
23 OS CPU Scheduling Algorithms 6 Applied
24 Greedy Algorithms 9 Easy β†’ Medium

Total: 260+ files Β· 24 topic modules Β· Actively growing


πŸ‘€ About the Author

Md. Ualiur Rahman Rahat
Completed B.Sc. Engineering in Electrical & Electronic Engineering from Gopalganj Science and Technology University.
Pursuing Bachelors of Science in Computer Science from University of the People.

I'm an EEE graduate with a deep passion for software engineering and systems-level programming. I built this repository to document my journey through Data Structures & Algorithms with the rigor I wish I had found in a single place β€” clean code, real explanations, and honest progression from brute force to optimal.

Beyond DSA, I've worked in embedded systems and published research at the IEEE ICRPSET 2024 international conference:

πŸ“„ "Advanced Hybrid Algorithms for High-Efficiency Image Compression in Satellite and Drone Systems"

I believe the best way to truly master something is to teach it β€” and this repository is my effort to teach DSA, one well-commented file at a time.

GitHub LinkedIn

πŸ“„ License

This repository is licensed under the MIT License β€” free to use, share, and build upon with attribution.


⭐ Found this helpful? Star the repo β€” it takes 2 seconds and means a lot.

Made with consistency, curiosity, and a lot of g++ commands.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages