# Algorithm

URL: https://softwaredictionary.org/terms/algorithm
Category: Programming Fundamentals
Last updated: 2026-09-29
In Turkish: Algoritma

In short: An algorithm is a finite, step-by-step set of instructions for solving a problem or completing a task, such as sorting a list or finding the shortest route.

## What is an algorithm?

An algorithm is a precise recipe for turning an input into a desired output. It spells out every step clearly enough that anyone, or any computer, following it will get the same result. Algorithms exist independently of programming languages: the same algorithm can be written in Python, in JavaScript, or on paper.

A cooking recipe is a good everyday analogy for an algorithm. It lists ingredients (the input), gives ordered steps, and ends with a finished dish (the output). In software, familiar examples include binary search, which finds an item in a sorted list by repeatedly cutting the list in half, and the sorting algorithms behind functions like `Array.prototype.sort`.

Different algorithms can solve the same problem with very different efficiency. Developers compare them using Big O notation, which describes how running time or memory use grows as the input gets larger. For example, checking every item in a list one by one is O(n), while binary search is O(log n), which is far faster for large lists.

An algorithm is not the same thing as a program. The algorithm is the idea, the logical sequence of steps, while a program is a concrete implementation of one or more algorithms in a specific language, together with everything else needed to run it.

## Key takeaways

- An algorithm is a finite, ordered set of steps that turns an input into an output.
- It is language-independent; code is just one way to express it.
- Efficiency is described with Big O notation for time and memory.
- Classic examples include searching, sorting, and shortest-path algorithms.

## Example: Binary search in JavaScript

```javascript
// Find target in a sorted array; return its index or -1
function binarySearch(sorted, target) {
  let low = 0;
  let high = sorted.length - 1;
  while (low <= high) {
    const mid = Math.floor((low + high) / 2);
    if (sorted[mid] === target) return mid;  // found it
    if (sorted[mid] < target) low = mid + 1; // search the right half
    else high = mid - 1;                     // search the left half
  }
  return -1; // not found
}

binarySearch([2, 5, 8, 12, 16], 12); // 3
```

## Frequently asked questions

**What is the difference between an algorithm and a program?**

An algorithm is the abstract sequence of steps for solving a problem. A program is a concrete implementation of that algorithm, usually along with many others, written in a specific programming language so a computer can run it.

**What is Big O notation?**

Big O notation describes how an algorithm's running time or memory use grows as the input size grows. For example, O(n) means the work grows in direct proportion to the input, while O(1) means it stays the same no matter how large the input is.

**Do I need to know algorithms to be a developer?**

You don't need to memorize every algorithm, but understanding common ones like searching and sorting, and knowing how to reason about efficiency, helps you write faster code. Algorithm questions are also common in technical interviews.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
