Find maximum clique with recursive function
Show older comments
I am solving an problem which has been stated and discussed here: maximum clique problem solve
As the OP showed in the above thread, the original version is inefficient because it is checking a bunch of sets of nodes that cannot possibly be part of a clique. So we need a smarter way to pick which nodes to check.
Therefore, based the tiny improvement in the accepted answer in maximum clique problem solve, I also tried:
- disregard nodes with length < length(clique)
- disregard nodes with the first element > clique(1)
- disregard nodes with the last element < clique(end)
- disregard nodes that are not in the follow list of first elemnt in the current clique
if ~any(node == clique) && length(graph{node}) >= length(clique) && graph{node}(1) <= clique(1) && graph{node}(end) >= clique(end) && any(node == graph{clique(1)})
Unfortunately, this runs for ~60 seconds on my computer, which is still not fast enough to pass the grader...
I also come up with the order of operands of && operator. So I change the above line to:
if any(node == graph{clique(1)}) && length(graph{node}) >= length(clique) && graph{node}(1) <= clique(1) && graph{node}(end) >= clique(end) && ~any(node == clique)
Although this gets a bit faster and runs for ~40 seconds on my computer, unfortunately this is still not fast enough to pass the grader...
I HOPE SOMEONE COULD PROVIDE SOME ADVICES.
ANY SUGGESTIONS WILL BE APPRECIATED.
5 Comments
I had the problem in the linked question already: The text of the question does not mention explicitly, what the code should calculate. I have to guess the intention from the result given by the slow example code. If I get such a question as a student, I'd refuse to solve it and ask for a clear problem description at first.
I'd just optimized the code blindly without understanding, what it does. I get the result
1769 1773 1774 1833 2222
but do not have the faintest idea, what this should be. In consequence I cannot rewrite the code in an efficient way, because the most important part of the description is missing.
Sorry, maybe it is only a langauge problem, because I'm not a native speaker.
Jan
on 12 Aug 2021
Okay, it's clear now.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!