# find the densest subgraph of size k

What is "the best" algorithm to find the densest subgraph of size k?

i.e. a subgraph of size k with the maximum number of edges inside for an unweighted and undirected graph.

For fixed k, the straightforward brute-force algorithm takes $O(n^k)$ time with n the number of nodes. I'm looking for something, like $O(2^kn)$ or so. Maybe using a recursive algorithm or dynamic programming.

• An answer to your problem tells you whether there exists a clique of size k. So, any such algorithm for your problem must be at least as slow as clique algorithms. See wikipedia section on FPT and clique. – Austin Buchanan Dec 16 '13 at 15:56
• @Austin, I think your comment can be an answer. :) – Kaveh Dec 19 '13 at 21:11
• You can easily remove a factor of k! by only selecting nodes in order. Then your algorithm only takes O(n choose k) – dspyz Dec 20 '13 at 1:00
• Edit, we're both forgetting an extra factor of k^2 to count the number of edges in a particular selection – dspyz Dec 20 '13 at 1:03

An answer to your problem tells you whether there exists a clique of size k. So, any such algorithm for your problem must be at least as slow as clique algorithms. See the wikipedia section on FPT and clique for more.

This is me again, more than 3 years after asking this question.

Here is a code that can solve the weighted version of the problem in some real-world weighted graphs efficiently: https://github.com/maxdan94/HkS

It uses branch&bound.

• (1) you should accept an answer. (2) what is a "real-world weighted graph"? Graphs can arise in all kinds of contexts in the real world, and can have very different properties. If you are going to declare an algorithm with no proven guarantees efficient for "real-world [...] graphs" then you should give some information about what it has been tested on and how, possibly link to a paper. – Sasho Nikolov Feb 10 '17 at 14:23
• Thanks for your feedback. I have edited my answer. What do you mean by "I should accept an answer"? – maxdan94 Feb 12 '17 at 14:11
• It means to mark one of the two answers as "accepted" by clicking on the grey tickmark next to it, so that the question does not keep popping up as unanswered. – Sasho Nikolov Feb 12 '17 at 14:46