Tools / Data structures Interview questions
Difference between a Tree and Graph in Data structure.
| Tree. | Graph. |
| Tree is a special form of graph also called as minimally connected graph having only one path between any two vertices. | A graph vertices can have more than one path, that is, a graph can have uni-directional or bi-directional paths (edges) between nodes. |
| A tree has no loops, no circuits and no self-loops. | Graph can have loops, circuits and also self-loops. |
| There is only one root node and every child have only one parent. | In graph there is no such concept of root node. |
| In trees, there is parent child relationship between nodes. | In Graph there is no such parent child relationship. |
| Trees are less complex in nature then graphs. | Graphs are more complex than trees as it can have cycles, loops. |
| Types of trees are: Binary Tree , Binary Search Tree, AVL tree, Heaps. | Two types of Graphs are Directed and Undirected graph. |
| Tree always has n-1 edges. | In Graph, number of edges depends on the graph. |
| Tree is a hierarchical model. | Graph is a network model. |
| Tree is traversed in Pre-Order, In-Order and Post-Order. | Graph is traversed by DFS: Depth First Search and in BFS : Breadth First Search algorithm. |
More Related questions...