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
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...
Find the worst-case complexity of the algorithm below. Show your work. UFSizeCalc Input:  uf: Union-Find array of...
Find the worst-case complexity of the algorithm below. Show your work. UFSizeCalc Input:  uf: Union-Find array of size n Input: n: size of uf Output: size array for uf; that is, an array s such that s[r] equals the number of elements in the Union-Find tree rooted at r, for every root r (s may have any value for indexes that are not roots of uf) Pseudocode: For i = 1 to n uf.Find(i) size = Array(n) Initialize size to be...
You are given a directed acyclic graph G(V,E), where each vertex v that has in-degree 0...
You are given a directed acyclic graph G(V,E), where each vertex v that has in-degree 0 has a value value(v) associated with it. For every other vertex u in V, define Pred(u) to be the set of vertices that have incoming edges to u. We now define value(u) = ?v∈P red(u) value(v). Design an O(n + m) time algorithm to compute value(u) for all vertices u where n denotes the number of vertices and m denotes the number of edges...