Check if a Clique Can Be Divided into Two Equal Halves

By | December 2, 2024

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 
Author: Mithlesh Upadhyay

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.