Algorithm Search⌘K

C

Every implementation in C on this site.

Tier
1
Toolchain
C23, GCC 15 or Clang 21, with ASan and UBSan
Tests
assert
Format
clang-format
Lint
clang-tidy
Run the tests
cc -std=c2x -Wall -Wextra -Wpedantic -Werror -fsanitize=address,undefined *.c && ./a.out

Implementations

  • Binary search

    Find a key in a sorted array. Compare the key with the middle item, and keep only the half that can hold the key.

    Θ(log n) worst · average intro
  • Insertion sort

    Sort an array one item at a time. Take the next item and move it left until the item before it is not larger.

    Θ(n²) worst · average intro
  • Merge sort

    Sort an array by divide and conquer. Sort each half, then merge the two sorted halves into one sorted array.

    Θ(n log n) worst · average · best intro