Skip to content
dhruvwarriorrPublic

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Dhruv's Competitive Programming & DSA Library

A topic-wise C++ library of core algorithms, data structures and templates for competitive programming (Codeforces, CodeChef, AtCoder) and coding interviews. Every implementation is a standalone, runnable file with a matching theory note.


CI C++ Version Implementations Notes


โœจ What's Inside

  • 74 runnable C++ implementations across arrays, number theory, binary search, sorting, bit tricks, graphs, trees and range-query structures.
  • A theory note for every implementation: when to use it, complexity, the core idea and the classic pitfalls.
  • Contest cheatsheets: full STL reference, math formulas, modular arithmetic, combinatorics, probability, and a page of quick CP facts.
  • Generic templates (Segment Tree, Lazy Segment Tree, Sparse Table) where you only change Node / Update per problem.
  • Verified: CI compiles every file and checks that every link and code fence in the docs is valid.

๐Ÿงญ Where to Start

I want to... Go to
Copy a starting template 8_misc/1_boilerplate.cpp
Remember an STL call STL Cheatsheet
Look up a formula or identity Math Formulas ยท CP Facts
Do range queries fast Prefix Sum โ†’ Fenwick โ†’ Segment Tree
Solve a shortest-path problem Dijkstra ยท Bellman-Ford ยท Floyd-Warshall
Answer $\binom{n}{r} \bmod p$ Optimised nCr

๐Ÿ“š Theory & Cheatsheets

All conceptual notes, proofs and formula sheets live under 0_theory/. The layout mirrors the code folders, so 2_math/11_binary_exponentiation.cpp is explained in 0_theory/2_math/11_binary_exponentiation.md.

๐Ÿ“– Algorithm-Specific Guides

Subject / Topic Core Concepts Covered
๐Ÿ“ฆ Arrays & Range Queries Prefix sums, 2D prefix sums, suffix sums, difference arrays, subarray sum, two pointers, sliding window, Kadane
๐Ÿ”ข Mathematics & Number Theory Sieve, smallest prime factor, factorization, divisors, factorials, nCr, Legendre's formula, binary exponentiation, Euler's totient, extended GCD
๐Ÿ” Binary Search Standard search, lower/upper bound, binary search on the answer (integer and decimal)
๐Ÿ”€ Sorting Algorithms Merge sort (divide & conquer), quick sort (partitioning & pivot choice)
โšก Bit Manipulation Bit tricks, set/unset bit positions, subset enumeration, bitset and bitset subset-sum
๐Ÿ•ธ๏ธ Graph Algorithms DFS, BFS, Dijkstra, bipartite check, DSU, Kruskal, cycle detection, topological sort, SCC, Bellman-Ford, Floyd-Warshall, Tarjan bridges, DP on DAG
๐ŸŒฒ Trees Parent / children / subtree size, height, diameter, ancestor query, binary lifting + LCA, Euler tour flattening
๐Ÿงฑ Segment Trees & Fenwick Generic segment tree, lazy propagation, Fenwick tree (BIT)
๐Ÿ› ๏ธ Miscellaneous & Templates Fast I/O + PBDS, sort map by values, matrix rotation, sparse table, full STL cheatsheet

๐Ÿ“ Conceptual Math & Reference Sheets

Subject / Topic Core Concepts Covered
๐Ÿ“ Mathematics Formulas Arithmetic, algebraic, geometric, volume and perimeter formulas
๐Ÿ“ Coordinate Geometry Midpoints, distances, triangle area via coordinates
๐Ÿชต Logarithms Logarithmic identities, change of base, digit-counting tricks
๐ŸŽฒ Combinatorics Permutations, combinations, circular arrangements, Stars & Bars
๐Ÿ“ˆ Probability Axioms, conditional probability, expected value, linearity
๐Ÿ”ข Modular Arithmetic Modular add/sub/mul/div rules, modular inverse
โšก Fermat's Little Theorem Statement, modular inverse via binary exponentiation, template
๐Ÿงฎ GCD & LCM Euclidean algorithm, LCMโ€“GCD relation, GCD/LCM properties
๐Ÿ“ Divisibility Rules Quick divisibility checks for 2 through 12, 25 and 100
๐Ÿงฟ Euler's Totient $\phi(n)$ product formula, Euler's theorem, exponent reduction, power towers
๐Ÿ”ค ASCII Table ASCII values, char arithmetic, string conversion utilities
๐Ÿ’ก CP Facts & Observations Prime gaps, divisor counts, coprime facts, rounding to multiples, pigeonhole, limits table
๐Ÿงฐ STL Cheatsheet Algorithms, conversions, string, vector, set, map, pair, stack, queue, deque, priority queue

๐Ÿ“‚ Code Index

Click a filename for the implementation, or ๐Ÿ“– for the theory note.

๐Ÿ“ฆ 1. Arrays & Range Queries ย ยทย  8 implementations
# Algorithm / Technique Code Notes
1 Prefix Sum Array 1_prefix_sum.cpp ๐Ÿ“–
2 2D Prefix Sum Matrix 2_2d_prefix_sum.cpp ๐Ÿ“–
3 Suffix Sum Array 3_suffix_sum.cpp ๐Ÿ“–
4 Difference Array 4_difference_array.cpp ๐Ÿ“–
5 Subarray Sum Equals K 5_subarray_sum.cpp ๐Ÿ“–
6 Two Pointers Technique 6_two_pointers.cpp ๐Ÿ“–
7 Sliding Window Max Sum 7_sliding_windows.cpp ๐Ÿ“–
8 Kadane's Algorithm (Max Subarray) 8_kadane_algorithm.cpp ๐Ÿ“–
๐Ÿ”ข 2. Mathematics & Number Theory ย ยทย  16 implementations
# Algorithm / Technique Code Notes
1 Sieve of Eratosthenes 1_sieve_of_eratosthenes.cpp ๐Ÿ“–
2 Sieve โ€” Smallest Prime Factor (SPF) 2_sieve_smallest_prime_factor.cpp ๐Ÿ“–
3 Distinct Prime Factorization 3_prime_factors.cpp ๐Ÿ“–
4 Efficient Factorization via SPF 4_efficient_prime_factor_using_spf.cpp ๐Ÿ“–
5 Smallest Prime Factor (Single) 5_smallest_prime_factor.cpp ๐Ÿ“–
6 Prime Check (Trial Division) 6_prime_check.cpp ๐Ÿ“–
7 Divisors / Factors of a Number 7_factors_of_number.cpp ๐Ÿ“–
8 Factorial with Modulo 8_factorial.cpp ๐Ÿ“–
9 Inverse Factorial (Fermat's LT) 9_inverse_factorial.cpp ๐Ÿ“–
10 Optimized nCr Calculations 10_optimised_ncr.cpp ๐Ÿ“–
11 Binary Exponentiation 11_binary_exponentiation.cpp ๐Ÿ“–
12 nCr Simple Formula 12_ncr.cpp ๐Ÿ“–
13 Legendre's Formula (Power of p in N!) 13_power_of_x_in_factorial.cpp ๐Ÿ“–
14 Power of x in N 14_power_of_x_in_n.cpp ๐Ÿ“–
15 Euler's Totient (Single + Sieve) 15_euler_totient.cpp ๐Ÿ“–
16 Extended GCD & Modular Inverse (Any Modulus) 16_extended_gcd.cpp ๐Ÿ“–
๐Ÿ” 3. Binary Search ย ยทย  5 implementations
# Algorithm / Technique Code Notes
1 Standard Binary Search 1_binary_search.cpp ๐Ÿ“–
2 Lower Bound 2_lower_bound.cpp ๐Ÿ“–
3 Upper Bound 3_upper_bound.cpp ๐Ÿ“–
4 Binary Search on Answers (Integer) 4_binary_search_on_answers.cpp ๐Ÿ“–
5 Binary Search on Answers (Decimal) 5_binary_search_on_decimals.cpp ๐Ÿ“–
๐Ÿ”€ 4. Sorting Algorithms ย ยทย  2 implementations
# Algorithm / Technique Code Notes
1 Merge Sort 1_merge_sort.cpp ๐Ÿ“–
2 Quick Sort 2_quick_sort.cpp ๐Ÿ“–
โšก 5. Bit Manipulation ย ยทย  8 implementations
# Algorithm / Technique Code Notes
1 Count Set Bits (Kernighan's Algorithm) 1_count_the_set_bits.cpp ๐Ÿ“–
2 Lowest Set Bit Position 2_lowest_set_bit_position.cpp ๐Ÿ“–
3 Highest Set Bit Position 3_highest_set_bit_position.cpp ๐Ÿ“–
4 Lowest Unset Bit Position 4_lowest_unset_bit_position.cpp ๐Ÿ“–
5 Highest Unset Bit Position 5_highest_unset_bit_position.cpp ๐Ÿ“–
6 Highest Unset Bit (Significant Bits) 6_highest_unset_bit_among_significant_bits.cpp ๐Ÿ“–
7 Generate All Subsets via Bitmasking 7_generate_all_subset_using_bitmasking.cpp ๐Ÿ“–
8 Bitset Subset Sum 8_bitset_subset_sum.cpp ๐Ÿ“–
๐Ÿ•ธ๏ธ 6. Graph Algorithms ย ยทย  16 implementations
# Algorithm / Technique Code Notes
1 Depth First Search (DFS) 1_depth_first_search.cpp ๐Ÿ“–
2 Breadth First Search (BFS) 2_breadth_first_search.cpp ๐Ÿ“–
3 Find Level of Every Node 3_find_level_of_every_node.cpp ๐Ÿ“–
4 DFS Entry / Exit Timers (Euler Tour) 4_in_time_out_time.cpp ๐Ÿ“–
5 Dijkstra (SSSP, Non-Negative Weights) 5_dijkstra.cpp ๐Ÿ“–
6 Bipartite Check 6_bipartite_check.cpp ๐Ÿ“–
7 Disjoint Set Union (DSU) 7_disjoint_set_union.cpp ๐Ÿ“–
8 Kruskal Minimum Spanning Tree 8_kruskal_mst.cpp ๐Ÿ“–
9 Directed Cycle Detection 9_directed_cycle_detection.cpp ๐Ÿ“–
10 Topological Sort (Kahn) 10_topological_sort_kahn.cpp ๐Ÿ“–
11 Topological Sort (DFS) 11_topological_sort_dfs.cpp ๐Ÿ“–
12 Kosaraju SCC 12_kosaraju_scc.cpp ๐Ÿ“–
13 Bellman-Ford 13_bellman_ford.cpp ๐Ÿ“–
14 Floyd-Warshall 14_floyd_warshall.cpp ๐Ÿ“–
15 Tarjan's Bridges 15_tarjan_bridges.cpp ๐Ÿ“–
16 DP on a DAG (Longest Path) 16_dp_on_dag.cpp ๐Ÿ“–
๐ŸŒฒ 7. Trees ย ยทย  12 implementations
# Algorithm / Technique Code Notes
1 Precompute Parent of Every Node 1_get_the_parent_of_the_node.cpp ๐Ÿ“–
2 Count Children for Every Node 2_number_of_children_for_a_node.cpp ๐Ÿ“–
3 Find Subtree Size 3_find_subtree_size.cpp ๐Ÿ“–
4 Farthest Leaf Node (Node Height) 4_farthest_leaf_node_inside_subtree.cpp ๐Ÿ“–
5 Diameter of a Tree 5_diameter_of_tree.cpp ๐Ÿ“–
6 Ancestor Query in O(1) 6_ancestor_query.cpp ๐Ÿ“–
7 Depth First Search (DFS) 7_depth_first_search.cpp ๐Ÿ“–
8 Breadth First Search (BFS) 8_breadth_first_search.cpp ๐Ÿ“–
9 Find Level of Every Node 9_find_level_of_every_node.cpp ๐Ÿ“–
10 DFS Entry / Exit Timers (Euler Tour) 10_in_time_out_time.cpp ๐Ÿ“–
11 Binary Lifting + LCA 11_binary_lifting_lca.cpp ๐Ÿ“–
12 Euler Tour Flattening (Subtree to Range) 12_euler_tour_flattening.cpp ๐Ÿ“–
๐Ÿ› ๏ธ 8. Miscellaneous & Boilerplate ย ยทย  4 implementations
# Algorithm / Technique Code Notes
1 Competitive Programming Boilerplate (Fast I/O + PBDS) 1_boilerplate.cpp ๐Ÿ“–
2 Sort std::map by Values 2_sort_map_by_values.cpp ๐Ÿ“–
3 Matrix Rotation & Mirroring 3_matrix_rotation.cpp ๐Ÿ“–
4 Sparse Table (Generic, O(1) Idempotent Queries) 4_sparse_table.cpp ๐Ÿ“–
๐Ÿงฑ 9. Segment Trees & Fenwick ย ยทย  3 implementations
# Algorithm / Technique Code Notes
1 Segment Tree (Generic, Point Update + Range Query) 1_segment_tree.cpp ๐Ÿ“–
2 Lazy Segment Tree (Generic, Range Update + Range Query) 2_lazy_segment_tree.cpp ๐Ÿ“–
3 Fenwick Tree (BIT) 3_fenwick_tree.cpp ๐Ÿ“–

๐Ÿ—‚๏ธ Repository Layout

.
โ”œโ”€โ”€ 0_theory/               # notes: mirrors the code folders + reference sheets
โ”‚   โ”œโ”€โ”€ 1_arrays/ โ€ฆ 9_segment_tree/
โ”‚   โ””โ”€โ”€ *.md                # math_formulas, combinatorics, cp_facts, ...
โ”œโ”€โ”€ 1_arrays/               # prefix sums, two pointers, Kadane, ...
โ”œโ”€โ”€ 2_math/                 # sieve, factorization, nCr, totient, extgcd, ...
โ”œโ”€โ”€ 3_binary_search/
โ”œโ”€โ”€ 4_sorting/
โ”œโ”€โ”€ 5_bit_manipulation/
โ”œโ”€โ”€ 6_graphs/               # traversals, shortest paths, DSU, SCC, bridges, ...
โ”œโ”€โ”€ 7_trees/                # LCA, diameter, Euler tour, ...
โ”œโ”€โ”€ 8_misc/                 # boilerplate, sparse table, matrix rotation, ...
โ”œโ”€โ”€ 9_segment_tree/         # segment tree, lazy segment tree, Fenwick
โ”œโ”€โ”€ scripts/                # check.sh (compile all) + lint_docs.py (validate docs)
โ””โ”€โ”€ .github/workflows/      # CI

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages