Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider a directed graph with n vertices and... Start Learning for Free
Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?
  • a)
    O(m+n)
  • b)
    O(m logn)
  • c)
    O(mn)
  • d)
    O(n logm)
Correct answer is option 'A'. Can you explain this answer?
Most Upvoted Answer
Consider a directed graph with n vertices and m edges such that all ed...
It’s a special case in which all edge weights are equal, so dfs would work and resultant depth first tree would be the spanning tree. So the answer would be O(m+n).
Free Test
Community Answer
Consider a directed graph with n vertices and m edges such that all ed...
Algorithm to Compute Minimum Spanning Tree

The minimum spanning tree (MST) of a graph is a tree that connects all the vertices of the graph with the minimum possible total edge weight. The algorithm to compute the MST of a graph can be implemented using different approaches, such as Kruskal's algorithm and Prim's algorithm.

Kruskal's Algorithm

Kruskal's algorithm is a greedy algorithm that selects the minimum-weight edge in each iteration and adds it to the MST if it does not create a cycle. The algorithm maintains a forest of trees, where each vertex is initially in its own tree. The algorithm repeatedly selects the minimum-weight edge that connects two trees and merges the trees into one. The algorithm stops when there is only one tree left, which is the MST.

The time complexity of Kruskal's algorithm is O(m log m), where m is the number of edges in the graph. This is because the algorithm sorts the edges in non-decreasing order of weight, which takes O(m log m) time using a sorting algorithm such as quicksort.

Prim's Algorithm

Prim's algorithm is also a greedy algorithm that builds the MST one vertex at a time. The algorithm starts with an arbitrary vertex and adds the minimum-weight edge that connects the tree to a vertex that is not yet in the tree. The algorithm maintains a set of vertices that are in the tree and a set of vertices that are not yet in the tree. In each iteration, the algorithm adds the minimum-weight edge that connects a vertex in the tree to a vertex outside the tree and adds the vertex to the tree. The algorithm stops when all vertices are in the tree, which is the MST.

The time complexity of Prim's algorithm is O(m log n), where n is the number of vertices in the graph. This is because the algorithm uses a priority queue to select the minimum-weight edge in each iteration, which takes O(log n) time for each edge. The total time for all edges is O(m log n).

Answer to the Question

The given graph has m edges with the same weight, so Kruskal's algorithm can be modified to have a time complexity of O(m n). In this modified algorithm, the edges are not sorted, and the minimum-weight edge is found by iterating over all edges. Since all edges have the same weight, iterating over all edges takes O(m) time. The algorithm maintains a forest of trees and repeatedly selects the minimum-weight edge that connects two trees and merges the trees into one. The algorithm stops when there is only one tree left, which is the MST.

Therefore, the correct answer is option 'A', O(m n).
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Question Description
Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?a)O(m+n)b)O(m logn)c)O(mn)d)O(n logm)Correct answer is option 'A'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?a)O(m+n)b)O(m logn)c)O(mn)d)O(n logm)Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?a)O(m+n)b)O(m logn)c)O(mn)d)O(n logm)Correct answer is option 'A'. Can you explain this answer?.
Solutions for Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?a)O(m+n)b)O(m logn)c)O(mn)d)O(n logm)Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?a)O(m+n)b)O(m logn)c)O(mn)d)O(n logm)Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?a)O(m+n)b)O(m logn)c)O(mn)d)O(n logm)Correct answer is option 'A'. Can you explain this answer?, a detailed solution for Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?a)O(m+n)b)O(m logn)c)O(mn)d)O(n logm)Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?a)O(m+n)b)O(m logn)c)O(mn)d)O(n logm)Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?a)O(m+n)b)O(m logn)c)O(mn)d)O(n logm)Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev