Exercise Lover

June 20, 2007

Exercises 22.2-8

Filed under: 22.2 — yuhanlyu @ 3:05 pm

We can modify BFS to traverse edge (u,v) twice. The first time is the tree edge (u,v), and the second time is (v,u).

Exercises 22.2-7

Filed under: 22.2 — yuhanlyu @ 2:59 pm

BFS from one node s and we can get a node u with maximum d value. Then do BFS from u, find out the node v with maximum d value. It is the solution.

Exercises 22.2-6

Filed under: 22.2 — yuhanlyu @ 2:53 pm

The problem is the same as recognizing bipartite graph. Set a node s as good guy, than all its rivals are bad guys. All bad guys’ rivals must be good guys. If there exists one pair violates this constraint then return No, otherwise return Yes.

Exercises 22.2-5

Filed under: 22.2 — yuhanlyu @ 2:37 pm

G = ({s,u,v,w,x}, {(s,u),(s,v),(u,w),(v,x),(u,x),(v,w)}). E_{\pi} = {(s,u),(s,v),(u,w),(v,x)}.

Exercises 22.2-4

Filed under: 22.2 — yuhanlyu @ 2:31 pm

Because d[u] is the distance from s to u, it must be unique. But the BFS tree depends on the order in the adjacency list.

Exercises 22.2-3

Filed under: 22.2 — yuhanlyu @ 2:30 pm

O(V^2).

Exercises 22.2-2

Filed under: 22.2 — yuhanlyu @ 2:29 pm

Exercises 22.2-1

Filed under: 22.2 — yuhanlyu @ 2:28 pm

Blog at WordPress.com.