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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Soution Pseudocode compon uf - Union find (n) for v in vi for u in N(O): # here NGOs means neighbour of v . if ( uf. Find (u)plz like it

Add a comment
Know the answer?
Add Answer to:
Analyze the worst-case complexity of the algorithm below when using an optimized adjacency list to store...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3. (10 points) Let G be an undirected graph with nodes vi,..Vn. The adja.- cency matriz represent...

    Please show work clearly. Thanks 3. (10 points) Let G be an undirected graph with nodes vi,..Vn. The adja.- cency matriz representation for G is the nx n matrix M given by: Mij-1 if there is an edge from v, to ty. and M,',-0 otherwise. A triangle is a set fvi, vjof 3 distinct vertices so that there is an edge from v, to vj, another from v to k and a third from vk to v. Give and analyze...

  • 2. Let G = (V, E) be an undirected connected graph with n vertices and with...

    2. Let G = (V, E) be an undirected connected graph with n vertices and with an edge-weight function w : E → Z. An edge (u, v) ∈ E is sparkling if it is contained in some minimum spanning tree (MST) of G. The computational problem is to return the set of all sparkling edges in E. Describe an efficient algorithm for this computational problem. You do not need to use pseudocode. What is the asymptotic time complexity of...

  • 3. The indegree of a vertex u is the number of incoming edges into u, .e, edges of the form (v,u)...

    3. The indegree of a vertex u is the number of incoming edges into u, .e, edges of the form (v,u) for some vertex v Consider the following algorithm that takes the adjacency list Alvi, v2, n] of a directed graph G as input and outputs an array containing all indegrees. An adjacency list Alvi, v.. /n] is an array indexed by the vertices in the graph. Each entry Alv, contains the list of neighbors of v) procedure Indegree(Alvi, v2,......

  • Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the gr...

    Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the graph is the set of all nodes that are adjacent (or directly connected) to v. Subsequently, we can define the neighbourhood degree of the node v as the sum of the degrees of all its neighbours (those nodes that are directly connects to v) (a) Design an algorithm that returns a list containing the neighbourhood degree for each node v V,...

  • Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the gr...

    This question needs to be done using pseudocode (not any particular programming language). Thanks Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the graph is the set of all nodes that are adjacent (or directly connected) to v. Subsequently, we can define the neighbourhood degree of the node v as the sum of the degrees of all its neighbours (those nodes that are directly connects to v) (a) Design an...

  • Problem 6. (Weighted Graph Reduction) Your friend has written an algorithm which solves the all pairs shortest path pr...

    Problem 6. (Weighted Graph Reduction) Your friend has written an algorithm which solves the all pairs shortest path problem for unweighted undirected graphs. The cost of a path in this setting is the number of edges in the path. The algorithm UNWEIGHTEDAPSP takes the following input and output: UNWEİGHTEDA PSP Input: An unweighted undirected graph G Output: The costs of the shortest paths between each pair of vertices fu, v) For example, consider the following graph G. The output of...

  • 4.1 4.1 Insertion Sort 4. Design 137 the a algorithm for generating the power set of...

    4.1 4.1 Insertion Sort 4. Design 137 the a algorithm for generating the power set of a set of n elements. (The power set of a set s is the set of all the subsets of S,including empty set and S itself.) 5. Consider the following algorithm to check connectivity of graph defined by adjacency a ALGORITHM Connected (A 0...n-1, 0..n ij) Input: Adjacency matrix Alo..n 1,0. n -1) of an undirected graph G //Output: 1 (true) if G is...

  • Exercise 7.3.5: Worst-case time complexity - mystery algorithm. The algorithm below makes some changes to an...

    Exercise 7.3.5: Worst-case time complexity - mystery algorithm. The algorithm below makes some changes to an input sequence of numbers. MysteryAlgorithm Input: a1, a2....,an n, the length of the sequence. p, a number Output: ?? i != 1 j:=n While (i < j) While (i <j and a < p) i:= i + 1 End-while While (i <j and a 2 p) j:=j-1 End-while If (i < j), swap a, and a End-while Return( aj, a2,...,an) (a) Describe in English...

  • What is the worst-case asymptotic time complexity of the following divide-andconquer algorithm (give a Θ-bound). The...

    What is the worst-case asymptotic time complexity of the following divide-andconquer algorithm (give a Θ-bound). The input is an array A of size n. You may assume that n is a power of 2. (NOTE: It doesn’t matter what the algorithm does, just analyze its complexity). Assume that the non-recursive function call, bar(A1,A2,A3,n) has cost 3n. Show your work! Next to each statement show its cost when the algorithm is executed on an imput of size n abd give the...

  • What is the worst-case asymptotic time complexity of the following divide-andconquer algorithm (give a Θ-bound). The...

    What is the worst-case asymptotic time complexity of the following divide-andconquer algorithm (give a Θ-bound). The input is an array A of size n. You may assume that n is a power of 2. (NOTE: It doesn’t matter what the algorithm does, just analyze its complexity). Assume that the non-recursive function call, bar(A1,A2,A3,n) has cost 3n. Show your work! Next to each statement show its cost when the algorithm is executed on an imput of size n abd give the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT