6.1210 Introduction to Algorithms

Jun 12, 20261 min

Definition of an algorithm

An algorithm is a procedure for solving a computational problem.

  • In this class, we want algorithms that are correct and efficient.

An algorithm is correct when it gives a correct answer for every possible input. An algorithm is efficient if it uses few resources (number of operations, memory, etc.).

Efficiency

  • πŸ”‘ We measure resource usage asymptotically as a function of the input size.
  • πŸ“ We start with worst-case analysis: for all input of the same size nn, we measure the resources used on the worst possible input.
    • Later in the course, we discuss average-case analysis.
  • For an algorithm AA, we denote the runtime of AA on the worst input of size nn as T(n)T(n)

Asymptotic notation

  1. Upper bounds: AA has worst-case runtime O(f(n))O(f(n)) iff there exists a constant c>0c>0 and n0β‰₯1n_0 \geq 1 such that, for all n>n0n > n_0, and for every input xx of length nn, algorithm AA uses no more than cβ‹…f(n)c \cdot f(n) operations on input xx. [similar structure to the definition of convergence in real analysis?]
  2. Lower bounds: AA has worst-case runtime Ξ©(f(n))\Omega(f(n)) iff there exists a constant c>0c>0 and n0β‰₯1n _0 \geq 1 such that, for all n>n0n > n_0, there exists an input xx of length nn, such that algorithm AA uses at least cβ‹…f(n)c \cdot f(n) operations on input xx.