|
1 | 1 | # Competitive-Programming-Repository
|
2 |
| -Competitive Programming templates that I used during the past few years. |
| 2 | +Collection of algorithms and data structures in C++ used widely in Competitive programming contests. |
| 3 | + |
| 4 | +### The following topics are covered: |
| 5 | + |
| 6 | +#### Range Updates and Queries |
| 7 | +* **Range Aggregate Queries** : |
| 8 | + * *Binary Indexed Trees (BIT)* : |
| 9 | + * [Point Update Range Query](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/binary_indexed_tree.cpp) |
| 10 | + * [Range Update Range Query](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/binary_indexed_tree_range_query_range_update.cpp) |
| 11 | + * [Order Statistic Query](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/binary_indexed_tree_order_stat.cpp) |
| 12 | + * [2D Binary Indexed Trees](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/binary_indexed_tree_2D.cpp) |
| 13 | + * *Segment Trees (SegTree)* : |
| 14 | + * [Point Update Range Query](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segment_tree_range_query_point_update.cpp) |
| 15 | + * [Fast Iterative Segtrees](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segment_trees_interative_fast.cpp) |
| 16 | + * [Range Update Point Query - Lazy Propogation](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segment_tree_range_query_range_update_lazy_propogation.cpp) |
| 17 | + * [Max subsegment sum in range](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segment_tree_custom_merge_function.cpp) |
| 18 | + * [2D Segment Trees](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segment_tree_2D.cpp) |
| 19 | + * [Dynamic Segment Trees - Insertion/Deletion between elements](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segment_tree_dynamic_using_treaps.cpp) |
| 20 | + * [Dynamic Segment Trees - Reverse a segment](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segment_tree_dynamic_reverse_subarray_using_treap.cpp) |
| 21 | + * *Merge Sort Trees* : |
| 22 | + * [Merge sort trees](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/merge_sort_trees.cpp) |
| 23 | + * [Merge sort trees - Order Statistics](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/merge_sort_trees_order_stat_query.cpp) |
| 24 | + * *Sparse Table* : |
| 25 | + * [Range Minimum Query](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/range_minimum_query_sparse_table.cpp) |
| 26 | + * *Mo Algorithm* : |
| 27 | + * [Mo Algorithm - Arrays](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/mo_algorithm_offline_range_query.cpp) |
| 28 | +* **Dynamic Programming** : |
| 29 | + * *Dynamic Programming Templates* : |
| 30 | + * [Digit DP / Bitwise DP](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/dynamic_programming_templates.cpp) |
| 31 | + * *Standard DP Problems* : |
| 32 | + * [Longest Increasing Subsequence](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/longest_increasing_subsequence_lis_binary_search.cpp) |
| 33 | + * [Longest Palindromic Subsequence](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/palindrome_longest_subsequence.cpp) |
| 34 | + * [Levenstein Distance / Edit Distance](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/edit_distance_levenstein_dynamic_programming.cpp) |
| 35 | +* **Graphs** : |
| 36 | + * *Single Source Shortest Path Algorithms* : |
| 37 | + * [Dijkstra in dense graphs](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/dijsktra_dense_graphs.cpp) |
| 38 | + * [Dijkstra using priority queue](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/dijkstra_using_priority_queue.cpp) |
| 39 | + * [Kth Shortest Path between Nodes using Dijkstra](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/kth_shortest_path_between_nodes_graph.cpp) |
| 40 | + * [Bellman Ford Negative cycle detection](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/bellman_ford.cpp) |
| 41 | + * *All Pair shortest path* : |
| 42 | + * [Using Binary exponentiation](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/all_pair_shortest_path_binary_exponentation.cpp) |
| 43 | + * [Floyd Warshall](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/all_pair_shortest_path_floyd_warshall.cpp) |
| 44 | + * *Cycle Detection* : |
| 45 | + * [Cycle detection in Undirected/Directed Graphs](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/cycle_detection_in_graph.cpp) |
| 46 | + * *Minimum Spanning tree* : |
| 47 | + * [Kruskal Algorithm](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/kruskal_min_spanning_tree.cpp) |
| 48 | + * *Topological Sort / Strongly Connected Component* : |
| 49 | + * [Topological Sort](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/topological_sort_kosaraju.cpp) |
| 50 | + * [Strongly Connected Component](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/strongly_connected_components_kosaraju.cpp) |
| 51 | + * *Maxflow/Matching* : |
| 52 | + * [Hopkroft Karp Max Matching](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/max_bipartite_matching_hopcroft_karp.cpp) |
| 53 | + * [Dinic Max Flow](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/max_flow_network_dinic_algorithm.cpp) |
| 54 | + * *Misc* : |
| 55 | + * [Bridges in Graph](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/bridges_in_graph.cpp) |
| 56 | + * [Connectivity](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/isConnected_using_bfs.cpp) |
| 57 | + * [Bipartite Check](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/non_bipartite_check.cpp) |
| 58 | +* **Trees** : |
| 59 | + * *Ancestor queries* : |
| 60 | + * [Lowest Common Ancestor](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/lowest_common_ancestor_lca.cpp) |
| 61 | + * [Kth Ancestor](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/kth_ancestor_tree.cpp) |
| 62 | + * *Path queries* : |
| 63 | + * [Sparse Table](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/trees_path_query_sparse_tables.cpp) |
| 64 | + * [Heavy Light Decomposition Weighted Nodes](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/heavy_light_decomposition_wieghted_vertices(hld).cpp) |
| 65 | + * [Heavy Light Decomposition Weighted Edges](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/heavy_light_decomposition_weighted_edges%20(hld).cpp) |
| 66 | + * *Misc* : |
| 67 | + * [Diameter of Tree](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/tree_diameter.cpp) |
| 68 | + * [Preorder/Postorder stamps, Is it in Subtree?](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/tree_dfs_preorder_postorder_isInSubtree.cpp) |
| 69 | +* **Binary Exponentiation** : |
| 70 | + * [Calculate n^m using Binary exponentiation](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/power_binary_exponentiation.cpp) |
| 71 | + * [Solving Linear Recurrences](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/linear_recurrence_matrix_exponentiation.cpp) |
| 72 | +* **Strings** : |
| 73 | + * *String Algorithms* : |
| 74 | + * [Z Algorithm](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/Z_algorithm_max_prefix_match.cpp) |
| 75 | + * [Rolling String Hashing](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/string_hashing.cpp) |
| 76 | + * [Rolling String Hashing for Dynamic Strings](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/string_hashing_dynamic_segment_trees.cpp) |
| 77 | +* **Sorting** : |
| 78 | + * [Merge Sort](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/merge_sort_count_inversion.cpp) |
| 79 | + * [Quick Select](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/quick_select_order_stat_linear.cpp) |
| 80 | +* **Fast Input/Output, String/Integer Conversion** : |
| 81 | + * [Fast Input/Output](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/fast_readInt_writeInt_function.cpp) |
| 82 | + * [String/Integer Conversion](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/int2string_string2int.cpp) |
| 83 | +* **Misc. Data Structures** : |
| 84 | + * [Disjoint Set](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/disjoint_set.cpp) |
| 85 | + * [Disjoint Set (Supports Undo Operation)](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/disjoint_set_with_undo_operation.cpp) |
| 86 | + * [Max/Min Priority Queue with update](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/heap_using_multiset_max_min_insert_erase_update.cpp) |
| 87 | + * [Binary Trie for xor maximization/minimization](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/binary_trie_max_xor.cpp) |
| 88 | + * [Bigint](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/bigint_library.cpp) |
| 89 | + * [Augmented Binary Tree for order statistics and rank query](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/orderstat_rank_query_augmented_bst.cpp) |
| 90 | + * [Monotone Priority Queue](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/monotone_priority_queue.cpp) |
| 91 | + * [Trie](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/trie_insertion_deleteion.cpp) |
| 92 | +* **Persistent Data Structures** : |
| 93 | + * *Persistent Segment Trees (SegTree)* : |
| 94 | + * [Persistent Segment Tree](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segment_tree_persistent.cpp) |
| 95 | + * [Persistent Segment Tree - Order Statistics](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segment_tree_persistent_order_stat.cpp) |
| 96 | +* **Number Theory Algorithms** : |
| 97 | + * *Primality Check* : |
| 98 | + * [Fermat's Primality Check](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/primality_check_fermat.cpp) |
| 99 | + * *Sieve* : |
| 100 | + * [Sieve of Eratosthenes](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/prime_sieve.cpp) |
| 101 | + * [Segmented Sieve for large primes](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/segmented_sieve_large_primes.cpp) |
| 102 | + * [Counting Prime Factors](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/prime_factor_count.cpp) |
| 103 | + * *Polynomial Multiplication* : |
| 104 | + * [Fast Fourier Tranform](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/fast_fourier_transform_fft.cpp) |
| 105 | + * [Karatsuba](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/karatsuba_polynomial_multiplication.cpp) |
| 106 | + * *Misc* : |
| 107 | + * [Combinatorial and Catalan - Factorial preprocessing](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/factorial_preprocessing.cpp) |
| 108 | + * [Mobeius Function](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/mobeius_function.cpp) |
| 109 | + * [Euler Totient Function](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/euler_phi_euler_totient_function.cpp) |
| 110 | + * [Lucas Theorm - Combinatorics](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/master/lucas_combinatorics.cpp) |
| 111 | +* **Misc** : |
| 112 | + * [Sum of floor(x) with x=1:n](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/aggreate_sqrt_distinct_values.cpp) |
| 113 | + * [Sum of cyclic functions](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/aggregate_cyclic_function.cpp) |
| 114 | + * [Closest element before/after every element](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/closest_max_element_before_after_index_using_stack.cpp) |
| 115 | + * [Multiply Long Long Integers](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/multiply_longlong_integers.cpp) |
| 116 | + * [Multiply Long Long Integers - Overflow detection](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/multiply_detect_overflow.cpp) |
| 117 | + * [Scanline - Merge intersecting intervals](https://github.com/dragonslayerx/Competitive-Programming-Repository/blob/dragonslayerx-readme-update/scanline_merge_overlapping_intervals.cpp) |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
0 commit comments