0% found this document useful (0 votes)
6 views24 pages

mahi-graphs-reva

The document provides an overview of graphs, including their definitions, applications in real-world scenarios such as social networks and transportation systems, and various types of graphs. It explains how graphs can be represented using adjacency matrices and lists, and outlines traversal algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS). The document serves as a foundational guide to understanding graph theory and its practical implications.

Uploaded by

Palak Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views24 pages

mahi-graphs-reva

The document provides an overview of graphs, including their definitions, applications in real-world scenarios such as social networks and transportation systems, and various types of graphs. It explains how graphs can be represented using adjacency matrices and lists, and outlines traversal algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS). The document serves as a foundational guide to understanding graph theory and its practical implications.

Uploaded by

Palak Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

AGENDA

WHY GRAPHS,
INTRODUCTION
APPLICATIONS OF GRAPHS
TYPES OF GRAPHS,
REPESENTATIONS
TRAVERSALS

PROBLEM SOLVING
WHY GRAPHS?
• Graphs are used to represent many real-life entities.
• Consider a social network where people can follow other
people.
WHY GRAPHS?
• A graph can represent cities linked by roads.
GRAPHS

• A graph data structure is used to represent relations between pairs of


objects.
• It consists of nodes (known as vertices) that are connected through
links (known as edges).
• The relationship between the nodes can be used to model the relation
between the objects in the graph.

• This is what makes graphs important in the real world.


GRAPH TERMINOLOGIES
APPLICATIONS OF GRAPHS
In Computer science graphs are used to represent the flow of computation.

Google maps uses graphs for building transportation systems, where intersection of
two(or more) roads are considered to be a vertex and the road connecting two vertices
is considered to be an edge, thus their navigation system is based on the algorithm to
calculate the shortest path between two vertices.

In Facebook, users are considered to be the vertices and if they are friends then there
is an edge running between them. Facebook’s Friend suggestion algorithm uses graph
theory. Facebook is an example of undirected graph.
In World Wide Web, web pages are considered to be the vertices. There is an edge
from a page u to other page v if there is a link of page v on page u. This is an example
of Directed graph. It was the basic idea behind Google Page Ranking Algorithm.
In Operating System, we come across the Resource Allocation Graph where each
process and resources are considered to be vertices. Edges are drawn from resources
to the allocated process, or from requesting process to the requested resource. If this
leads to any formation of a cycle then a deadlock will occur.
TYPES OF GRAPHS

Undirected Graph Directed Graph

Weighted Graph Unweighted Graph


TYPES OF GRAPHS

Simple Graph
Non Simple Graph

Acyclic Graph Cyclic Graph


REPRESENTATION OF GRAPHS

GRAPHS

ADJACENCY ADJACENCY
MATRIX LIST
ADJACENCY MATRIX

In this representation, the graph can be represented using a matrix of size


total number of vertices by total number of vertices.

Here, rows and columns both represents vertices.

This matrix is filled with either 1 or 0.

1 represents there is an edge from row vertex to column vertex

0 represents there is no edge from row vertex to column vertex.


ADJACENCY LIST

In this representation, every vertex of graph contains a linked list of its


adjacent vertices.
REPRESENTATION OF DIRECTED GRAPH

ADJACENCY MATRIX
REPRESENTATION OF DIRECTED GRAPH

ADJACENCY LIST
REPRESENTATION OF UNDIRECTED GRAPH

ADJACENCY MATRIX
REPRESENTATION OF UNDIRECTED GRAPH

ADJACENCY LIST
REPRESENTATION OF WEIGHTED GRAPH

ADJACENCY MATRIX
REPRESENTATION OF WEIGHTED GRAPH

ADJACENCY LIST
GRAPH TRAVERSALS

TRAVERSALS

BREADTH FIRST DEPTH FIRST


SEARCH SEARCH
BREADTH FIRST SEARCH

Breadth-first search (BFS) is a graph search algorithm that begins at the root node
and explores all the neighbouring nodes.

Then for each of those nearest nodes, the algorithm explores their unexplored
neighbour nodes, and so on, until it finds the specified node.

A queue is used as an auxiliary data structure to keep track of the neighbouring


nodes.
STEPS TO PERFORM BFS
Step 1: Define a Queue of size total number of vertices in the graph.
Step 2: Select any vertex as starting point for traversal. Visit that vertex and insert it
into the Queue.
Step 3: Visit all the adjacent vertices of the vertex which is at front of the Queue
which is not visited and insert them into the Queue.
Step 4: When there is no new vertex to be visit from the vertex at front of the Queue
then delete that vertex from the Queue.
Step 5: Repeat step 3 and 4 until queue becomes empty.
Step 6: When queue becomes Empty, then produce final spanning tree by removing
unused edges from the graph
DEPTH FIRST SEARCH

The depth-first search algorithm progresses by expanding the starting node and then
going deeper until the goal node is found, or until a node that has no children is
encountered.
When a dead-end is reached, the algorithm backtracks, returning to the most recent
node that has not been completely explored.

It uses a stack as an auxiliary data structure.


STEPS TO PERFORM DFS
Step 1: Define a Stack of size total number of vertices in the graph.
Step 2: Select any vertex as starting point for traversal. Visit that vertex and push it on
to the Stack.
Step 3: Visit any one of the adjacent vertex of the vertex which is at top of the stack
which is not visited and push it on to the stack.
Step 4: Repeat step 3 until there are no new vertex to be visit from the vertex on top
of the stack.
Step 5: When there is no new vertex to be visit then use back tracking and pop one
vertex form the stack.
Step 6: Repeat steps 3, 4 and 5 until stack becomes Empty.
Step 7: When stack becomes Empty, then produce final spanning tree by removing
unused edges from the graph
ANY QUERIES?
KEEP WAITING FOR NEXT SESSION

You might also like