Skip to content
DSA Visualizerpreview

Merge two sorted lists

Repeatedly take the smaller of the two heads; attach whatever is left at the end.

O(n + m) time · O(1) space

Two lists1, 4, 7, 10 | 2, 3, 8, 12

Merge two sorted lists by always taking the smaller head.

Merged so far: nothing.
  • compare
  • swap or write
  • settled

1 / 10

Speed

Space play · ← → step · Home End jump · drag the strip to scrub