What makes something an algorithm

Correctness, termination, and a cost you can predict before you run it.

An algorithm is a finite procedure that turns an input into an output, and it has to satisfy three things before anyone should trust it.

Correctness

It produces the right answer for every valid input, not for the input you happened to try. Most wrong algorithms work on the happy path; they fail on the empty list, the single element, the duplicate, the already-sorted array.

Termination

It finishes. A loop whose variable never approaches its bound, or a recursion with no base case, is not a slow algorithm — it is not an algorithm at all.

// Terminates: lo and hi always close the gap.
function binarySearch(sorted, target) {
  let lo = 0;
  let hi = sorted.length - 1;

  while (lo <= hi) {
    const mid = (lo + hi) >> 1;

    if (sorted[mid] === target) return mid;
    if (sorted[mid] < target) lo = mid + 1;
    else hi = mid - 1;
  }

  return -1;
}

Drop the + 1 from lo = mid + 1 and the loop can spin forever on a two-element range. That single character is the difference between an algorithm and a hang.

A predictable cost

You should be able to say how the running time grows as the input grows, without running it. That is what Big O gives you, and it is the whole of the next chapter.

Correct first, then fast

The order is not negotiable. A fast wrong answer has no value, and a clear correct solution is the thing you optimise. In an interview, saying "here is the brute force, it is O(n²), now let me improve it" scores far better than silence while you hunt for the clever answer.

Write the obvious version. Prove it right. Then make it fast.