Algorithm visualizer
Pick an algorithm, enter your own numbers or use a preset, then step through the run. The pseudocode and the explanation follow each step.
On a sorted array, move one pointer from each end. A sum that is too small moves the left pointer right; too large moves the right pointer left.
Precondition: The array must be sorted from smallest to largest.
Make the array longer and find the target sum by hand before stepping. Does your pair match the first one found?
Step 1 of 7
Set i = 0 and j = 5, the two ends of the sorted array.