Introduction to Algorithms

Definitions

Problem: A set consisting of pairs of $(x, S)$, where

e.g. $\textsf{Mul} = {((x,y), {xy}) \mid x,y \in \mathbb{R}}$ means the problem $\textsf{Mul}$ is the set of all inputs $x,y$ with the set of their product $xy$.

How would you define the problem $\textsf{Factor}$?

Algorithm: Procedure that outputs a valid solution to a problem given some input.

In this module we mainly care about algorithms’

Computational Model: Defines

Adversary Arguments

These are used to prove lower bounds of runtime, i.e. There exists no algorithm $M$ that solves $\textsf{Problem}$ in less than some runtime.

Adversary. Input model that returns the worst case answer for any operation the algorithm may perform.

Outline of proving algorithmic lower bounds $L$

Theorem. Show that any algorithm solving (insert problem) has runtime $ge$ (insert runtime) by the (insert comparison model).

  1. Come up with a representation model the adversary can visualize the state of the problem with. (Graph, tree, etc.) The Algorithm is constructing this representation model with each query.
  2. For each operation, the adversary must set the input such that the operation is as least informative as possible.
  3. Suppose some algorithm with runtime $<$ given amount outputs the correct answer for some input. Then in another modified input, the same algorithm will return the same answer but would be wrong.

For the Zero-One problem

Let $\textsf{Zero-One}$ bef the problem: given an array $A$ of size $n$ of 0s and 1s, determine if there are more 0s than 1s in the array.

Theorem. Any algorithm solving $\textsf{Zero-One}$ has runtime $\ge n$ by the query model (each query = one time unit).

Proof. Suppose there exists an algorithm $\mathcal{M}$ which solves $\textsf{Zero-One}$ in time $< n$ with the query model.

  1. [Can omit]
  2. Let array $A$ be an array of size $n$ where $n$ is odd.
  3. $\mathcal{M}$ cannot distinguish between $A, A’$.

For the Maximum problem

Let $\textsf{Max}$ be the problem: given an array $A$ of numbers, return the number with maximum value in $A$.

Theorem. Any algorithm solving $\textsf{Max}$ has runtime $\ge n - 1$ by the comparison model (each comparison between 2 elements = one time unit).

Proof. Suppose there exists an algorithm $\mathcal{M}$ which solves $\textsf{Max}$ in time $< n - 1$ with the comparison model.

  1. Construct a graph of $n$ nodes where each node corresponds to an index.
  2. [Can omit] For $n-1$ comparisons, the adversary can respond with either Yes or No to the comparison “Is $i < j$?”
  3. After any $m < n-1$ comparisons, note that the graph is still disconnected.

\(A'_i = \begin{cases} A_i & \text{if $i \in C_1$} \\ A_i + m & \text{if $i \in C_2$} \\ \end{cases}\)

For the Sorting problem

Let $\textsf{Sort}$ be the problem: given an array $A$ of numbers, return the same array but in sorted order $B$ such that $B_1 < B_2 < \dots < B_n$.

Theorem. Any algorithm solving $\textsf{Sort}$ has runtime $\ge \log(n!)$ by the comparison model.

Proof. Suppose there exists an algorithm $\mathcal{M}$ which solves $\textsf{Max}$ in time $< n - 1$ with the comparison model.

  1. Let the set $U$ be the set of all the possible permutated inputs of the indices of $A$.
  2. Let $U_i$ be the number of valid inputs consistent with the previous $i$ comparisons made by the algorithm.

\(U_{i+1} = \begin{cases} U_{i, A_j < A_k} & \text{if $\|U_{i, A_j < A_k}\| \ge \|U\|/2 $ } & \text{(YES)}\\ U_{i, A_j \ge A_k} & \text{if $\|U_{i, A_j \ge A_k}\| \ge \|U\|/2 $ } & \text{(NO)} \end{cases}\)

For the connected graph problem

Let $\textsf{Conn}$ be the problem: given an graph $G$ of size $n$ nodes, determine if the graph is connected.

Theorem. Any algorithm solving $\textsf{Conn}$ has runtime $\ge {n \choose 2}$ by the query model (each query = one time unit).

Proof. Suppose there exists an algorithm $\mathcal{M}$ which solves $\textsf{Conn}$ in time $L < {n \choose 2}$ with the query model.

  1. [Can omit]
  2. Let graph $G$ be the input graph of $n$ nodes.
  3. $\mathcal{M}$ cannot distinguish between $G, G’$.