Question

Analyze the worst-case complexity of the algorithm below when using an optimized adjacency list to store...

Analyze the worst-case complexity of the algorithm below when using an optimized adjacency list to store G.

ComponentCount:

Input: G = (V, E): an undirected graph with n vertices and m edges

Input: n, m: the order and size of G, respectively

Output: the number of connected components in G

Pseudocode:

comp = n

uf = UnionFind(n)

For v in V:

    For u in N(v):

        If (uf.Find(v) != uf.Find(u))

            uf.Union(u, v)

            comp = comp - 1

        End if

    End for

End for

Return comp

Homework Answers

Answer #1

Answer:-

comp = n

uf = UnionFind(n) // O(log V)

For v in V: // O(V)

    For u in N(v): // O(V) in worst case

        If (uf.Find(v) != uf.Find(u))

            uf.Union(u, v)

            comp = comp - 1

        End if

    End for

End for

Return comp

The total time complexity in worst case is = O(V*V*logV)

i.e O(V^2logV)

Please UPVOTE thank you...!!!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT