SkillAgentSearch skills...

Algs4

Algorithms, 4th edition textbook code in C++

Install / Use

/learn @landerrosette/Algs4
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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.

View on GitHub
GitHub Stars445
CategoryDevelopment
Updated12d ago
Forks38

Languages

C++

Security Score

95/100

Audited on Mar 25, 2026

No findings