# Difference Between Tree and Graph

By Mona Kumari|Updated : October 5th, 2022

The Difference Between Tree and Graph is that a cycle can be represented in a graph, whereas in trees, there is no cycle representation. This article explains the difference between graph and tree; we will discuss various parameters based on which these two data structures differ. Graphs and trees are non-linear data structures that store, traverse and retrieve data. Though the two data structures still perform exactly the same task, the difference between the graph and tree exists.

Difference Between Tree and Graph PDF

Apart from discussing the major difference between Tree and Graph, we will also learn about the two data structures individually, how they are used to store data, how to find an element stored in them, what is the basic difference and which among the two is preferred most. Let's understand each one individually in the sections given below.

## Difference Between Tree and Graph

Trees and graphs are useful in programming because they depict nonlinear data. A tree is an exception to the rule of graphs because it does not loop, but graphs can. Both the graph and the tree have certain similarities, but they also have some distinctions. It is an essential topic in the GATE CSE syllabus. In the table below, let's look at the difference between a tree and a graph.

### Key Differences Between Tree and Graph

 Graph Tree The graph is a non-linear data structure. The tree is a non-linear data structure. It is a collection of vertices/nodes and edges. It is a collection of nodes and edges. A node in a graph can have any number of edges. A tree consists of nodes having any number of child nodes, while a binary tree has at most two child nodes. There is no unique node called the starting node in a graph. There is a unique node called root in trees. A cycle can be present in a graph No cycle can be present in a tree. Applications: The graph is used to find the shortest path in networking. Applications: The tree data structure is preferred for game and decision trees.

## What is a Graph?

The graph is a non-linear data structure. It is a collection of nodes and edges where V represents the finite set, a non-empty set of nodes, and E represents the finite and non-empty set of edges. Graphs and questions based on graphs are seen vividly in the GATE question paper. The key points to represent a graph are:

• Nodes are nothing but the vertices of the graph.
• An edge E connects two adjacent nodes
• Any graph is denoted by G={V,E}

For example:

## What is a Tree?

A tree is a non-linear data structure. It is also referred to as an acyclic graph i.e a graph with no cycles present in it, this is one of the basic differences between a graph and a tree. A tree is a finite set of one or more nodes such that:

• A tree has a special node called the root node.
• The rest of the nodes are partitioned into disjoint sets T1, T2,… Tn where T1, T2,…. Tn is called the subtrees of the root.

For example:

## Applications of Tree and Graph

Graphs and trees are used in various searching and minimizing techniques over the web. This is an essential topic as per the GATE exam as well. The graph data structure is used to minimize the cost from one end to another end, finding the shortest distance between two points/ nodes. The tree data structure is used in the binary search tree, and hierarchal trees and organizing trees are also used in gaming and related fields.

Further, let us see some other related articles.

 Related GATE Links Difference Between Email and Gmail Difference between first and third angle projection Difference Between Linux and Windows Difference between half adder and full adder Difference between impact and non-impact printers Difference Between Algorithm and Flowchart

write a comment

## FAQs on Difference Between Tree and Graph

• The very basic difference between graph and tree is that a graph consists of cycles while a tree is an acyclic graph that do not consists of any cycle. A tree has zero cycles

• The number of edges difference between graph and tree is as follows. A graph can have a maximum of n(n-1)/2 edges while a tree always consists of n-1 edges. This difference in the number of edges is because of the acyclic graph property of the tree.

• Graph data structure has applications in many fields in computer science, graphs algorithms are widely used by google maps, facebook, image processing etc to find the shortest path or minimized cost.

• To find the shortest distance between two nodes in a graph we have several algorithms such as Dijkstra’s algorithm, Bellmen ford algorithm, Floyd warshall algorithm etc.

• There is a major difference between the number of nodes in a graph and a tree such that a graph can have any number of nodes and no special node present in tree while in tree there is a special node called the root node which is the starting vertex of the tree, every other tree node is referred to as right node and left node.

### GATE & PSU CS

Computer ScienceGATEGATE CSENIELITOther ExamsQuick LinksMock Test