Maximum Clique Problem|Recursive Solution


Finding the biggest complete subgraph, or clique, in a given graph is the goal of the famous Maximal Clique Problem in graph theory. Each vertex in a clique is connected to every other vertex in the clique by a direct edge. The technique iteratively adds vertices connecting to all vertices in the current clique to investigate all possible expansions of the clique. In order to quickly explore the search space, it employs backtracking, eliminating potential paths that would not end in maximum cliques.Using the recursive method, we can efficiently discover and label all maximum cliques in a given graph, yielding important insights into the connections and patterns found in complicated networks. This technique's adaptability to new settings and success with huge graphs have led to its widespread use.

Methods Used

  • Recursive Solution

Recursive Solution

Recursion solves the Maximal Clique Problem. Starting from each network vertex, the method finds maximum cliques. It adds vertices related to every clique vertices to iteratively explore all clique extensions. Adding vertices until the clique is largest continues.

Algorithm

  • A function canAddToClique(v, graph, clique) tests if a vertex v can be added to the clique. Check each clique vertex i for a graph edge between v and i. Return false if edges are missing, true otherwise.

  • A recursive function findMaximalCliques(graph, clique, visited, vertex) finds the graph's maximum cliques. The graph, clique, array, and vertex are inputs.

  • Set isMaximal to true.

  • Iterate over the vertices from vertex+1 to the graph's end.

  • a. Add the current vertex to the clique using the canAddToClique function, run findMaximalCliques recursively, then delete the vertex.

  • b. Set isMaximal to false after adding a clique vertex.

  • If isMaximal is true, display the clique as maximum.

Example

;
#include <iostream>
#include <vector>
using namespace std;

// Function to check if a given vertex can be added to the current clique
bool canAddToClique(int v, int clique, vector<vector<int>>& graph) {
    for (int i = 0; i < graph.size(); ++i) {
        if ((clique & (1 << i)) && graph[v][i] == 0)
            return false;
    }
    return true;
}

// Recursive function to find the maximal cliques in a graph
void findMaximalCliques(int vertex, int clique, vector<vector<int>>& graph) {
    bool isMaximal = true;

    for (int i = vertex + 1; i < graph.size(); ++i) {
        if (canAddToClique(i, clique, graph)) {
            findMaximalCliques(i, (clique | (1 << i)), graph);
            isMaximal = false;
        }
    }

    if (isMaximal) {
        for (int i = 0; i < graph.size(); ++i) {
            if ((clique & (1 << i)))
                cout << i << " ";
        }
        cout << endl;
    }
}

// Function to find and print all maximal cliques in the given graph
void printMaximalCliques(vector<vector<int>>& graph) {
    int numVertices = graph.size();

    for (int v = 0; v < numVertices; ++v) {
        findMaximalCliques(v, (1 << v), graph);
    }
}

int main() {
    vector<vector<int>> graph = {
        {0, 1, 1, 0},
        {1, 0, 1, 1},
        {1, 1, 0, 1},
        {0, 1, 1, 0}
    };

    cout << "Maximal Cliques:" << endl;
    printMaximalCliques(graph);

    return 0;
}

Output

Maximal Cliques:
0 1 2 
0 2 
1 2 3 
1 3 
2 3 
3 

Conclusion

In conclusion, the Maximal Clique issue is an essential graph−theoretic issue with many practical applications. Finding all maximum cliques in a graph may be accomplished efficiently using the recursive technique. The approach effectively discovers subsets of vertices that form complete subgraphs by recursively searching the graph and making use of backtracking.The recursive answer provides a methodical and complete search strategy, finding every feasible maximum clique. It improves the algorithm's efficiency by decreasing its computational cost by cutting off branches that don't lead to maximum cliques. This allows it to be used with practical applications and huge graphs.

Updated on: 14-Jul-2023

192 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements