Kruskal’s Minimum Spanning Tree Algorithm Problem Statement

You are given a connected undirected weighted graph. Your task is to determine the weight of the minimum spanning tree of this graph.

A minimum spanning tree (MST) is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices without any cycles and with the minimum total edge weight. The weight of a spanning tree is the sum of the weights of the edges in that tree.

Input:

The first line contains an integer ‘T’, denoting the number of test cases. Each test case includes: 
  
  • The first line contains two integers ‘N’ and ‘M’, representing the number of nodes and edges respectively.
  • The subsequent ‘M’ lines each contain three integers ‘U’, ‘V’, and ‘W’, indicating there is an undirected edge between nodes ‘U’ and ‘V’ with weight ‘W’.

Output:

For each test case, return the weight of the minimum spanning tree of the given graph. 

Example:

Assume a test case where N = 4, M = 5 and the edges are as follows: [ (1, 2, 10), (2, 3, 15), (3, 4, 4), (1, 4, 5), (2, 4, 6) ]. The weight of the MST will be 19.

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 10000
  • 1 <= M <= 10000
  • 1 <= W <= 1000
  • 1 <= U, V <= N

Time limit: 1 sec

Note:

You don't need to print the output; just implement the function as specified. 
AnswerBot
4mo

The task is to determine the weight of the minimum spanning tree of a given connected undirected weighted graph.

  • Implement Kruskal's algorithm to find the minimum spanning tree weight.

  • Sort the edges ba...read more

Help your peers!
Select
Add answer anonymously...

Paxcom India Software Engineer interview questions & answers

A Software Engineer was asked Q. Determine the Left View of a Binary Tree You are given a binary tree of integers...read more
A Software Engineer was asked Q. Maximize Expression Value Given an arithmetic expression EXP containing integer ...read more
A Software Engineer was asked Q. Sum Tree Conversion Convert a given binary tree into its sum tree. In a sum tree...read more

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. Determine the Left View of a Binary Tree You are given a binary tree of integers...read more
A Software Engineer was asked Q2. Maximize Expression Value Given an arithmetic expression EXP containing integer ...read more
A Software Engineer was asked Q3. Sum Tree Conversion Convert a given binary tree into its sum tree. In a sum tree...read more
Paxcom India Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits