# Dominant Set of a Graph

In graph theory, a dominating set for a graph G = (V, E) is a subset D of V such that every vertex not in D is adjacent to at least one member of D. The domination number is the number of vertices in a smallest dominating set for G.

Examples:

Input : A graph with 4 vertex and 4 edges Output : The Dominant Set S= { a, b } or { a, d } or { a, c } and more. Input : A graph with 6 vertex and 7 edges Output : The Dominant Set S= { a, d, f } or { e, c } and more.

It is believed that there may be no efficient algorithm that finds a smallest dominating set for all graphs, but there are efficient approximation algorithms.

**Algorithm : **

- First we have to initialize a set ‘S’ as empty
- Take any edge ‘e’ of the graph connecting the vertices ( say A and B )
- Add one vertex between A and B ( let say A ) to our set S
- Delete all the edges in the graph connected to A
- Go back to step 2 and repeat, if some edge is still left in the graph
- The final set S is a Dominant Set of the graph

`// C++ program to find the Dominant Set of a graph ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `vector<vector<` `int` `> > g; ` `bool` `box[100000]; ` ` ` `vector<` `int` `> Dominant(` `int` `ver, ` `int` `edge) ` `{ ` ` ` `vector<` `int` `> S; ` `// set S ` ` ` `for` `(` `int` `i = 0; i < ver; i++) { ` ` ` `if` `(!box[i]) { ` ` ` `S.push_back(i); ` ` ` `box[i] = ` `true` `; ` ` ` `for` `(` `int` `j = 0; j < (` `int` `)g[i].size(); j++) { ` ` ` `if` `(!box[g[i][j]]) { ` ` ` `box[g[i][j]] = ` `true` `; ` ` ` `break` `; ` ` ` `} ` ` ` `} ` ` ` `} ` ` ` `} ` ` ` `return` `S; ` `} ` ` ` `// Driver function ` `int` `main() ` `{ ` ` ` `int` `ver, edge, x, y; ` ` ` ` ` `ver = 5; ` `// Enter number of vertices ` ` ` `edge = 6; ` `// Enter number of Edges ` ` ` `g.resize(ver); ` ` ` ` ` `// Setting all index value of an array as 0 ` ` ` `memset` `(box, 0, ` `sizeof` `(box)); ` ` ` ` ` `// Enter all the end-points of all the Edges ` ` ` `// g[x--].push_back[y--] g[y--].push_back[x--] ` ` ` `g[0].push_back(1); ` ` ` `g[1].push_back(0); ` `// x = 1, y = 2 ; ` ` ` `g[1].push_back(2); ` ` ` `g[2].push_back(1); ` `// x = 2, y = 3 ; ` ` ` `g[2].push_back(3); ` ` ` `g[3].push_back(2); ` `// x = 3, y = 4 ; ` ` ` `g[0].push_back(3); ` ` ` `g[3].push_back(0); ` `// x = 1, y = 4 ; ` ` ` `g[3].push_back(4); ` ` ` `g[4].push_back(3); ` `// x = 4, y = 5 ; ` ` ` `g[2].push_back(4); ` ` ` `g[4].push_back(2); ` `// x = 3, y = 5 ; ` ` ` ` ` `vector<` `int` `> S = Dominant(ver, edge); ` ` ` `cout << ` `"The Dominant Set is : { "` `; ` ` ` `for` `(` `int` `i = 0; i < (` `int` `)S.size(); i++) ` ` ` `cout << S[i] + 1 << ` `" "` `; ` ` ` `cout << ` `"}"` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

The Dominant Set is : { 1 3 5 }

Reference : wiki

## Recommended Posts:

- Convert the undirected graph into directed graph such that there is no path of length greater than 1
- Detect cycle in the graph using degrees of nodes of graph
- Graph implementation using STL for competitive programming | Set 2 (Weighted graph)
- BFS for Disconnected Graph
- Sum of dependencies in a graph
- Biconnected graph
- Islands in a graph using BFS
- Transpose graph
- Bridges in a graph
- Hypercube Graph
- Graph and its representations
- Coloring a Cycle Graph
- Degree of a Cycle Graph
- Check if a given graph is Bipartite using DFS
- Fibonacci Cube Graph

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.