Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Interview Problems on Graph
  • Practice Graph
  • MCQs on Graph
  • Graph Tutorial
  • Graph Representation
  • Graph Properties
  • Types of Graphs
  • Graph Applications
  • BFS on Graph
  • DFS on Graph
  • Graph VS Tree
  • Transpose Graph
  • Dijkstra's Algorithm
  • Minimum Spanning Tree
  • Prim’s Algorithm
  • Topological Sorting
  • Floyd Warshall Algorithm
  • Strongly Connected Components
  • Advantages & Disadvantages
Open In App
Next Article:
Program to Calculate the Edge Cover of a Graph
Next article icon

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> 

Output
3

Time Complexity: O(1), As we are doing constant time operations only.
Auxiliary Space: O(1)


Next Article
Program to Calculate the Edge Cover of a Graph

N

Naman_Garg
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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences