1. Array Deque

    Implementations C++ #include <cstddef> #include <memory> template <typename T> class ArrayDeque { private: std::allocator<T> alloc_; T *array_ = nullptr; std::size_t start_ = 0; // WARN: end_ is not needed and you CANNOT do it without a size_ // end can be computed from size ...

  2. Binary Search Tree

    Implementations C++ #include <cstddef> #include <iterator> #include <memory> #include <ranges> #include <type_traits> #include <utility> #include <vector> template <typename T> class BST { private: struct Node { T val; std::unique_ptr<Node> left,...

  3. Disjoint Set Union

    Implementations C++ // for the single array holds size and par trick // you need a signed int as the array elem type // since the par too must be same as the elem type // you need int as type // templating here is kind of wasteful #include <vector> class DSU { private: std::vector<int> p...

  4. Dynamic Array

    Implementations C #include <stddef.h> #include <stdlib.h> #include <string.h> typedef struct { unsigned char *data; size_t size; size_t capacity; size_t elem_size; } Array; /// initialise void array_init(Array *array, size_t elem_size) { *array = (Array){.data = NULL, .size = 0, .c...

  5. Fenwick Tree

    Implementations C++ #include <concepts> #include <cstddef> #include <vector> template <typename T> concept Group = requires(T a, T b) { // INFO: you need to use other std::concepts in rhs here // so can't do std::is_same_v, need std::is_same_as // alternative is to add a...

  6. Hash Map

    Implementations C++ #include <concepts> #include <cstdint> #include <cstdio> #include <functional> #include <string> #include <type_traits> #include <utility> #include <vector> template <typename T> concept HashableKey = requires(T key) { { std::...

  7. Heap

    Implementations C++ #include <cstddef> #include <vector> template <typename T, typename Cmp = std::less<T>> class Heap { private: std::vector<T> array_; Cmp comp_; // INFO: you don't need a size // INFO: it's complete b tree in the sense that you FILL the // r...

  8. Linked List

    Implementations C++ #include <cstddef> template <typename T> class LinkedList { private: // INFO: only C needs struct Node like creation, in cpp can just do Node // so you never need that typedef thing struct Node { Node *next; Node *prev; T value; // copy ctors on T expected, fails othe...

  9. Segment Tree

    Implementations C++ #include <concepts> #include <cstddef> #include <vector> template <typename Ops, typename S, typename L> concept LazySegConcept = requires(S a, S b, L f, L g, std::size_t len) { { Ops::identity_value() } -> std::same_as<S>; { Ops::combine(a, b) } ...

  10. How to Solve

    general ideas for what I notice and feel while solving a problem the solution is not the code, implementation is not the challenge here ( well not at this stage ).