I have read that Trees are special cases of Graphs. Graphs can be directed or undirected. But if we consider tree as a data structure is it directed or undirected graph?
See Tree on Wikipedia :
A tree is an undirected graph.
Unless qualified otherwise, trees in Mathematics or Graph Theory are usually assumed to be undirected, but in Computer Science or Programming or Data Structure, trees are usually assumed to be directed and rooted.
You need to be aware of the context of discussion.
See Tree on Wikipedia :
A tree is an undirected graph.
Trees are connected acyclic graphs. that means you should be able to traverse from any node u to any node v. If we say trees are directed then it may not be possible to traverse from every node u to every node v.
In context of rooted trees, direction just tells which node of tree is treated as root (starting point) or to show parent child relationship between nodes and that's it all it says ... this direction does not limit the connectivity of graph or a connection between any node u to node v of tree.[1]
[1] if we considered directions in rooted as actual path which can be traversed in tree to go from node u to node v, then connectivity would be broken and that graph would not be a tree any more.
Both are acceptable. You may have some cases where you want to be able to go up from a leaf and then go back down (usually in another branch), or you may want to be able to go only down.
1-Trees are a subset of graphs.
2-They are undirected acyclic graphs. (Many times we need to go back from leaf nodes to previous nodes to change branches , with unidirectional edges it is not possible)
© 2022 - 2024 — McMap. All rights reserved.