C++ GPL-3.0

algs4

Algorithms, 4th edition textbook code in C++

L

landerrosette

Dernière activité 26 janv. 2026
landerrosette/algs4

445

étoiles

34

forks

0

issues ouvertes

Ce README est souvent en anglais.

Overview

This repository contains C++ implementations of the algorithms and clients in the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

For the original Java source code, visit the official repository.

Algorithms

Fundamentals

Sorting

Symbol Tables

Graphs

Strings

Clients

Fundamentals

Sorting

  • Sorts (Selection, Insertion, Shell, Merge, MergeBU, Quick, Quick3way, Heap): Sorting.cpp.in
  • Heap priority queue (MaxPQ): MaxPQ.cpp

Symbol Tables

  • Symbol table tests (TestSequentialSearchST, TestBinarySearchST, TestBST, TestRedBlackBST, TestSeparateChainingHashST, TestLinearProbingHashST): TestST.cpp.in

Graphs

  • Depth-first search (DepthFirstPaths) | Breadth-first search (BreadthFirstPaths): Paths.cpp.in
  • Connected components (CC, KosarajuSCC): CC.cpp.in
  • Reachability (DirectedDFS): DirectedDFS.cpp
  • Topological order (Topological): Topological.cpp
  • Minimum spanning tree (PrimMST, KruskalMST): MST.cpp.in
  • Shortest paths (DijkstraSP, AcyclicSP, BellmanFordSP): SP.cpp.in

Strings

  • String sorts (LSD, MSD, Quick3string): Sorting.cpp.in
  • Trie symbol table tests (TestTrieST) | TST symbol table tests (TestTST): TestST.cpp.in
  • Substring search (KMP, BoyerMoore, RabinKarp): SubstrSearch.cpp.in
  • Regular expression pattern matching (GREP): GREP.cpp
  • Huffman compression/expansion (Huffman) | LZW compression/expansion (LZW): Compress.cpp.in

Usage

Build

This project uses CMake as the build system. Ensure you have CMake 3.21+ and a C++20 compliant compiler.

cmake -B build
cmake --build build

Run clients

By default, all clients are built and the executables can be found in the build directory. Refer to the comments in the source files listed in Clients for instructions on how to run each client. Go to the book's website for test data.

Use as header-only library

Option A: CMake add_subdirectory

Add to your CMakeLists.txt:

add_subdirectory(/path/to/algs4)
target_link_libraries(your_target PRIVATE algs4)

Option B: Manual integration

If you are not using CMake, simply ensure the include/ directory is in your compiler's include path and include the headers you need.

Projets similaires

Algorithms, 4th edition textbook code and libraries

Java
Kkevin-wayne
7,5 k étoiles2,7 k

Book Code for Competitive Programming

C++
Eecnerwala
641 étoiles77

Collection of various algorithms in mathematics, machine learning, computer science and physics implemented in C++ for educational purposes.

C++algorithmalgorithm-competitionsalgorithms-implemented
TTheAlgorithms
34,7 k étoiles7,9 k