Algorithm
ELI5 — The Vibe Check
An algorithm is just a step-by-step recipe for solving a problem. Sort a list? There is an algorithm. Find the shortest path? Algorithm. Make a sandwich? That is also an algorithm. In code, algorithms turn input into output through a defined sequence of steps. The trick is making them fast and correct.
Real Talk
An algorithm is a finite, deterministic sequence of instructions that transforms input into output, solving a well-defined problem. Algorithms are analyzed for time complexity (how long they take) and space complexity (how much memory they use), expressed in Big O notation. Classic algorithms include sorting (QuickSort, MergeSort), searching (binary search), and graph traversal (BFS, DFS).
Show Me The Code
// Binary search algorithm — finds a number in a sorted array:
function binarySearch(arr, target) {
let left = 0, right = arr.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) return mid;
if (arr[mid] < target) left = mid + 1;
else right = mid - 1;
}
return -1; // not found
}
// O(log n) — much faster than checking every element
When You'll Hear This
"Which algorithm are you using to sort that?" / "The algorithm runs in O(n²) — too slow for large datasets."
Related Terms
Big O
Big O notation is how we describe how fast (or slow) an algorithm gets as the input grows. O(1) means instant no matter the size.
Data Structure
A data structure is a way of organizing information in your code so it is easy to use and fast to access.
Pseudocode
Pseudocode is fake code written in plain English that describes what your real code should do, without worrying about syntax.
Recursion
Recursion is when a function calls itself to solve a smaller version of the same problem, like a set of Russian nesting dolls.
Time Complexity
Time complexity is how the time your algorithm takes grows as the input gets bigger. Does it take twice as long when you double the data? Ten times longer?