Related Articles

# Java Program to Find the Largest Clique in a Planar Graph

• Last Updated : 03 Sep, 2021

Independent set of Graph as a pre-requisite is the set of vertices where no two are adjacent to each other. It is just opposite in definition to clique, Hence knowledge about the complements of a graph is necessary in order to go further. Basically, the idea of a planar graph is not of utmost importance but can be referred. Hence, we will be using the idea of all these three to solve the Question mentioned.

We are required to find the largest Clique in the given Planar Graph. The clique of any planar graph is the subset of vertices such that any two vertexes in that subset are adjacent to each other i.e. the set of vertices form a complete graph and this complete graph is a subgraph of a given planar graph. In other words, Maximal Clique is the maximum subset of vertices such that they form a complete subgraph in the given graph and no more vertices can be added to that subset. Now if we are familiar with the idea of independent sets then we can found a foggy relationship between the two concepts: Clique and Independent-set.

Hence, the relationship and differences go hand in hand as discussed below:

• A Clique is a set of vertices of an undirected or planar graph such that every two distinct vertices in the clique are adjacent.
• An Independent set is a set of vertices such that no two are adjacent to each other.
• The idea of maximal is the same for both sets.

The definition of both Clique and independent sets of a graph directly indicates that there is some complementary relationship between them.

Suppose if we complement our given graph, then according to the definition of the maximal independent set, it will be the largest set of those vertices which are not adjacent to each other in the real graph (since we are finding the independent set in the complement graph). Hence, the maximal independent set of the complement of the given graph is nothing but the maximal Clique in the given graph.

Concept:

So the largest Clique of a given graph can be considered as the largest Independent set in the complement graph of the given graph. Since we are having many ways to find the largest independent sets of a given planar graph (although they are NP-hard problems) we can use any of them to find the clique. We just have to make a small change in the given algorithms in that we have to input the complement of the input graph.

Implementation: graph as shown as below as follows:

• Now we are going to find the Largest clique in the above-given graph. (which is the subgraph made up of green edges)
• The below given is the implementation of above idea of finding the independent set of a graph’s complement which is indirectly the Clique of that Graph.

Go through if you do not know the idea in order to find the Independent set of graph using different methods

Example

## Java

Output
The number of vertices in the graph is taken as 5
The maximal independent set's size to be find is 4
Searching for the set
Independent set of size 4found
1 2 3 4
Found set of 4 size whose elements are displayed above as a clique for the input graph

Output explanation:

As we can see the output tells that the number of vertices taken are 5 and after finding the independent set of size 4 it return the set of vertices which together forms the independent set in the complement graph and since we had discussed that independent set of complements are clique in original graphs hence these sets are the clique in the original graph.

Note: If we will mention the full size of graph (i.e. 5 in above eg), Then the output is shown below:

The number of vertices in the graph is taken as 5
The maximal independent set's size to be find is 5
Searching for the set
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Independent set of size 4found
1 2 3 4
Found set of 4 size whose elements are displayed above as a clique for the input graph

Output explanation:

In order to find the maximal clique set just mention the original size of the graph (i.e. 5 here). If any independent set of such size is found then it is returned to the output else the nearest maximum one is returned. Hence, we can always find the maximal clique set of graphs with this idea. Hence, we can see that the above idea worked, and we are able to find the maximal clique of the given graph.

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.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

My Personal Notes arrow_drop_up