Rudolf Adamkovič Personal site


Proof of complexity claims

Statements.

BFS runs in exponential time \(\mathcal{O}(b^{d + 1})\), where

BFS runs in linear time \(\mathcal{O}(|V| + |E|)\), where

Objective.

Prove the above statements equivalent for any complete graph \(K_n\).

Proof.

Lemma 1. Given \(|V| = n\), prove \(\mathcal{O}(|V| + |E|) = \mathcal{O}(n^2)\).

For any \(K_n\),

\[\begin{align*}
  |V| = n \> \iff \> |E| = \frac{n(n - 1)}{2},
\end{align*}
\]

and so

\[\begin{align*}
  \mathcal{O}(|V| + |E|)
  & = \mathcal{O}(|V|) + \mathcal(|E|)
  && \text{distribute \(\mathcal{O}\)}
  \\[1ex]
  & = \mathcal{O}(n) + \mathcal{O} \big( n(n - 1) / 2 \big)
  && \text{substitute \(|V|\) and \(|E|\)}
  \\[1ex]
  & = \mathcal{O}(n) + \mathcal{O} \big( (n^2 - n) / 2 \big)
  && \text{distribute \(n\)}
  \\[1ex]
  & = \mathcal{O}(n) + \mathcal{O} \big( (1/2) (n^2 - n) \big)
  && \text{split fraction}
  \\[1ex]
  & = \mathcal{O}(n) + \mathcal{O} \big( (1 / 2) n^2 - (1 / 2) n \big)
  && \text{distribute \(1/2\)}
  \\[1ex]
  & = \mathcal{O}(n) +
    \mathcal{O}\big((1 / 2) n^2 \big) -
    \mathcal{O}\big((1 / 2) n \big)
  && \text{distribute \(\mathcal{O}\)}
  \\[1ex]
  & =
    \mathcal{O}(n) +
    \mathcal{O} \big( 1/2 \big) \, \mathcal{O} \big( n^2 \big) -
    \mathcal{O} \big( 1/2 \big) \, \mathcal{O} \big (n \big)
  && \text{distribute \(\mathcal{O}\)}
  \\[1ex]
  & =
    \mathcal{O}(n) +
    \mathcal{O}(1) \, \mathcal{O}(n^2) -
    \mathcal{O}(1) \, \mathcal{O}(n)
  && \text{standardize}
  \\[1ex]
  & = \mathcal{O}(n^2).
  && \text{simplify}
\end{align*}
\]

Lemma 2. Given \(|V| = n\), prove \(\mathcal{O}(b^{d + 1}) = \mathcal{O}(n^2)\).

In any \(K_n\), all vertices are of degree \(n - 1\) and adjacent, so

\[b = n - 1 \qand d = 1,
\]

respectively, which gives

\[\begin{align*}
  \mathcal{O}(b^{d + 1})
  & = \mathcal{O} \big( (n - 1)^{1 + 1} \big)
  && \text{substitute \(b\) and \(d\)}
  \\[1ex]
  & = \mathcal{O} \big( (n - 1)^2 \big)
  && \text{combine like terms}
  \\[1ex]
  & = \mathcal{O} \big( (n - 1)(n - 1) \big)
  && \text{take square}
  \\[1ex]
  & = \mathcal{O} \big( n^2 - 2n + 1 \big)
  && \text{multiply binomials}
  \\[1ex]
  & = \mathcal{O}(n^2) - \mathcal{O}(2n) + \mathcal{O}(1)
  && \text{distribute \(\mathcal{O}\)}
  \\[1ex]
  & = \mathcal{O}(n^2) - \mathcal{O}(n) + \mathcal{O}(1)
  && \text{standardize}
  \\[1ex]
  & = \mathcal{O}(n^2).
  && \text{simplify}
\end{align*}
\]

Given Lemma 1 and Lemma 2,

\[\begin{align*}
  \mathcal{O}(|V| + |E|) & \stackrel{?}{=} \mathcal{O}(b^{d + 1}) \\
  \mathcal{O}(n^2) & \stackrel{\checkmark}{=} \mathcal{O}(n^2).
  \quad \blacksquare
\end{align*}
\]

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.