What Is an Algorithm? Explained Simply
An algorithm is a finite, well-defined sequence of steps that solves a problem or performs a computation. Learn the concept with a simple sorting example.
Published September 22, 2026
An algorithm is a finite, precisely defined sequence of steps that takes some input and produces a correct output for that problem, regardless of the programming language used to implement it.
Common causes
- Any given problem — sorting a list, finding a shortest path, searching for a value — can typically be solved by multiple different algorithms, each with different tradeoffs in speed and memory use
How to fix it
- Focus on correctness first — an algorithm must produce the right answer for every valid input, including edge cases like empty input
- Then consider efficiency — compare algorithms using Big O notation to understand how they'll scale as input grows
- Remember an algorithm is independent of any specific programming language — the same algorithm (like binary search) can be implemented in Python, Java, or any other language and remains the same algorithm
Example
// Bubble sort algorithm, implemented in JavaScript
function bubbleSort(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]
}
}
}
return arr
}FAQ
Is an algorithm the same thing as code?
No — an algorithm is the abstract idea/steps for solving a problem; code is one specific implementation of that idea in a particular programming language.