hw5solns - CMPS 101 Summer 2009 Homework Assignment 5...

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

View Full Document Right Arrow Icon
1 CMPS 101 Summer 2009 Homework Assignment 5 Solutions 1. (3 Points) p. 538: 22.2-2 Show the d and π values that result from running breadth-first search on the undirected graph below using the following vertices as source. For each source, show the order in which vertices are added to the Queue, and show the state of the BFS tree after execution completes. Assume adjacency lists are processed in alphabetical order. r s t u v w x y a. (1 Point) Let vertex u be the source Solution: vertex adjacency list d r s v 4 s s r w 3 w t u w x 1 u u t x y 0 nil v r 5 r w s t x 2 t x t u w y 1 u y u x 1 u Queue: u t x y w s r v BFS Tree u t x y w s r v b. (1 Point) Let vertex w be the source Solution: vertex adjacency list d r s v 2 s s r w 1 w t u w x 1 w u t x y 2 t v r 3 r w s t x 0 nil x t u w y 1 w y u x 2 x Queue: w s t x r u y v BFS Tree w s t x r u y v
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 c. (1 Point) Let vertex v be the source Solution: vertex adjacency list d π r s v 1 v s r w 2 r t u w x 4 w u t x y 5 t v r 0 nil w s t x 3 s x t u w y 4 w y u x 5 x Queue: v r s w t x u y BFS Tree v r s w t x u y 2. (1 Point) p. 538: 22.2-6 There are two types of professional wrestlers: “good guys” and “bad guys.” Between any pair of professional wrestlers, there may or may not be a rivalry. Suppose we have n professional wrestlers and we have a list of r pairs of wrestlers for which there are rivalries. Give an ( ) O n r + -time algorithm that determines whether it is possible to designate some of the wrestlers as good guys and the remainder as bad guys such that each rivalry is between a good guy and a bad guy. If it is possible to perform such a designation, your algorithm should produce it. (Hint: figure out how to use BFS to solve this problem.) Solution: Let the n wrestlers be the vertices of an undirected graph in which two vertices are joined by an edge if and only if there is a rivalry between the corresponding wrestlers. The question asks whether it is possible to partition the vertex set into two subsets Good and Bad such that all edges join Good vertices to Bad vertices. Such a graph is called bipartite . More precisely, an undirected graph ) , ( E V G = is called bipartite if its vertex set V can be partitioned into two subsets X and Y such that every edge has one end in X and the other end in
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/03/2009 for the course CS CS101 taught by Professor Agoreback during the Spring '09 term at American College of Gastroenterology.

Page1 / 6

hw5solns - CMPS 101 Summer 2009 Homework Assignment 5...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online