Given a complete graph with N vertices, the task is to count the number of ways to remove edges such that the resulting graph has odd number of edges.
Input: N = 3
The initial graph has 3 edges as it is a complete graph. We can remove edges (1, 2) and (1, 3) or (1, 2) and (2, 3) or (1, 3) and (2, 3) or we do not remove any of the edges.
Input: N = 4
Approach: As the graph is complete so the total number of edges will be E = N * (N – 1) / 2. Now there are two cases,
- If E is even then you have to remove odd number of edges, so the total number of ways will be which is equivalent to .
- If E is odd then you have to remove even number of edges, so the total number of ways will be which is equivalent to .
Note that if N = 1 then the answer will be 0.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program to find total number of edges in a Complete Graph
- Count ways to change direction of edges such that graph becomes acyclic
- Minimum edges required to make a Directed Graph Strongly Connected
- Maximum number of edges that N-vertex graph can have such that graph is Triangle free | Mantel's Theorem
- Path with minimum XOR sum of edges in a directed graph
- Maximum number of edges in Bipartite graph
- Minimum number of edges between two vertices of a Graph
- Number of Simple Graph with N Vertices and M Edges
- All vertex pairs connected with exactly k edges in a graph
- Minimum number of edges between two vertices of a graph using DFS
- Count number of edges in an undirected graph
- Tree, Back, Edge and Cross Edges in DFS of Graph
- Shortest path with exactly k edges in a directed and weighted graph | Set 2
- Largest subset of Graph vertices with edges of 2 or more colors
- Shortest path with exactly k edges in a directed and weighted graph
- Remove all outgoing edges except edge with minimum weight
- Program to find the diameter, cycles and edges of a Wheel Graph
- Maximum number of edges among all connected components of an undirected graph
- Minimum number of Edges to be added to a Graph to satisfy the given condition
- Assign directions to edges so that the directed graph remains acyclic
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.