Is there an algorithm (or a sequence of algorithms) to find, given a generic graph structure G=(V,E) with no notion of parent node, leaf node and child node but only neighboordhood relations:
1) If G it is a tree or not (is it sufficient to check |V| = |E|+1?)
2) If the graph is actually a tree, the leaves and the center of it? (i.e the node of the graph which minimizes the tree depth)
Thanks
If the “center” of the tree is defined as “the node of the graph which minimizes the tree depth”, there’s an easier way to find it than finding the diameter.
and the last one left in que is the center.
you can prove this by thinking about the diameter path.
to simpify , we assume the length of the diameter path is odd, so that the middle node of the path is unique, let’s call that node M,
we can see that:
diameter path has been pushed into que
that is pushed after M has already been pushed into que, then N must
be on a longer path than the diameter path. Therefore N can’t exist. M must be the last
node pushed (and left) in que