# CMPSCI 311: Theory of Algorithms

### from Wednesday 10 Sept 2003

Here we review the method of proof by induction from CMPSCI 250. Please answer the questions during the discussion period.

• Question 1: The family of undirected graphs {K_n: n≥ 1} is defined as follows. K1 is a single node with no edges. Kn+1 consists of a copy of Kn plus one new node, with an edge from the new node to each of the old nodes. Prove by induction on all n≥1 that there are exactly n(n-1)/2 edges in Kn.

• Question 2: A forest is an undirected graph with no cycles. For all n, prove by induction on all e from 0 through n-1 that a forest with n nodes and e edges has exactly n-e connected components.

• Question 3: A full rooted binary tree or FBRT of depth d, with d≥0, is defined as follows. An FRBT of depth 0 is a single node (its root) with no edges. An FBRT of depth d+1 consists of two FBRT's of depth d plus a new node, its root, and new directed edges from the root to the roots of the depth-d trees. Prove by induction on d that a depth-d FBRT has exactly 2d+1-1 nodes and exactly 2d+1-2 edges.

• Question 4: You are proving on HW#1 that if a and b are non-negative integers with a > b, and c is the remainder when a is divided by b, then gcd(a,b) = gcd(b,c). Using this fact, prove by strong induction on the number a+b that the Euclidean algorithm terminates with the correct greatest common divisor when started on inputs a and b. Assume the following recursive Java-like code is being used for gcd:

``````      int gcd (int a, int b)
{  //assumes a > b >= 0
if (b == 0) return a;
else return gcd (b, a%b);}
``````