Finding an MST among all spanning trees with maximum of white edges

686 Views Asked by At

Let an undirected graph $G=(V,E)$ with the color property $c(e)$ for every edge (could be black or white) and a weight property $1 \le w(e) \le 100$. Find the MST from the set of all spanning trees with the maximum number of white edges. Do it in linear time ($O(|V|+|E|$).

So basically I want to utilize Prim's algorithm; Suppose the heaviest weight of all white edges is $WMAX$ then we can add this value for every black edge's weight. Now, white edges will be prioritized over black edges.

Now, Prim's algorithm complexity time is defined by it's priority queue implementation. Therefore, I need to use an array of lists (I guess) with a fixed size.

We can maintain a pointer to the minimum value so extraction could be done in $O(1)$ but what about the DECREASE-KEY operation?

To conclude,
How should I implement the priority queue in order to keep it linear?

1

There are 1 best solutions below

0
On BEST ANSWER

Since $0 \leq w(e) \leq 100$ you can use a modified bucket queue as priority queue. For each possible edge weight $w$ you keep a list $A[w]$ of nodes with key $w$. Minimum value extraction can then be accomplished in $\mathcal{O}(100)$ by iterating $w$ from $0$ to $100$ and returning the first element of the first non empty list $A[w]$.

Assume that a node $v$ has key $w$ and a decrease key operation is performed to update the key to $\tilde{w} < w$. Then $v$ must be removed from $A[w]$ (can be done in $\mathcal{O}(1)$ if, for example, linked lists are used and each node stores a pointer to its position in the list) and inserted into $A[\tilde{w}]$ (can again be accomplished in $\mathcal{O}(1)$).

In order to prioritize white edges, you could modify the insertion into the lists such that white edges are always inserted at the front and black edges at the back of a list.