CMSC250

Structual Induction

Structual Indcution

Induction Recap
Structual Induction

Induction Recap

def weak(a):
  if a ==0:
    return 1
  return 2 * weak(a-1)

Claim: weak(\(n\)) = \(2^n\)

Assumption: for some $k \ge n_0, weak(k) = 2^k$

Want to prove: $weak(k+1) = 2^{k+1}$

$P(k+1)$ relies on $P(k)$

 public int strong(int n){
  if(n==0) return 3;
  if(n==1) return 4;
  return -n + strong(n-1) + strong(n-2);
}

Claim: $strong(n) = n + 3$

Assumption: $\forall i, k \ge i \ge n_0, strong(i) = i + 3$, for some $k\in \mathbb{Z}$

Want to prove: $strong(k+1) = {k+1}+3$

$P(k+1)$ relies on $P(k)$ and $P(k-1)$

Recall: We said induction was where we show $\forall n\in \mathbb{Z}^{\ge 0}, P(n)$

Structual induction: For all recursively defined structures $x$, $x$ has some property $p$

Weak and Strong: $P(n_0), P(n_0 + 1), P(n_0 +2), \ldots$

Structual: $P(n_0), P(n_1), P(n_2), \ldots$

Structual Induction - Sets

Let $S$ be a set

  • $1 \in S$
  • If $x \in S$, then $2x \in S$

Claim: $\forall z \in S, z$ is an Integer power of 2

Base case: $1 \in S$ and $1 = 2^0$

IH: Suppose that $k \in S$ and $k$ is an integer power of 2

IS: WTP that $2k$ is a power of 2

Let $S$ be a set

  • $(0,0) \in S$
  • If $(x,y) \in S$, then $(x,y+1),(x+1,y+1),(x+2,y+1) \in S$

Claim: $\forall (a,b) \in S, a \le 2b$

Base case: $(0,0) \in S$ and $0 \le 2(0)$

IH: Suppose that $(p,q) \in S$ and $p \le 2q$

IS: WTP that $p \le 2(q+1), p+1 \le 2(q+1), p+2 \le 2(q+1)$

Let $S$ be a set

  • $"X" \in S$
  • If $a \in S$, then $YaY \in S$

Claim: $\forall x \in S, x$ is a palindrome

Base case: $"X" \in S$ and $X$ is a palindrome

IH: Suppose that $k \in S$ and $k$ is a palindrome

IS: WTP that for some string $a \in S, YaY$ is a palindrome

Structual Induction - Trees

Let $T$ be a binary tree

Claim: for any binary tree $T, L(T)\le 2^{H(T)}$

Base case: Singular node has height 0 and 1 leaf. $1 \le 2^0$

Recall the definition:

If $T_1$ and $T_2$ are trees, we can make a new Tree by making a new node, and attaching $T_1$ and $T_2$

If $T_1$ is a tree, we can make a new Tree by making a new node, and attaching $T_1$ as a branch

Let $T$ be a binary tree

Claim: for any binary tree $T, L(T)\le 2^{H(T)}$

Base case: Singular node has height 0 and 1 leaf. $1 \le 2^0$

IH: Suppose we have a Tree $T$ where $L(T)\le 2^{H(T)}$

IH: Suppose we have Trees $T_1, T_2$ where $L(T_1)\le 2^{H(T_1)}, L(T_2)\le 2^{H(T_2)}$

IS: We add a parent node

Let $T$ be a binary tree

Claim: for any binary tree $T, N(T)\le 2^{H(T)+1}-1$

Base case: Singular node has height 0, $1 \le 2^{0+1}-1$

IH: Suppose we have a Tree $T$ where $N(T)\le 2^{H(T)+1}-1$

IH: Suppose we have Trees $T_1, T_2$ where $N(T_1)\le 2^{H(T_1)+1}-1, N(T_2)\le 2^{H(T_2)+1}-1$

IS: We add a parent node

Not Limited to Trees and Sets

Consider a $2n$ x $2n$ grid for some $n \in \mathbb{Z}^{\ge 1}$

Claim, I can cover any $2n$ x $2n$ grid with a 'L' shaped piece of 3 units