Search Algorithms

Reference comparison of fundamental search algorithms.

  • JSON4,876 B
  • YAML3,163 B · −35%
  • TOON2,272 B · −53%

Searching algorithms with best, average and worst time, space and a description: linear, binary, jump, interpolation, exponential and ternary search, plus Fibonacci search, hash-based lookup and binary-search-tree lookup.

Use it when

  • You need to choose a search method for sorted or unsorted data.
  • You need the complexity of a lookup.

Watch out for

  • Binary-search variants require sorted, randomly accessible data.
  • Hash lookup is average O(1) but needs a good hash and extra memory, and it does not support range queries.

The data

NameBestAverageWorstSpaceDescription
Linear SearchO(1)O(n)O(n)O(1)Sequentially checks each element until the target is found.
Binary SearchO(1)O(log n)O(log n)O(1)Repeatedly divides a sorted interval in half.
Jump SearchO(1)O(sqrt n)O(sqrt n)O(1)Jumps ahead by fixed steps and then performs linear search.
Interpolation SearchO(1)O(log log n)O(n)O(1)Estimates position using interpolation for uniformly distributed data.
Exponential SearchO(1)O(log n)O(log n)O(1)Finds range by repeated doubling then binary searches within it.
Ternary SearchO(1)O(log n)O(log n)O(1)Divides the array into three parts and narrows the interval.
Fibonacci SearchO(1)O(log n)O(log n)O(1)Divides a sorted array using Fibonacci numbers, using only addition and subtraction.
Hash-Based LookupO(1)O(1)O(n)O(n)Computes a hash of the key to find its bucket directly.
Binary Search Tree LookupO(1)O(log n)O(n)O(1)Follows left and right branches by comparing keys; worst case occurs in an unbalanced tree.

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
datanamestringLinear Search
databeststringO(1)
dataaveragestringO(n)
dataworststringO(n)
dataspacestringO(1)
datadescriptionstringSequentially checks each element until the targ…

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

curl "https://yjtoon.com/api/dataset/search-algorithms?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/search-algorithms.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • algorithms
  • search
  • complexity
  • big-o

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets