algorithm
/ AL-guh-rith-um /
An algorithm is a precise, step-by-step recipe for solving a problem or getting a result. Before your code does anything, there's a plan behind it — the exact sequence of steps that turns the input you have into the answer you want. The algorithm is that plan; the code is just one way of writing it down.
A good way to feel it: a cooking recipe is an algorithm. Take these ingredients, do these steps in this order, and you reliably get the dish. So are the directions to a friend's house. What makes it an algorithm rather than a vague idea is the precision — no step left to guesswork, each one clear enough that a machine could follow it.
The same problem can have many algorithms, and they're not equally good. Sorting a list of names can be done a dozen ways; some finish in a blink, others crawl on a long list. So choosing the right algorithm — fast enough, simple enough, correct in every case — is a real part of the craft, separate from the typing of code itself.
// algorithm: find the largest number
let max = nums[0];
for (const n of nums) {
if (n > max) max = n;
}
// max now holds the biggest valueA tiny algorithm in plain steps: start with the first, keep whichever is bigger.
How an algorithm's cost grows as the input gets bigger is its 'time complexity' — the reason one approach can be lightning-fast and another painfully slow on the same data.