SortingD2Phase 1divide-and-conquerstablearray

Merge Sort

Stable divide-and-conquer sort with predictable O(n log n) behavior.

Easy Explanation

Merge Sort splits the array into smaller pieces, sorts each piece, then merges them back in order.

Renderer Mode

`Simple` uses abstract, short-form-friendly visuals. `Advanced` keeps the current detailed view.

Arrays + Grid
Visualizer
O(n log n)Merge Sort
Deterministic recursive split and merge playback with compare and write-back events.

Comparisons

0

Writes

0

Merges

0

Depth

n/a

Ready

Press Play or Step to start execution.

No values available for visualization.
Merge Sort Implementation
Pseudocode + TypeScript
Reference implementation examples are intentionally abstracted from the playback engine so learners can map concepts to code.
pseudocode
function mergeSort(values):
  if length(values) <= 1:
    return values

  mid <- floor(length(values) / 2)
  left <- mergeSort(values[0..mid-1])
  right <- mergeSort(values[mid..end])

  return merge(left, right)

function merge(left, right):
  output <- []
  i <- 0
  j <- 0

  while i < length(left) and j < length(right):
    if left[i] <= right[j]:
      append left[i] to output
      i <- i + 1
    else:
      append right[j] to output
      j <- j + 1

  append remaining left and right values to output
  return output
1.00xNo Run