# 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 = {{V_{1}, V_{2}, V_{3}, V_{4}, V_{5}, V_{6}}, {E_{1}, E_{2}, E_{3}, E_{4}, E_{5}, E_{6}, E_{7}}}

**Tree : **

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

- There is a specially designated node called root.
- The remaining nodes are partitioned into n>=0 disjoint sets T
_{1}, T_{2}, T_{3}, …, T_{n}

where T_{1}, T_{2}, T_{3}, …, T_{n}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.

## Recommended Posts:

- Check if a given graph is tree or not
- Convert Directed Graph into a Tree
- Check if a given tree graph is linear or not
- DFS for a n-ary tree (acyclic graph) represented as adjacency list
- Tree, Back, Edge and Cross Edges in DFS of Graph
- Check whether given degrees of vertices represent a Graph or Tree
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Sub-tree with minimum color difference in a 2-coloured tree
- Minimum difference between any two weighted nodes in Sum Tree of the given Tree
- Maximum number of edges to be added to a tree so that it stays a Bipartite graph
- Difference between General tree and Binary tree
- Difference Between sum of degrees of odd and even degree nodes in an Undirected Graph
- Difference between Binary tree and B-tree
- Convert the undirected graph into directed graph such that there is no path of length greater than 1
- Maximum number of edges that N-vertex graph can have such that graph is Triangle free | Mantel's Theorem
- Difference between B tree and B+ tree
- Graph implementation using STL for competitive programming | Set 2 (Weighted graph)
- Detect cycle in the graph using degrees of nodes of graph
- Difference between Binary Tree and Binary Search Tree
- Difference between sum of even and odd valued nodes in a Binary Tree

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.