{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Midterm1

# Midterm1 - Solutions to Midterm 1 Peng Du University of...

This preview shows pages 1–3. Sign up to view the full content.

Solutions to Midterm 1 Peng Du University of California, San Diego 1 (10 points) 1.1 Part (a) The DFS forest is showed in Fig. 1 where pre and post numbers are written in the form [pre,post] beside each node. a b c f d e h g i [1,2] [3,6] [9,18] [7,8] [4,5] [14,15] [12,13] [11,16] [10,17] Fig. 1. The DFS forest. 1.2 Part (b) The shortest path tree is showed in Fig. 2 where the distances are written next to each node. 2 (10 points) 2.1 Part (a) Polynomial time. We only need to output all nodes with zero in-degrees, which takes O ( | V | + | E | ) time. 2.2 Part (b) Exponential time. We have proved in homework 2-4 that graphs can have expo- nentially many cycles. It takes the computer at least exponential time to output all of them.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 a b c e d f h g i 0 6 7 8 5 8 1 3 7 Fig. 2. The shortest path tree. 2.3 Part (c) Exponential time. There are n ! many topological orderings for a graph with n nodes and no edges. Since n ! > 2 n when n is large enough, we need at least exponential time to output all of them. 3 (10 points) 3.1 Part (a) Just find the SCC with largest number of nodes. Please refer to section 3.4 of the book for the time complexity. 3.2 Part (b) One way of doing this is brute force. For each
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

Midterm1 - Solutions to Midterm 1 Peng Du University of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online