Question: You have an undirected graph G = ( V , E ) and two special nodes r , dinV. At time 0 , node r
You have an undirected graph and two special nodes dinV. At time node is
republican, node is democratic, while all the other nodes are initially "undecided".
For every dots, the following stage "conversion" process is performed at time time At
the first stage, all republicans at time look at all their neighboring nodes which are still
undecided, and convert those undecided nodes to become republican. Similarly, at the second stage,
all democratic nodes at time look at all their neighboring nodes which are still undecided
by the end of the first stage above, and convert those undecided nodes to become democratic. The
process is repeated until no new conversions can be made. For example, if is a cycle
where after time node becomes republican and node becomes democratic, and
after time the last remaining node becomes republican as republicans move first On the
other hand, if the initial democratic node was instead, then already after step nodes and
become republican, and node becomes democratic, and no step is needed.
Assume each node have a field vcolor, where red means republican, blue means democratic,
and purple means undecided, so that, at time rcolor red, dcolor blue, and all other nodes
have color purple.
a points Using two BFS calls, show how to properly fill the final color of each node.
b points Show how to speed up your procedure in part a by a factor of or more,
depending on your implementation by directly modifying the BFS procedure given in the
book. Namely, instead of computing distances from the root node, you are computing the final
colors of each node, by essentially performing a single, appropriately modified BFS traversal
of Please write pseudocode, as it is very similar to the standard BFS pseudocode, and is
much easier to grade. Briefly argue your code's correctness and running time.
c points Now assume that at time more than one node could be republican or democratic.
Namely, you are given as inputs some disjoint subsets and of where nodes in are
initially republican and nodes in are initially democratic, but otherwise the conversion
process is the same. For concreteness, assume for some so that parts
a and b correspond to Show how to generalize your solutions in parts a and b
to this more general setting. Given parts a and b took time with different
constants how long would their modifications take as a function of Which
procedure gives a faster solution?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
