Skip to content
DSA Visualizerpreview

Integer square root (search the answer)

Search the answers, not an array: halve the range of k until k² is as big as it can be.

O(log x) time · O(1) space

x30

Find the largest k with k² ≤ 30. Every candidate k from 0 to 30 is a bar of height k².

Array of 31 values: 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, and 11 more. Active index 0 (0) and index 30 (900). Pointers lo at index 0 and hi at index 30.
  • compare
  • swap or write
  • settled

1 / 7

Speed

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