All problems
Clique Number
Problem
Find the size of the largest clique in an undirected graph with n nodes.
Use the Bron-Kerbosch algorithm with three sets: the current clique, candidate nodes, and already excluded nodes. edges is a list of [u, v] pairs and n is small.
Hint
Bron-Kerbosch grows a clique while keeping candidates adjacent to all chosen nodes.
Test cases
case 1
in: [3,[[0,1],[1,2],[2,0]]]
expected: 3
case 2
in: [4,[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]]]
expected: 4
case 3
in: [5,[[0,1],[1,2],[2,3],[3,4],[4,0]]]
expected: 2
case 4
in: [3,[]]
expected: 1
case 5
in: [5,[[0,1],[0,2],[1,2],[2,3],[3,4],[2,4]]]
expected: 3
Starter codePython
def clique_number(n, edges):
# Your code here
pass5 test cases · run your code against them in the editor