# Practice Exam for Third Midterm Exam

### Directions:

• Answer the problems on the exam pages.
• There are four problems for 100 total points. Approximate scale would be A=90, C = 54.
• If you need extra space use the back of a page.
• No books, notes, calculators, or collaboration.

```  Q1: 20 points
Q2: 35 points
Q3: 30 points
Q4: 15 points
Total: 100 points
```

• Question 1 (20): Let G be the following undirected graph. The vertex set is {a,b,c,d,e,f} and the edge set is {(a,b), (a,d), (a,f), (b,c), (c,d), (d,e), (e,f)}. Draw depth-first and breadth-first search trees for G, including the non-tree edges in your picture and distinguishing them from the tree edges. (When adding vertices to the open list, add them in alphabetical order.)

• Question 2 (35): Recall that a rooted directed tree is defined to be either (a) a single node, a leaf, or (b) a root node with edges to the roots of one or more other rooted directed trees. Suppose we are given a rooted directed tree where each leaf is labeled with a natural number, and we want to find the maximum value of all these leaf values.
• (a,15) Describe a recursive algorithm to find this maximum value, using English or pseudo-Java or some combination. Your algorithm should follow the definition of rooted directed trees, having a base case for leaves and using recursion on subtrees if the given tree has subtrees.
• (b,20) Prove by induction on trees that your algorithm returns the correct maximum value whenever the input is a tree. (Recall the induction method for rooted directed trees -- if P(v) is true whenever v is a leaf, and P(v) is true whenever P(w) is true for every child w of v, then P(v) is true for all nodes in the tree.)

• Question 3 (30): Consider the following directed multigraph G where the node set is {1,2} and the edges have names as follows: edge a goes from 1 to 1, edges b and c both go from 1 to 2, and edge d goes from 2 to 1.
• (a,5) Give the natural-number matrix A for G, where the (i,j) entry says how many edges go from i to j.
• (b,10) How many four-step paths go from vertex 1 to vertex 2? Calculate this number using your matrix, and list the paths as sequences of four edges.
• (c,10) Suppose we view the matrix A as being over the integers modulo 5 rather than over the naturals. Find the matrix A4 over this semiring and explain what each of its four entries mean.
• (d,5) Is the number of 400-step paths from 1 to 2 in G divisible by 5? Explain your answer.

• Question 4 (15): Suppose I have a directed graph G where each node has at most two edges out of it and let s be a particular node of G. Prove that for any natural d, the number of nodes that are reachable from s by paths of length at most d is at most 2d+1-1. (Hint: Use ordinary induction on d.)