- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to Calculate the Edge Cover of a Graph
Given a n number of vertices of a graph, the task is to calculate the edge cover of the graph. Edge cover is to find the minimum number of edges required to cover every vertex of the graph.
Like we have n = 5
Then its graph will be like −
So its edge cover is 3
Let’s take another example where the n is 8
And its edge cover will be:4
Example
Input: n= 5 Output: 3 Input: n= 8 Output: 4
Approach used below is as follows −
- Take the input from the user
- Find the ceiling value of the result of number of vertices by dividing it by 2.0
- Return and print the result.
Algorithm
Start Step 1-> declare function to calculate the edge cover of a graph int edge(int n) set float val = 0 set val = ceil(n / 2.0) return val step 2-> In main() set int n = 10 call edge(n) Stop
Example
#include <bits/stdc++.h> using namespace std; // Function to calculates Edge Cover int edge(int n) { float val = 0; val = ceil(n / 2.0); return val; } int main() { int n = 10; cout<<"minium number of edges required are :"<<edge(n); return 0; }
Output
IF WE RUN THE ABOVE CODE IT WILL GENERATE FOLLOWING OUTPUT
minium number of edges required are :5
- Related Articles
- C++ Program to Find the Edge Connectivity of a Graph
- C++ Program to Perform Edge Coloring of a Graph
- C++ Program to Perform Edge Coloring to the Line Graph of an Input Graph
- C++ Program to Implement a Heuristic to Find the Vertex Cover of a Graph
- C++ Program to Perform Edge Coloring on Complete Graph
- C++ Program to Construct a Random Graph by the Method of Random Edge Selection
- C++ Program to Create a Random Graph Using Random Edge Generation
- C++ Program to Find a Good Feedback Edge Set in a Graph
- C++ program to find minimum vertex cover size of a graph using binary search
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph in C++
- Program to Calculate the Perimeter of a Decagon in C program
- C++ Program to Find the Vertex Connectivity of a Graph
- Maximize number of nodes which are not part of any edge in a Graph in C++
- C++ Program to Find Maximum Number of Edge Disjoint Paths
- C++ Program to Calculate Power of a Number

Advertisements