Given an undirected unweighted connected graph consisting of n vertices and m edges. The task is to find any spanning tree of this graph such that the maximum degree over all vertices is maximum possible. The order in which you print the output edges does not matter and an edge can be printed in reverse also i.e. (u, v) can also be printed as (v, u).
Input: 1 / \ 2 5 \ / 3 | 4 Output: 3 2 3 5 3 4 1 2 The maximum degree over all vertices is of vertex 3 which is 3 and is maximum possible. Input: 1 / 2 / \ 5 3 | 4 Output: 2 1 2 5 2 3 3 4
Prerequisite: Kruskal Algorithm to find Minimum Spanning Tree
Approach: The given problem can be solved using Kruskal’s algorithm to find the Minimum Spanning tree.
We find the vertex which has maximum degree in the graph. At first we will perform the union of all the edges which are incident to this vertex and than carry out normal Kruskal’s algorithm. This gives us optimal spanning tree.
3 2 3 5 3 4 1 2
- Boruvka's algorithm for Minimum Spanning Tree
- Reverse Delete Algorithm for Minimum Spanning Tree
- Kruskal’s Minimum Spanning Tree Algorithm | Greedy Algo-2
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Find if a degree sequence can form a simple graph | Havel-Hakimi Algorithm
- Minimum Product Spanning Tree
- Kruskal's Minimum Spanning Tree using STL in C++
- Find the weight of the minimum spanning tree
- Minimum Bottleneck Spanning Tree(MBST)
- Minimum spanning tree cost of given Graphs
- Applications of Minimum Spanning Tree Problem
- Prim’s Minimum Spanning Tree (MST) | Greedy Algo-5
- Make a tree with n vertices , d diameter and at most vertex degree k
- Find the minimum spanning tree with alternating colored edges
- Minimum Spanning Tree using Priority Queue and Array List
- Print the nodes with a prime degree in given Prufer sequence of a Tree
- Print the node with the maximum degree in the prufer sequence
- Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST
- Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorithm using Segment Tree
- Dinic's algorithm for Maximum Flow
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.