Difference between graph and tree

Graph :

A graph is collection of two sets V and E where V is a finite non-empty set of vertices and E is a finite non-empty set of edges.

  • Vertices are nothing but the nodes in the graph.
  • Two adjacent vertices are joined by edges.
  • Any graph is denoted as G = {V, E}.

For Example:

G = {{V1, V2, V3, V4, V5, V6}, {E1, E2, E3, E4, E5, E6, E7}}

Tree :

A tree is a finite set of one or more nodes such that –

  1. There is a specially designated node called root.
  2. The remaining nodes are partitioned into n>=0 disjoint sets T1, T2, T3, …, Tn
    where T1, T2, T3, …, Tn is called the subtrees of the root.

The concept of tree is represented by following Fig.

Graph vs Tree

No. Graph Tree
1 Graph is a non-linear data structure. Tree is a non-linear data structure.
2 It is a collection of vertices/nodes and edges. It is a collection of nodes and edges.
3 Each node can have any number of edges. General trees consist of the nodes having any number of child nodes. But in case of binary trees every node can have at the most two child nodes.
4 There is no unique node called root in graph. There is a unique node called root in trees.
5 A cycle can be formed. There will not be any cycle.
6 Applications: For finding shortest path in networking graph is used. Applications: For game trees, decision trees, the tree is used.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.