Reputation: 4928
In the book I am reading it tells me to choose a vertex with depth 0 but I do not understand how depth is calculated in a graph.
Looking at above example, it chooses vertex A as its starting point and explains that it has depth 0. In my understanding it has depth 0 because it has 0 in-degree (no incoming edges).
But what if the graph is un-directed how do we calculate its depth?
If I think of it as a tree where A is the root it seems to me that I assign G to be the root and thus this time G would have depth 0 thus become a starting point.
I've watched lectures, read articles but cannot figure out how to find a starting point in an un-directed graph and for directed graph is my understanding correct (0 depth => 0 in-degree)?
Thanks in advance.
Upvotes: 0
Views: 958
Reputation: 54
No, your understanding is incorrect. Because there is no depth of for graph . In graph we use starting point , it is given by problem setter.
There is no depth in graph .
Let's we take a example :- What is the depth of Node E is your example
--If we follow path A->B->E
then 2
--If we follow path A->C->D->E
then 3
If there is no incoming edge in any node and you didn't choose it then it will not come in traversal . So you choose A as starting point(you said it "depth 0").
And in undirected graph you can choose any node as starting node according your algorithm .
Depth term is use for Tree data structure. Hopeful , Now you understand what I am saying.
And I am able to clear your confusion.
Upvotes: 1