Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
Last Updated :
01 Feb, 2023
Give a complete graph with N-vertices. The task is to find out the maximum number of edge-disjoint spanning tree possible.
Edge-disjoint Spanning Tree is a spanning tree where no two trees in the set have an edge in common.
Examples:
Input : N = 4
Output : 2
Input : N = 5
Output : 2
The maximum number of possible Edge-Disjoint Spanning tree from a complete graph with N vertices can be given as,
Max Edge-disjoint spanning tree = floor(N / 2)
Let’s look at some examples:
Example 1:
Complete graph with 4 vertices
All possible Edge-disjoint spanning trees for the above graph are:
A
B
Example 2:
Complete graph with 5 vertices
All possible Edge-disjoint spanning trees for the above graph are:
A
B
Implementation: Below is the program to find the maximum number of edge-disjoint spanning trees possible.
C++
#include <bits/stdc++.h>
using namespace std;
float edgeDisjoint( int n)
{
float result = 0;
result = floor (n / 2);
return result;
}
int main()
{
int n = 4;
cout << edgeDisjoint(n);
return 0;
}
|
Java
import java.io.*;
class GFG
{
static double edgeDisjoint( int n)
{
double result = 0 ;
result = Math.floor(n / 2 );
return result;
}
public static void main(String[] args)
{
int n = 4 ;
System.out.println(( int )edgeDisjoint(n));
}
}
|
Python3
import math
def edgeDisjoint(n):
result = 0
result = math.floor(n / 2 )
return result
if __name__ = = "__main__" :
n = 4
print ( int (edgeDisjoint(n)))
|
C#
using System;
class GFG
{
static double edgeDisjoint( double n)
{
double result = 0;
result = Math.Floor(n / 2);
return result;
}
public static void Main()
{
int n = 4;
Console.Write(edgeDisjoint(n));
}
}
|
PHP
<?php
function edgeDisjoint( $n )
{
$result = 0;
$result = floor ( $n / 2);
return $result ;
}
$n = 4;
echo edgeDisjoint( $n );
?>
|
Javascript
<script>
function edgeDisjoint(n)
{
var result = 0;
result = Math.floor(n / 2);
return result;
}
var n = 4;
document.write( edgeDisjoint(n));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...