Determining whether or not a directed or undirected graph is a tree

后端 未结 3 504
Happy的楠姐
Happy的楠姐 2020-12-30 02:59

I would like to know of a fast algorithm to determine if a directed or undirected graph is a tree.

This post seems to deal with it, but it is not very clear; accordi

3条回答
  •  再見小時候
    2020-12-30 03:32

    An undirected graph is a tree when the following two conditions are true:

    1. The graph is a connected graph.
    2. The graph does not have a cycle.

    A directed graph is a tree when the following three conditions are true:

    1. The graph is a connected graph.
    2. The graph does not have a cycle.
    3. Each node except root should have exactly one parent.

提交回复
热议问题