Check if a Clique Can Be Divided into Two Equal Halves

Updated

Considering a clique of n vertices. Determine if it is possible to divide the set of vertices into two equal halves such that there is an edge between any two vertices of the two halves. A clique is a graph with an edge between any two distinct vertices.

Examples:

Input : 
5
Output :
NO

Input :
2
Output :
YES

Approach:
The answer would “YES” if n is even.
Else the answer would be “NO”.
That is, it is only possible to divide the clique into 2 halves only if n is divisible by 2.

# Below is the Python implementation of the above code
n = 2
if n % 2 == 0:
    print("YES")
else:
    print("NO")

Output:

YES 
Comment
Next tutorial
Mithlesh Upadhyay Published 2 Dec 2024 · 1 min read

Mithlesh Upadhyay is a Computer Science and AI expert from Madhya Pradesh with strong academic background (BE in CSE and M.Tech in AI) and over six years of experience in technical content development. He has contributed tech articles, led teams, and worked in Full Stack Development and Data Science. He founded the w3colleges.org portal for learning resources.

Related tutorials