1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Depth first search of graph

  1. Aug 9, 2014 #1

    Maylis

    User Avatar
    Gold Member

    ImageUploadedByPhysics Forums1407629937.062203.jpg

    Hello, I drew up this graph to try and understand the concept of depth-first search. Starting at node C, I was wondering if its correct for the order to be C-A-B-D or C-B-A-D? It seems like you can traverse in either direction without a problem.
     
  2. jcsd
  3. Aug 10, 2014 #2

    verty

    User Avatar
    Homework Helper

    For me, both are valid. You could certainly look at all the children, order them by some preference and visit each one in that order.
     
  4. Aug 10, 2014 #3

    Maylis

    User Avatar
    Gold Member

    I'm confused as to what movements are not allowed? It seems very unclear to me what is a legitimate traversal and what isn't. Can you go C-D-B-A or C-D-A-B??? What counts as not being permitted?
     
  5. Aug 10, 2014 #4

    verty

    User Avatar
    Homework Helper

    Depth-first means the whole subtree of each child node is processed before any other child nodes are processed. Does that make sense? Your example tree is a bad example because the children of C have no children themselves.

    Oh sorry, you are talking about a graph, not a tree. Hmm.
     
  6. Aug 10, 2014 #5

    verty

    User Avatar
    Homework Helper

    Ok, for a graph, depth-first must mean, process every unvisited neighbor before backtracking. CAD -- not allowed.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted