Do not hand in Part A. And for Part E, solve the problem below rather than what appears on the original handout.
Assume that all operations in Graph and SetOfInts are O(1). (Examples are removing an integer from a SetOfInts, and adding an edge to a Graph.) Also, assume that there are n vertices in the Graph.
Answer the following questions:
For your convenience, here is the algorithm. Analyze this, not your own Java code!
// Colours are 0,1
// Precondition: every vertex v has been initialized
// so that v.colour == -1.
Algorithm 2-colour(Graph <V,E>)
S = V ;
while (S not empty) {
Pick one vertex v in S and remove it from S ;
v.colour = 1 ;
C = {v} ;
while ( C not empty ) {
Pick one vertex u in C and remove it from C ;
for ( each vertex w adjacent to u ) {
if ( w.colour == -1 ) {
Remove w from S ;
w.colour = 1 - u.colour ;
C = C union {w} ;
else if ( w.colour == u.colour ) {
return false ;
}
}
}
}
return true ;
end 2-colour