Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

graph theory

  • 31-07-2007 1:23am
    #1
    Closed Accounts Posts: 2,349 ✭✭✭


    Hi, I'm learning about graph theory as I was reading up about routing protocols on the internet and such. I've seen shortest path algorithms (bellman-ford and djikstra) to find the shortest route from a to b.

    I'm wondering if anyone knows any name (or general name) for an algorithm that simply confirms that there IS a path from A to B?


Comments

  • Registered Users, Registered Users 2 Posts: 219 ✭✭rjt


    grasshopa wrote:
    Hi, I'm learning about graph theory as I was reading up about routing protocols on the internet and such. I've seen shortest path algorithms (bellman-ford and djikstra) to find the shortest route from a to b.

    I'm wondering if anyone knows any name (or general name) for an algorithm that simply confirms that there IS a path from A to B?

    There are probably better ways, but try a Depth First Search.


  • Registered Users, Registered Users 2 Posts: 861 ✭✭✭Professor_Fink


    grasshopa wrote:
    I'm wondering if anyone knows any name (or general name) for an algorithm that simply confirms that there IS a path from A to B?

    I don't know any, but I can think one up fairly easily. To do it, we need to maintain some lists (which I'll call LIST1 and LIST2).

    1) Select vertex A
    2) Let A=C
    3) Add all vertices D for which an edge C->D exists to LIST1
    4) Add D to LIST2
    5) If B is in LIST1, stop (there exists a route)
    6) Remove all vertices in LIST2 from LIST1
    7) If LIST1 if empty, stop (a route does not exist)
    8) Assign some vertex from LIST1 to C
    9) Goto 3

    Should give you the answer in <N^2 repetitions, where N is the total number of vertices in the graph.

    I have assumed you were talking about a directed graph. If you just meant a simple non-directed graph, then you can work it out directly from the adjacency matrix.


Advertisement