← Back to Library Computer Science Beginner 7 min read

What Is an Algorithm? Problem Solving and Computational Logic

An algorithm is a finite, unambiguous, step-by-step sequence of computational instructions designed to solve a specific problem or perform a calculation.

💡 Plain-English Analogy

An algorithm is just like a recipe for baking chocolate chip cookies. If you follow the clear instructions in order (preheat oven, mix flour and sugar, fold in chips, bake for 10 minutes), you consistently get delicious cookies every single time.

⚙️ Architecture & Under the Hood

Algorithms transform input data into intended output representations. They are analyzed according to correctness, determinism, termination (guaranteed halt), and asymptotic time and space complexity. Classic paradigms include Divide-and-Conquer, Greedy algorithms, Dynamic Programming, and Backtracking.

Real-World Algorithm: Linear Search vs Binary Search

Searching for a number in a sorted list of 1,000,000 items demonstrates how algorithmic efficiency transforms computation time.

// Binary Search: O(log N) Time Complexity
function binarySearch(sortedArray, target) {
  let left = 0;
  let right = sortedArray.length - 1;

  while (left <= right) {
    const mid = Math.floor((left + right) / 2);
    
    if (sortedArray[mid] === target) {
      return mid; // Target found at index
    }
    if (sortedArray[mid] < target) {
      left = mid + 1; // Discard left half
    } else {
      right = mid - 1; // Discard right half
    }
  }
  return -1; // Target not found
}

Frequently Asked Questions

What is pseudocode?

Pseudocode is an informal, human-readable outline of an algorithm's logic that mimics code structure without adhering to the strict syntax rules of any specific programming language.