Differences between Tree & Graph Data-Structures.
Howdy folks! 😊
You know, almost every real time scenarios can be represented using either Graphs or Trees.Like from Facebook network or Linkedin network or cities on a map or electical network or structure of your organisation where you are working or family tree structure and so on...
Then why not take out some time and understand the differences between Graph and Tree data structures.
You know, almost every real time scenarios can be represented using either Graphs or Trees.Like from Facebook network or Linkedin network or cities on a map or electical network or structure of your organisation where you are working or family tree structure and so on...
Then why not take out some time and understand the differences between Graph and Tree data structures.
Tree
|
Graph
|
|
1
|
Tree has directions.
|
Graph can be uni-directional Or bi-directional both.
|
2
|
Tree do not have self-loops.
|
Graph can also have self-loops.
|
3
|
Between two nodes only one path can exists.
|
There can be multiple paths between two nodes.
|
4
|
All trees can be graph. That is tree can be considered as DAG(Directional
acyclic graph with the restriction that a child can only have
one parent)
|
All graphs cannot be trees.
|
5
|
Tree has parent and child relationship.
|
No parent and child relationship.
|
6
|
Tree always has n-1 edges.
|
In Graph, no. of edges depends on the graph.
|
7
|
Hierarchical model.
|
Network model.
|
8
|
Less Complex.
|
More Complex.
|
9
| Binary tree, AVL tree |
Directed graph, undirected graph.
|
10
|
Can be traversed using BFS or DFS in Pre-order,
In-order or Post-order manner.
|
Can be traversed using DFS or BFS.
|
11
|
That is it folks!
Hope this post helped you.Also don't forget to share and leave your comments below.
Comments
Post a Comment