Finding all cycles in a directed graph

Hi all,
I have a task I believe I will solve relatively easy if I manage to detect all cycles within a graph that I can build from the data given.
I googled for a while but I couldn't find some explanation that I can use. I came upon refrerences to some publication referred as "Reingold, Nievergelt and Deo 1977", however I could not find some online resources from that ?book?.
AFAIK I can detect whether thre is a cycle using DFS, but I need all cycles.
Please guide me to some online resource that can help me find a suitable algorithm, or if you know such algorithm please post its name so I can find information about it.
Thanks for your cooperation
Mike

Thanks for all those replies!
I still haven't implemented a solution and I have some questions. I googled and skimmed through a book I have and I came up with the definition that topological sorted graph means that all 'paths' lead in one direction (such ordering of the vertices V that for each edge(i, j) in E vertex i is to the left of vertex j).
If I understand correctly your idea, it is to first order the vertices by some criterion and then remove all edges leading in a direction opposite to the sorting direction.
I am not quite sure I understand correctly how to choose the ordering of the vertices. In the beginning of the sorted vertex list we must have vertices with the most possible outgoing edges /as sum of weights/ and least incoming(because these are to be removed), did I understand the idea correctly?
I thought about another solution but I cannot estimate how heavy it will be as processing time: to perform search(maybe DFS) and if I find a cycle - to remove the least heavy edge and continue the search from the position before passing this edge.
I guess it is not applicable since it can escalate to a very time-heavy task, especially if each time we go back.
So I think I will implement the Idea YATArchivist proposed - sorting vertices and removing back-edges, and we'll see what will happen. After all - it's only a contest, I can only win or not win, there are no losers ;)
Thank you for giving your valuable time for sharing thoughts in this thread
Mike

Similar Messages

  • Detecting Cycles in a Directed Graph

    Can somebody help me how to find cycles in a directed graph,
    I already made a Depth First Search code and base on what I've learned Cycles can be done using Depth First Search
    public static void DFS(int numberNodes){
        System.out.print("Enter starting node for Depth First search: ");
            int v = scanner.nextInt();
        for(int i = 1;i<=numberNodes;i++)
                 visited[i] = false;
            dfs_rec(v,numberNodes);
        }//end DFS()
         public static void dfs_rec(int v,int n){
        int i;
        visited[v] = true;     
             System.out.print(" "+v);
             for(i = 1;i<n;i++)
                  if(adj[v] == 1 && visited[i] == false)
                   dfs_rec(i,n);
         }//end dfs rec                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    malcolmmc wrote:
    paulcw wrote:
    I don't see the need for unsetting the flag. Visited is visited. What needs to be added is to respond when the flag is set to true.You need to clear the flag because the same node might be reached through more than one route without the graph being cyclic (it could be a shared sub-tree).
    Only if you encounter a node which is already part of the path you're examining have you found a loop.But not if it's a depth-first search, no?
    Oh, I see what you're saying. Set the flag, do a depth-first search, then when you exhaust that and do a sibling, clear the flag. OK.

  • Clever way to find cycles in a directed graph

    I need to find cycles in a graph.
    I can think of a way to do it recursively: i go down every path, keep track of previous nodes, and when i visit a node in my history, i have a cycle.
    what im curios is if you guys know a better way to do this?
    yes i have googled this before asking.

    No, DFS is optimal. However, you need to think about whether you want to find every cycle, because that becomes very expensive very quickly in a graph with high connectivity.

  • Finding all unique paths in graph

    can anyone suggest an algorithm to find all unique paths between two nodes?
    I have already implemented a variation of Dijkstra's shortest path algorithm to find ONE path, i'm just not sure how I can find ALL unique paths..
    Any help much appreciated.
    thanks :)

    I'm not really sure about the english terminology to be used and most of inteligent discussions ends up with finding the proper words for definitions :)
    Let me just say I wrote the algorhytm that found all 3 paths in the small example graph (I know, I know. Still testing. Besides I don't want to prove that the code is complete in mathemathical meaning). The limitations are like for every real life path finding algorhytms (let's go from a to b, 0 or more paths may exists, 2 nodes may have 0 or 1 connection, the connetions are not directed, i want unique paths, and I don't want circles in any of the paths).
    In the iteration
    - I check if the path is ends with ENDNODE
    - I get all the neighbors of the last node and generate all the possible paths extending the current (exceptions: path never can include the same node twice) and add them into a queue
    - I get the first from the queue and that is the current path now.
    The iteration ends when I have no more paths to analyze.
    If I undestood the term "unique path" as it can have any circles in it then I may agree with you, but thats another problem.
    In that case (if I had a school homework or I was working for a science group which has no access downloading these kind of algorhytms and they must come up with one for some reason :) I think I'd try to find all the unique circles first then all the paths (without the circles) and then combined them in all the way...
    I'll improve and test the algorhytm before publish it.

  • Airport Utility cannot find all 802.11n gigabit sase stations

    hello everyone,
    airport utility (5.2.1, "Airport-Dienstprogramm" in german does not seem to find all my base stations (6 stations alltogether, IPs assigned ok via DHCP, pingable, usable, green light, no errors, manageable by Airport Utility via manual IP entry) in the list to the left of the main screen. Mostly they are not shown at all, sometimes (or after I manually managed one) they are in the list until Airport Utility is restarted.
    SNMP is on, I tried a new cummunity string but reverted back to "public" just to make sure.
    Is there a way to manually fill the list and then "save" that list somehow so that I can do a quick check on the status?
    Thanks in advance,
    best regards,
    Christian.

    Are you using the latest version (5.5.2) of the AirPort Utility to access the new 802.11n AirPort Extreme Base Station (AEBSn)? Your tagline has it that you are running OS X 10.4.6. You would need at least 10.5.7 to run the utility. I assume that you are running the latest utility on another device ... correct?
    When having difficulties accessing the AirPort thru the AirPort Utility, try the following, in order checking accessibility with the utility after each step:
    o Check the local connection. If you are trying to access the AirPort wirelessly, make sure that you are connected to its wireless network before running the AirPort Utility to administer it. If you are still unable to access it with the utility, temporarily connect your computer directly using an Ethernet cable to one of the base station's LAN ports.
    o Power cycle the base station. Remove the power adapter's plug from the power outlet, and then, wait 15 seconds before plugging it back in.
    o Perform a "factory default" reset on the base station.

  • Find out the peak position from graph

    Hello All,,
    Actually i want to run this algorithm real time,, to find out the peak position from graph ,, i need to generate the position automatically,,, firstly i try to use image processing by  apply threshold followed by edge detection and the find out the center of each  detected part. the drawpack of this procedure is that the obtained images are different and that lead to different threshold values,, so how can i directly find the position from the graph,,, here i attach the image and the graph of the image,,
    thank you,,
    Attachments:
    11.png ‏15 KB
    13.PNG ‏85 KB

    Hello Klemen: 
    here i will explain in more details: the main objective of my work is to calculate velocity of small particle,, i perform my experiments by exposing the particle to 2 light pulses,, and i know the time between the two pulses,, so i need to know the distance to calculate the velocity,,, for that i apply correlation,,, the spot that appear in the correlation image is an indication of symmetry,,,so i should know the location of maximum intensity of each peak. The central peak (highest intensity) will be the reference (zero point) and the other peaks locations should be subtracted from the reference peak to determine the shift,,,
    Here is the sequence of the process:
    Acquiring raw image, correlation, position of central peak, shift calculation, velocity determination,,,,,
    applying image processing is good idea in case of post processing condition,,, but in my case i need it real time, that mean if i need to apply image processing for calculation, i have to find out a universal criteria for threshold value that can be applied for all raw images,, from my experiments i didn't find specific criteria & i have to manually change the threshold value,,
    If I choose the intensity (grey level) to be the criteria, then the small peaks (symmetry) will not take place,, because their intensity is very low compare to the central peak,,,
    So the most reliable procedure is to directly find out the position of the two small peaks beside the central peak and save this values into an array and use it for calculation,,, I hope I am clearly explain my problem..
    Thanks 
    Attachments:
    7-2.png ‏36 KB
    7-1.png ‏3 KB
    7-700.PNG ‏123 KB

  • When you are pulling music from a hard drive and it says music can not be found, is there a way to stop it from doing that every time I play music from my computer? It used to find all music now it only finds 1 song at a time

    When pulling music from a harddrive and it say music can not be found, is there a way to stop this from happening every time I play music on my computer? It used to find all music when serching for song but now it only finds 1 at a time. I have over 2000 songs so I can't go through this every time.

    1) However I do not want to move my itunes Music onto the flash drive, only my Movies, and want to keep my music on my hard drive.
    Is this possible?
    Yes
    2) Do the MacBook Air's not have a separate program other than itunes that can play movies? If so, is there a program I can get to solve this problem? I went onto the App Store to see if there was something I could download, but all the apps were for creating DVD's, not simply playing them.
    If you can play the movies in iTunes, you should be able to open the movie files using Quicktime, which should already be on your system.  If you have already transferred the files to your flash drive, open the flash drive in Finder, and hold control when you click on the movie file (or right click if you have the enabled) and select Open With Quicktime Player.  This should play the movie directly from the flash drive. 
    If you want to set all .m4v files to open with Quicktime by just double clicking on the file, you can follow the steps here: http://www.tech-recipes.com/rx/2573/os_x_how_to_change_default_application_to_op en_file_type/
    3) If 1. & 2. questions are solvable, will it then be safe to delete the movies from my itunes?
    You can move the TV shows to your flash drive by dragging them from the iTunes window to your flash drive in Finder or the flash drive icon on the desktop.  When you are sure everything is transferred over to your external device, you can delete the movie from iTunes.  I recommend playing the videos from the flash drive first before deleting them in iTunes. 
    To delete the videos from iTunes, you can highlight them and press the delete key on your keyboard.  In the next prompt, you would want to move it to the trash so that it is deleted from your internal hard drive.  
    I hope that helps!

  • A problem about the compression of directed graphs

    Right now I encountered a problem in my research that is about graph compressing (or contraction, etc.). I've searched in various ways for existing techniques on this problem and found nothing. I've been trying to figure out this problem by myself. However I would also like to seek some advice from you guys.
    The description of this problem:
    Given a directed graph G = (V, E) where V is the set of vertices and E
    is the set of directed edges. These vertices and directed edges
    represent the events and the directional relationships between pairs of
    events. Each edge is associated with a weight (or confidence score)
    which indicates the degree of the relationship. Now I want to compress
    the graph by merging some of the vertices into one superior vertex,
    which implies that several lower-level events are merged into one
    high-level event (this is mainly because the extent of news events
    defined are usually flexible). After that we can reorganize the
    vertices and edges and repeat this process until the size of the graph
    reaches a certain limit. Purely looking from the point of graph theory,
    is there any existing graph algorithm that solves this problem? As far as I have searched, the answer seems to be negative.This seems to be an interesting novel problem which falls in the area of graph algorithms. Could you suggest anything? Attached is a sample directed graph of such a kind which may be interesting.
    Check this URL to find out more about this kind of DAG:
    http://ihome.cuhk.edu.hk/~s042162/2005-05-24.jpg
    Thank you very much for your time and help.
    Regards,
    Daniel

    Sounds like an interesting problem. The temporal aspect presents an interesting wrinkle. Graph models have been becoming popular for the standard clustering problem recently, but they are typically undirected formulations. The idea of compressing a graph reminded me of work done by G. Karypis and V. Kumar on graph partitioning, some of their papers are available here:
    http://www-users.cs.umn.edu/~karypis/publications/partitioning.html
    SImilar to the reference given by matfud, with the additional restriction that there may be a size restriction on the size of the partitions or there may be multiple partitions (both restrictions make the problem NP-complete, IIRC).
    There's also the area of spectral graph partitioning which may be of interest. Its a way of finding relatively dense areas in a graph by using the eigenvalues of the adjacency matrix. Most of the results in this area are dependent on the fact that adjacency matrices for graphs are symmetric and semi-definite, which wouldn't be the case for a directed graph, but could be worth some experimentation if you have MATLAB or something similar.
    There's something else this problem reminds me of, but I can't think of it right now. Maybe later something will come to me.
    Good luck.

  • In FINDER, all applications have .app after it now, why?

    HI!
    Just got a new iMac. Used a firewire to migrate the date from my old eMac.
    Anyway, now in FINDER, all of my applications have .app after them (iPhoto.app, Dictionary.app, iChat.app, etc).
    When I click on something in Finder...I have to double click it and it opens the application directly. If i single click it highlights it in black.
    Before, when I would single click on iPhoto (for example) it would open a new screen with the camera icon and information on iPhoto, then I would single click the camera icon and then iPhoto would open.
    How do I get rid of the .app? I like the single click and not opening an app directly?
    Thanks!!

    Wow! Such an easy solution to a problem that I could not figure out! Thank you so much.
    Just to let you know, I even went down to the Apple store and asked then what to do and they didn't know! They told me to leave it alone.
    LOL!!
    Why would they have the option of .app or not? I mean, what do some use a .app for when you know it is an application?
    (to add....I have another question in iPhoto 08 if you are interested ........

  • Find all groups in LDAP

    A user is member of a certain group. This group is member of multiple other groups and so on. Does anyone know how I can retrieve all those groups with java ?
    Do I have to loop through all the groups, get the DN and find all other groups that have that DN as a member, again loop through all these groups, ....., or are there better solutions ?
    Any help is very appreciated
    Koen Boutsen

    In general, you will have to find all groups which have the user as a direct member and then check out all groups who have these groups as members, etc.
    Some of the LDAPs have 'virtual' attributes which keep track of this forward mapping of group membership (which infrequently changes) and which can be simply fetched as if it were a normal attribute. For example, "nsRole" in iPlanet and 'memberOf' in Active Directory
    Hope that helps,
    Ken Gartner
    Quadrasis, Inc (We Unify Security, www -dot-- quadrasis dot com)

  • Where do I find all explanations of Weather Forecast (app) Symbols??

    Where do I find all explanations of Weather Forecast (app) Symbols??
    thanks!!

    If it's a third party app, best place to check will be the developer's website - have you tried that?
    If you need help with that, please post a link to their website or the direct link in the app store.

  • Finding all employees who come under the manager

    Hi experts,
    I have created a report which is attahced in MSS. So i want to restrict the manager to view the details of  only the employees who come under this manager.  At present the report is showing the details of all employees. So pls tell me whehter i can use O-S-P relation for finding all direct and indirect employees of the mnagaer by passing the org unit of the manager (or) should i need to find all position holders who report to the manager's position?..  If so, how?
    Finding the list of all employees who come under manager org unit is same as finding the list of position holders who report to the manager position? Pls telll me which is correct and how to find the same?

    hello shanthi,
    mashhour is right, it largely depends on how data is being maintained in your system.
    first, you are generally mixing two concepts together of finding "direct" & "indirect" employees for a manager. In standard implementations, typically the data is maintain in such a way where only 1 method is appropriate to find a manager's employee, and the most common scenario is where the employee has an indirect relationship with their manager. 
    So typically the two are not used together.  In certain circumstances companies will implement both to create matrix like scenarios, but they are better ways to handle this. 
    The indirect method: is called this way, because the manager has a relationship to an org unit as the chief (a012), and his/her employees are in positions, which have relationships to those same org units, hence no direct relationship.
    In the direct method, a relationship is created directly between the manager's position and any subordinates positions using the A/B 002 relationship. 
    Assuming that you are using indirect only, then O-S-P with no depth defined, will all employees belonging to that entire org structure.  this is assuming your program knows the root ID of the manager relationship, which is the a012 to the root org unit. 
    best regards,
    michael

  • How to find all tables that are associated with a given domain name.

    I want to find all table, excluding the structures, of a given domain name, say, waers.
    Some of the tables are directly contains the domains while others are related with a data element which is connected to that domain.
    I want to find tables for all two case -either tables connected directly to the domain or connected via data element- and exclude the structures.
    thanks in advance.

    Hi,
    The following thing may help you.
    in se11-> search for tables having names like 'DD*'.
    From this list of tables you can find the required table to get domain, data element nad table name.
    one way of doing it:
    SELECT rollname domname
      FROM dd04l
      INTO CORRESPONDING FIELDS OF TABLE it_tab.
    SELECT rollname tabname
      FROM dd03l
      INTO CORRESPONDING FIELDS OF TABLE it_tab1
      FOR ALL ENTRIES IN it_tab
      WHERE rollname = it_tab-rollname.
    SORT it_tab1.
    DELETE ADJACENT DUPLICATES FROM it_tab1.
    LOOP AT it_tab1 INTO wa_tab.
      MODIFY it_tab FROM wa_tab
      TRANSPORTING tabname
      WHERE rollname = wa_tab-rollname.
    ENDLOOP.
    LOOP AT it_tab INTO wa_tab.
      WRITE:/ wa_tab-domname,
              wa_tab-tabname.
    ENDLOOP.
    Regards,
    Manoj Kumar P

  • Find All Occurrences always fails within loop

    Dear forumers,
    There's this strange problem that requires a fix.
    Finding all occurences of '#' works fine here:-
    REPORT  zz_test.
    DATA: lv_text TYPE string,
          ls_result TYPE match_result,
          et_release type table of yytc_release,
          lt_result  TYPE match_result_tab.
    lv_text = '"RFC-1234#Create ""Payroll"" under NL directory"'.
      FIND ALL OCCURRENCES OF REGEX '#'
                IN lv_text
                RESULTS lt_result IGNORING CASE IN CHARACTER MODE.
      IF sy-subrc = 0.   " SY-SUBRC is always 0
        READ TABLE lt_result INTO ls_result INDEX 1.
        WRITE :'Offset: ' .
        WRITE: ls_result-offset .
        WRITE: lv_text+00(ls_result-offset).
      ENDIF.
    But it always fails here, within a loop at an internal table:-
    SELECT * .... INTO TABLE it_jira ...
    LOOP AT it_jira ASSIGNING <jira>.
      <release>-summary = <jira>-summary.
      IF <release>-type CS 'Subtask'.
        " <release>-summary is of data type CHAR255
        PERFORM get_subtask USING <release>-summary.  
      ENDIF.
    ENDLOOP.
    FORM get_subtask  USING    pv_summary TYPE yytc_release-summary.
      DATA:
        lv_string  TYPE char255,
        lv_final   TYPE char255,
        lv_summary TYPE string,
        lv_strlen  TYPE i,
        lt_result  TYPE match_result_tab.
      lv_string = pv_summary.     " LV_STRING = '"RFC-1234#Create ""Payroll"" under NL directory"''
      CONDENSE lv_string.
      lv_strlen = STRLEN( lv_string ).
      lv_strlen = lv_strlen - 1.
      IF lv_string+0(1) = '"' AND lv_string+lv_strlen(1) = '"'.
        lv_strlen = lv_strlen - 1.
        WRITE lv_string+1(lv_strlen) TO lv_final+1(254).
      ENDIF.
      lv_summary = lv_final.
    "  FIND ALL OCCURRENCES OF '#'
    "      IN lv_summary
    "    RESULTS lt_result IGNORING CASE.   * SY-SUBRC is always 4 here too
      FIND ALL OCCURRENCES OF REGEX '#'
          IN lv_summary
        RESULTS lt_result IGNORING CASE IN CHARACTER MODE.
      IF sy-subrc = 0.    " SY-SUBRC is always 4 here - why?!  :(
      ENDIF.
      CLEAR: lv_string,
             lt_result.
    ENDFORM.                    " GET_SUBTASK
    Only when the string LV_SUMMARY is edited from within the debugger (add space to the string prefix, etc), the SY-SUBRC will be 0 and there'll be data found in LT_RESULT.
    How can I resolve this issue? Please do help. Thanks.

    I think the subtle difference is that in your first example the character is actually '#' whereas in the second example it is actually another (unprintable)value such-as line-feed and only APPEARS to be '#'.
    You must find out what the value in question is(will it always be the same value?) and then replace that instead of '#'.

  • How do I find all the purchased items on my iPhone? When I try to update the iPhone iOS while connected to my MacBook it says there are purchased items on the phone that have not been transferred to my iTunes library and that I should transfer them.

    How do I find all the purchased items on my iPhone? When I try to update the iPhone iOS while connected to my MacBook it says there are purchased items on the phone that have not been transferred to my iTunes library and that I should transfer them before updating.

    Thanks. This seems to have worked easily.

Maybe you are looking for

  • [SOLVED]Mail Server and Drupal/Gallery2

    I set up this server, that's got a webpage running Drupal with Menalto Gallery2 running.  I've discovered that whenever a new user tries to register with either, no email is sent, and with Gallery2 an error message comes up.  So I figure I need a mai

  • Business Systems Limit

    Hi ALL, we have nearly 150 third party systems in our Project ,customer is asking to create all of them as Business systems in the SLD . i want to know like is there any limit for the number of business systems to be created in the SLD .. ? thanks So

  • Video Playback in indesign swf page flipper

    Hi I need to know if I can set movie file parameters. When I up load the interactive document with a movie file on the page the clip has to load fully before playing. It used to be [CS5] the movie clip would start playing after buffering a bit. But w

  • Playing content with computer from an ipod without syncing.

    Is there a way to watch what's on my ipod on a computer without syncing or 'tranfering purchases'? N.B. The ipod is synced with another computer.

  • DDL Error in Vista x64 SP2

    Hey, Curious to see if anyone else is having problems with Dolby Digital Li've on Vista x64 SP2. <img border="0" src="http://www.bhavikb.com/img/DDLerror.jpg" alt="DDL Error"> I am using Daniel_K's drivers (since they are more reliable for me in comp