# Introduction to Graph in Data Structure

**Graph in Data Structure**: In this article, we are going to **see what is graph data structure and types of graphs**?

Submitted by Souvik Saha, on March 17, 2019

What you are going to learn?

In this article, we learn about the **introduction to Graphs in Data Structure and Algorithm**.

- What are the
**components in Graph**? **Types of the Graphs**.- How we use the
**Graph**data structure?

## Graph

The **graph** is an abstract data type in computer science. It maps the value between two data nodes.

**Figure 1.1**

### Components

**1) Node:** In the above example, Graph(Figure 1.1) there is a set of nodes. Nodes basically store values of data types ( int, float etc). In the example A, B, C, D, E, F are the nodes of the graph.

**2) Edge:** In the example graph, there is a set of edges in a graph. Edges make a relationship between two nodes or they are a connection between nodes in a graph. In the example e1 , e2, e3, e5, e6 ,e7,e8are the edges in that graph. Edges can be weighted or unweighted. In the case of a weighted edge, each edge is assigned a weight.

### Types

There are two **types of graphs**,

**1) Directed Graph:** When all the edges have a direction from one node to another node then the graph is called Directed Graph. (Figure 1.2)

**Figure 1.2**

**2) Undirected Graph:** When all the edges have no direction then it called Undirected Graph. The edges start from one node and go to another node. (Figure 1.1)

**Real life Application of graphs:**

- Building recommendation system for e-commerce websites
- Facebook friend circle
- GPS system Google maps

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions