** Tree vs Graph in Data Structure **

Since trees and graph are the non-linear data structures that are used to solve complex computer problems, knowing the difference between tree and graph in data structure is useful. Both data structures represent the data items in the mathematical form. The main objective of the article is to highlight the significance of nonlinear data structures. It also includes key difference between these two data structures.

## What is a Tree in Data Structure?

Tree is a non-linear data structure in which all data items are arranged in some sorted sequence. Tree defines a finite set of data items. Each data item is termed as node. There is a special parent node that is also termed as the root node. All other nodes are child node or sub child nodes. The main objective of the tree is to represent hierarchical relationship between different data items. Normal tree grows in the upper direction, but data structure tree grows in down direction. All sub-nodes attached with the tree are divided into various levels. Binary tree is the most common example of non-linear data structure. The maximum degree of a binary tree is two. It means maximum two nodes can be attached with every parent node.

## What is Graph in Data Structure?

Graph is a popular non-linear data structure that is used to solve various computer problems. They are used to design various games and puzzles. Graphs can be divided into many categories. These are:

• **Directed Graph:** In the directed graph, each edge is defined by ordered pair of vertices.

•** Non-Directed Graph:** In the undirected graph, each edge is defined by unordered pair of vertices

• **Connected graph:** In the connected path, there is a path from every vertex to every other vertex.

•** Non Connected Graph:** In the non-connected graph, path does not exist from any vertex to any other vertex.

• **Weighted Graph:** In the weighted graph, some weight is attached to the edge.

• **Simple Graph** or **Multi Graph**

## Similarities between Tree and Graph in Data Structure

• Trees and graph both are non-linear data structure that are used to resolve complex computer problems.

• Both data structures use a parent node and multiple sub-nodes.

## What is the difference between Tree and Graph in Data Structure?

• Tree is considered as a special case of graph. It is also termed as a minimally connected graph.

• Every tree can be considered as a graph, but every graph cannot be considered as a tree.

• Self-loops and circuits are not available in the tree as in the case of graphs.

• For designing tree, you require a parent node and various sub-nodes. For designing a graph, you require vertices and edges. Edge is a pair of vertices.

The above discussion concludes that tree and graph are the most popular data structures that are used to resolve various complex problems. Graphs are a more popular data structure that is used in computer designing, physical structures and engineering science. Most of the puzzles are designed with the help of graph data structure. Shortest distance problem is the most commonly used data structure. In this problem, we have to calculate the shortest distance between two vertices.

Further Reading:

## Leave a Reply