Program to Calculate the Edge Cover of a Graph Last Updated : 23 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Given the number of vertices N of a graph. The task is to determine the Edge cover.Edge Cover: Minimum number of edges required to cover all vertex is known as Edge Cover. Examples: Input : N = 5 Output : 3 Input : N = 4 Output : 2 Example 1: For N = 5 vertices, Edge Cover is: 3 (Choosing the edges marked in Red, all of the vertices will get covered) Example 2: For N = 8 vertices, Edge Cover is: 4 (Choosing the edges marked in Red, all of the vertices will get covered) Formula: Edge Cover = ceil (no. of vertices / 2) Implementation: C++ // C++ program to find Edge Cover #include <bits/stdc++.h> using namespace std; // Function that calculates Edge Cover int edgeCover(int n) { float result = 0; result = ceil(n / 2.0); return result; } // Driver Code int main() { int n = 5; cout << edgeCover(n); return 0; } Java // Java program to find Edge Cover import java.util.*; import java.lang.*; import java.io.*; class GFG{ // Function that calculates Edge Cover static int edgeCover(int n) { int result = 0; result = (int)Math.ceil((double)n / 2.0); return result; } // Driver Code public static void main(String args[]) { int n = 5; System.out.print(edgeCover(n)); } } Python3 # Python 3 implementation of the above approach. import math # Function that calculates Edge Cover def edgeCover(n): result = 0 result = math.ceil(n / 2.0) return result # Driver code if __name__ == "__main__" : n = 5 print(int(edgeCover(n))) # this code is contributed by Naman_Garg C# // C# program to find Edge Cover using System; class GFG { // Function that calculates Edge Cover static int edgeCover(int n) { int result = 0; result = (int)Math.Ceiling((double)n / 2.0); return result; } // Driver Code static public void Main () { int n = 5; Console.Write(edgeCover(n)); } } // This code is contributed by Raj PHP <?php // PHP program to find Edge Cover // Function that calculates // Edge Cover function edgeCover($n) { $result = 0; $result = ceil($n / 2.0); return $result; } // Driver Code $n = 5; echo edgeCover($n); // This code is contributed by Raj ?> JavaScript <script> // javascript program to find Edge Cover // Function that calculates Edge Cover function edgeCover(n) { var result = 0; result = parseInt( Math.ceil(n / 2.0)); return result; } // Driver Code var n = 5; document.write(edgeCover(n)); // This code contributed by gauravrajput1 </script> Output3 Time Complexity: O(1), As we are doing constant time operations only.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to Calculate the Edge Cover of a Graph N Naman_Garg Follow Improve Article Tags : Graph Computer Science Fundamentals DSA Python DSA-exercises Practice Tags : Graph Similar Reads Program to find the diameter, cycles and edges of a Wheel Graph Wheel Graph: A Wheel graph is a graph formed by connecting a single universal vertex to all vertices of a cycle. Properties: Wheel graphs are Planar graphs.There is always a Hamiltonian cycle in the Wheel graph.Chromatic Number is 3 and 4, if n is odd and even respectively. Problem Statement: Given 6 min read Program to find total number of edges in a Complete Graph Given N number of vertices of a Graph. The task is to find the total number of edges possible in a complete graph of N vertices.Complete Graph: A Complete Graph is a graph in which every pair of vertices is connected by an edge. Examples: Input : N = 3 Output : Edges = 3 Input : N = 5 Output : Edges 3 min read How to create a random Graph in C++? A graph is a type of non-linear data structure that has two types of components "Vertices" (nodes) and "edges". It contains a set of vertices (V) and a set of edges (E). Two nodes of the graph are connected by an edge. A graph is denoted by G(V, E). Example of a GraphWays to represent a Graph:There 4 min read Edge Coloring of a Graph In graph theory, edge coloring of a graph is an assignment of "colors" to the edges of the graph so that no two adjacent edges have the same color with an optimal number of colors. Two edges are said to be adjacent if they are connected to the same vertex. There is no known polynomial time algorithm 9 min read Find the Degree of a Particular vertex in a Graph Given a graph G(V,E) as an adjacency matrix representation and a vertex, find the degree of the vertex v in the graph. Examples : 0-----1 |\ | | \ | | \| 2-----3 Input : ver = 0 Output : 3 Input : ver = 1 Output : 2 Algorithm: 1. Create the graphs adjacency matrix from src to des 2. For the given ve 7 min read Like