Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The longest cycle problem includes the special case of finding a Hamiltonian cycle (a cycle that visits every node exactly once), and is therefore NP-complete. This means you will not find an efficient solution, only something along the lines of a brute-forcing. I couldn't find much info on the longest-cycle problem, but you can reduce the longest-path problem to the Hamiltonian cycle problem as follows:
If you have a graph with V vertices, take all size-V subsets of vertices, then all size-(V-1) subsets, etc.. For each of these subsets of vertices, determine if there's a Hamiltonian cycle. The first subset of nodes you encounter that contains a Hamiltonian cycle is the longest cycle in your original graph.
The Hamiltonian cycle problem is very common, and you should be able to find a lot of literature on the subject. However, any code is going to be exponential (with the possible exception of some special class of graphs perhaps).

It may be time to rethink a way through this problem. Is there is a way to do it without needing the longest cycle? This page has some good suggestions for rethinking problems involving Hamiltonian cycles. For instance, perhaps you can solve the same problem only by needing an Eulerian cycle, which is much easier to compute.

blokhead


In reply to Re: Largest cycle in the graph by blokhead
in thread Largest cycle in the graph by artist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-25 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found