Learning Path
A New Journey of Knowledge Awaits
Graph

Graph Data Structure
In this tutorial, you will learn what a Graph Data Structure is. Also, you will find representations of a graph. A graph data structure is a collection of nodes that have data and are connected to other nodes. Let's try to understand this through an example. On facebook, everything is a node. That includes User, Photo, Album, Event, Group, Page, Comment, Story, Video, Link, Note...anything that has data is a node. Every relationship is an edge from one node to another. Whether you post a photo, join a group, like a page, etc., a new edge is created for that relationship.

Graph Terminology
Adjacency: A vertex is said to be adjacent to another vertex if there is an edge connecting them. Vertices 2 and 3 are not adjacent because there is no edge between them.
Path: A sequence of edges that allows you to go from vertex A to vertex B is called a path. 0-1, 1-2 and 0-2 are paths from vertex 0 to vertex 2.
Directed Graph: A graph in which an edge (u,v) doesn't necessarily mean that there is an edge (v, u) as well. The edges in such a graph are represented by arrows to show the direction of the edge.

Graph Representation
Graphs are commonly represented in two ways:
1. Adjacency Matrix An adjacency matrix is a 2D array of V x V vertices. Each row and column represent a vertex. If the value of any element a[i][j] is 1, it represents that there is an edge connecting vertex i and vertex j.
2. Adjacency List An adjacency list represents a graph as an array of linked lists. The index of the array represents a vertex and each element in its linked list represents the other vertices that form an edge with the vertex.
Graph Operations
The most common graph operations are:
Check if the element is present in the graph
Graph Traversal
Add elements(vertex, edges) to graph
Finding the path from one vertex to another

Relevant Links
Exercise (Score 75% or more to complete this chapter)
1. What is the number of edges present in a complete graph having n vertices?
1. (n*(n+1))/2
2. (n*(n-1))/2
3. n
4. Information given is insufficient
2. A connected planar graph having 6 vertices, 7 edges contains _____________ regions.
1. 15
2. 3
3. 1
4. 11
3. Which of the following properties does a simple graph not hold?
1. Must be connected
2. Must be unweighted
3. Must have no loops or multiple edges
4. Must have no multiple edges
4. What is the maximum number of edges in a bipartite graph having 10 vertices?
1. 24
2. 21
3. 25
4. 16