Skip to content
ExamplesEspañolWorkspace →

Sorting & searching

The classic sorting and searching algorithms, with their complexity: bubble, selection, insertion, merge, quick sort and binary search.

10 examples

  • Bubble Sort

    Sorts random numbers by swapping neighbors, and stops as soon as they're in order.

    Intermediate
  • Selection Sort

    Finds the smallest of the remaining numbers and puts it in its place.

    Intermediate
  • Insertion Sort

    Inserts each number among the sorted ones, like arranging cards in your hand.

    Intermediate
  • Shell Sort

    Insertion sort between far-apart elements, with a gap that shrinks every pass.

    Advanced
  • Merge Sort

    Splits the array in halves, sorts each one recursively and merges them.

    Advanced
  • Quicksort

    Picks a pivot, splits smaller from larger values and sorts each side recursively.

    Advanced
  • Heap Sort

    Arranges the array as a heap, then takes the largest out again and again.

    Advanced
  • Counting Sort

    Counts how many times each value appears, without comparing numbers.

    Intermediate
  • Binary Search

    Finds a value in a sorted array by halving the range every step.

    Intermediate
  • Linear vs. Binary Search

    Counts the comparisons each search needs on the same sorted list.

    Intermediate