Kodewick
Start learning →
Data structures and algorithms · C++

Data Structures and Algorithms in C++

Build data structures by hand in C++: classes, pointers, new and delete, every step drawn for you. Then learn the STL's vector, stack, priority_queue, map, unordered_map, sort and lower_bound: what they do inside and why they are fast. Each chapter ends with the patterns problems ask for.

Start with lesson 1 →52 lessons · about 16 hours · free · runs in your browser
  1. Part 1Getting started: how fastCounting steps, Big O, where log n comes from, and what each STL container's operations cost.4 lessons · 1 h
    1. Lesson 1Counting the steps16 minStart
    2. Lesson 2Big O: O(1), O(n), O(n²)17 minStart
    3. Lesson 3Where log n comes from16 minStart
    4. Lesson 4What STL operations cost24 minStart
  2. Part 2Arrays and linked listsClasses, pointers, new and delete; arrays and vector: indexing, inserting, deleting, how size and capacity grow; linked lists by hand, then std::list.8 lessons · 2.5 h
    1. Lesson 5Objects, pointers and references22 minStart
    2. Lesson 6Arrays and vector: straight to an index18 minStart
    3. Lesson 7Inserting and deleting in an array20 minStart
    4. Lesson 8Arrays that grow: vector20 minStart
    5. Lesson 9Linked lists: nodes and pointers15 minStart
    6. Lesson 10Inserting and deleting in a linked list16 minStart
    7. Lesson 11Doubly linked and circular lists17 minStart
    8. Lesson 12Patterns: arrays and linked lists20 minStart
  3. Part 3Stacks and queuesArray and linked stacks, matching brackets, postfix expressions, circular queues, and stack, queue, deque and monotonic stacks.5 lessons · 1.5 h
    1. Lesson 13Stacks: last in, first out15 minStart
    2. Lesson 14Matching brackets12 minStart
    3. Lesson 15Evaluating expressions: postfix15 minStart
    4. Lesson 16Queues, circular queues and deque16 minStart
    5. Lesson 17Patterns: stacks and queues20 minStart
  4. Part 4Hash tablesHash functions, open addressing, chaining and resizing, and unordered_map's buckets and load factor.4 lessons · 1 h
    1. Lesson 18Hash functions18 minStart
    2. Lesson 19Open addressing17 minStart
    3. Lesson 20Separate chaining and unordered_map16 minStart
    4. Lesson 21Patterns: hash tables18 minStart
  5. Part 5TreesBinary trees and recursion, four traversals, rebuilding a tree, binary search trees with set and map, a heap by hand and then priority_queue, heap sort and top-k, Huffman coding, every step drawn on the tree.8 lessons · 2.5 h
    1. Lesson 22Binary trees and recursion20 minStart
    2. Lesson 23Four ways to walk a binary tree20 minStart
    3. Lesson 24Rebuilding a tree from its traversals18 minStart
    4. Lesson 25Binary search trees, set and map22 minStart
    5. Lesson 26Heaps and priority_queue18 minStart
    6. Lesson 27Heap sort and top-k18 minStart
    7. Lesson 28Huffman trees and Huffman codes16 minStart
    8. Lesson 29Patterns: trees20 minStart
  6. Part 6GraphsAdjacency matrices and lists (vector<vector<…>>), BFS and DFS, topological sort, Dijkstra with priority_queue, Prim and Kruskal (union-find), every step drawn on the graph.7 lessons · 2 h
    1. Lesson 30Storing a graph: adjacency matrix and list17 minStart
    2. Lesson 31Breadth-first search (BFS)17 minStart
    3. Lesson 32Depth-first search (DFS)17 minStart
    4. Lesson 33Topological sort16 minStart
    5. Lesson 34Shortest paths: Dijkstra20 minStart
    6. Lesson 35Minimum spanning trees: Prim and Kruskal20 minStart
    7. Lesson 36Patterns: graphs18 minStart
  7. Part 7SearchingSequential and binary search, binary search bounds and lower_bound / upper_bound, balanced trees (AVL rotations, red-black trees), and binary search on the answer.4 lessons · 1 h
    1. Lesson 37Sequential and binary search16 minStart
    2. Lesson 38Binary search bounds and lower_bound17 minStart
    3. Lesson 39Balanced trees: AVL and red-black18 minStart
    4. Lesson 40Patterns: searching18 minStart
  8. Part 8SortingBubble, selection, insertion, Shell, merge, quick, counting and radix sort, each run for real with its comparisons counted; then std::sort, stable_sort and comparators.6 lessons · 2 h
    1. Lesson 41Bubble sort and selection sort15 minStart
    2. Lesson 42Insertion sort and Shell sort15 minStart
    3. Lesson 43Merge sort24 minStart
    4. Lesson 44Quicksort24 minStart
    5. Lesson 45Counting sort and radix sort22 minStart
    6. Lesson 46Patterns: sorting26 minStart
  9. Part 9Algorithm designRecursion and divide and conquer, backtracking (next_permutation), greedy, dynamic programming and knapsack problems: recursion trees, search trees and DP tables drawn box by box.6 lessons · 2.5 h
    1. Lesson 47Recursion and divide and conquer24 minStart
    2. Lesson 48Backtracking24 minStart
    3. Lesson 49Greedy algorithms22 minStart
    4. Lesson 50Dynamic programming24 minStart
    5. Lesson 51Knapsack problems24 minStart
    6. Lesson 52Patterns: algorithm design26 minStart

Questions

Is it really free?

Yes. Every lesson, example and exercise is free, with no sign-up.

Do I need to know C++ first?

A little: variables, loops, functions, vector and string, ideally classes too. If not, start with our C++ course.

How is it different from the C and Python editions?

The same chapters, taught the C++ way: each structure by hand with classes and pointers first, then the STL container or algorithm that does it, and what it costs.

Where is my progress kept?

In this browser, with no account.