An algorithm is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computation. They are the fundamental building blocks of any piece of software.

Key aspects include:

  • Efficiency: How well it performs in terms of time and memory ($O(n)$).
  • Correctness: Whether it produces the correct output for all valid inputs.
  • Design Patterns: Common approaches like divide and conquer, dynamic programming, or greedy algorithms.
Algorithms