- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find out the minimum size of the largest clique in a graph (Python)

Suppose we are given a graph and are asked to find out the minimum size of the largest clique in the graph. A clique of a graph is a subset of a graph where every pair of vertices are adjacent, i.e. there exists an edge between every pair of vertices. Finding the largest clique in a graph is not possible in polynomial time, so given the number of nodes and edges of a small graph we shall have to find out the largest clique in it.

So, if the input is like nodes = 4, edges =4; then the output will be 2.

In the graph above, the maximum size of a clique is 2.

To solve this, we will follow these steps −

- Define a function helper() . This will take x, y
- ga := x mod y
- gb := y - ga
- sa := quotient of value of(x / y) + 1
- sb := quotient of value of(x / y)
- return ga * gb * sa * sb + ga *(ga - 1) * sa * sa / 2 + gb * (gb - 1) * sb * sb / 2

- i := 1
- j := nodes + 1
- while i + 1 < j, do
- p := i + floor value of((j - i) / 2)
- k := helper(nodes, p)
- if k < edges, then
- i := p

- otherwise,
- j := p

- return j

## Example

Let us see the following implementation to get better understanding −

import math def helper(x, y): ga = x % y gb = y - ga sa = x // y + 1 sb = x // y return ga * gb * sa * sb + ga * (ga - 1) * sa * sa // 2 + gb * (gb - 1) * sb * sb // 2 def solve(nodes, edges): i = 1 j = nodes + 1 while i + 1 < j: p = i + (j - i) // 2 k = helper(nodes, p) if k < edges: i = p else: j = p return j print(solve(4, 4))

## Input

4,4

## Output

2

- Related Questions & Answers
- Program to Find Out the Minimum Cost Possible from Weighted Graph in Python
- Program to find out the sum of minimum cost within a graph among all vertices in Python
- Program to Find Out the Strings of the Same Size in Python
- Program to find out the path between two vertices in a graph that has the minimum penalty (Python)
- Python program to find the size of the largest subset of anagram words
- Python program to find the size of largest subset of anagram words
- Program to Find Out the Edges that Disconnect the Graph in Python
- C++ Program to find out the super vertices in a graph
- C++ program to find minimum vertex cover size of a graph using binary search
- Program to Find Out the Largest K-Divisible Subsequence Sum in Python
- Program to Find Out the Minimum Cost to Purchase All in Python
- C++ program to find out the maximum sum of a minimally connected graph
- Program to find out if the graph is traversable by everybody in Python
- Python program to Find the size of a Tuple
- Program to find largest color value in a directed graph in Python

Advertisements