0% found this document useful (0 votes)
7 views31 pages

Graph

The document provides an overview of graph theory, including key terminology such as vertices, edges, and types of graphs (directed, undirected, weighted, etc.). It also discusses graph representations, algorithms like Breadth-First Search (BFS), Depth-First Search (DFS), and Dijkstra's algorithm for finding the shortest path in weighted graphs. Applications of graphs in various fields such as social networks, transportation, and data science are highlighted.
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)
7 views31 pages

Graph

The document provides an overview of graph theory, including key terminology such as vertices, edges, and types of graphs (directed, undirected, weighted, etc.). It also discusses graph representations, algorithms like Breadth-First Search (BFS), Depth-First Search (DFS), and Dijkstra's algorithm for finding the shortest path in weighted graphs. Applications of graphs in various fields such as social networks, transportation, and data science are highlighted.
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/ 31

GRAPH

BY: TANVI MADHWANI | VAIDEHI KACHAWA | UMESH TANK | UDIT


PATEL | YASH PATEL
INDEX

o GRAPH
o GRAPH THEORY
(TERMINOLOGY)
o TYPES OF GRAPH
o GRAPH
REPRESENTATIONS
GRAPH
A GRAPH IS A PICTORIAL AND MATHEMATICAL REPRESENTATION OF A SET OF
OBJECTS WHERE SOME PAIRS OF OBJECTS ARE CONNECTED BY LINKS.
THE INTERCONNECTED OBJECTS ARE REPRESENTED BY POINTS TERMED AS
VERTICES OR NODES AND THE LINKS THAT CONNECT THE VERTICES ARE CALLED
EDGES OR ARCS OR LINES
GRAPH THEORY
FUNDAMENTAL CONCEPTS
(TERMINOLOGY)
• Point
• Line
• Vertex
• edge
POINT

o A POINT IS A PARTICULAR POSITION


THAT IS LOCATED IN A SPACE. SPACE
CAN BE ONE-DIMENSIONAL , TWO-
DIMENSIONAL OR THREE-
DIMENSIONAL SPACE . A DOT IS
USED TO REPRESENT A POINT IN
GRAPH AND IT IS LABELED BY
ALPHABET , NUMBERS OR
ALPHANUMERIC VALUES .
LINE

o TWO POINTS ARE CONNECTED TO


EACH OTHER THROUGH A LINE . A
LINE IS A CONNECTION BETWEEN 2
POINTS . IT IS REPRESENTED BY A
SOLID LINE .
VERTEX

o A VERTEX IS A SYNONYM OF POINT IN GRAPH


I.E. ONE OF THE POINTS ON WHICH THE
GRAPH IS DEFINED AND WHICH MAY BE
CONNECTED BY LINES/EDGES IS CALLED
VERTEX.
o A VERTEX IS ALSO KNOWNS AS “NODE” ,
”POINT” OR “JUNCTION”. A VERTEX IS
DENOTED BY ALPHABETS , NUMBERS OR
ALPHANUMERIC VALUE.
EDGE
o IT IS THE CONNECTION BETWEEN 2 VERTICES. EACH
In-Directed edge EDGE CONNECTS 1 VERTEX TO ANOTHER VERTEX IN
THE GRAPH . WITHOUT A VERTEX , AN EDGE CANNOT
BE FORMED . IT IS ALSO CALLED LINE , BRANCH ,
LINK OR ARC .
o EDGE CAN EITHER BE DIRECTED OR IN-DIRECTED .
A DIRECTED EDGE IS THE EDGE WHICH POINTS
FROM 1 VERTEX TO ANOTHER , AND AN UNDIRECTED
EDGE HAS NO DIRECTION.

Directed o IF THERE IS A DIRECTED EDGE FROM VERTEX A TO B


edge AND A DIRECTED EDGE FROM B TO A , THIS WOULD
ESSENTIALLY BE EQUIVALENT TO AN UNDIRECTED
EDGE CONNECTING A AND B.
o EXAMPLE: IF ‘A’ N ‘B’ ARE THE VERTICES AND THE
LINK ‘AB’ B\W THEM IS CALLED EDGE.
APPLICATIONS
o SPORT DATA SCIENCE , GRAPH AS CAN BE USED TO
ANALYZE AND UNDERSTAND THE DYNAMICS OF
TEAM PERFORMANCE AND PLAYER INTERACTION ON
THE FIELD .
o SOCIAL NETWORK ANALYSIS
o COMPUTER NETWORK: CONNECTION BETWEEN
ROUTERY AND SWITCHY.
o TRANSPORTATION , ROADS AND AIRPORTS
TYPES OF GRAPH
TYPES OF GRAPHS

o IN-DIRECTED GRAPH
o DIRECTED GRAPH
o COMPLETE GRAPH
o WEIGHTED GRAPH
o UNWEIGHTED GRAPH
• DEFINITION: IN AN
UNDIRECTED GRAPH, THE
EDGES DO NOT HAVE A
DIRECTION. THE
CONNECTION BETWEEN
TWO VERTICES IS MUTUAL,
MEANING IF THERE'S AN
EDGE BETWEEN VERTEX A
AND VERTEX B, YOU CAN
TRAVEL IN BOTH
DIRECTIONS (A ↔ B).
• EXAMPLE: SOCIAL
NETWORKS (WHERE A
FRIENDSHIP IS A MUTUAL
RELATIONSHIP).
GRAPH, EDGES HAVE A
DIRECTION. EACH EDGE
HAS A STARTING VERTEX
(SOURCE) AND AN ENDING
VERTEX (DESTINATION). YOU
CAN ONLY TRAVEL FROM THE
SOURCE VERTEX TO THE
DESTINATION VERTEX, NOT
THE OTHER WAY AROUND
UNLESS THERE IS A SEPARATE
EDGE.
• EXAMPLE: WEB PAGE LINKS,
WHERE ONE PAGE LINKS TO
ANOTHER BUT NOT
NECESSARILY THE REVERSE.
3. COMPLETE GRAPH
• DEFINITION: A COMPLETE GRAPH
IS A GRAPH IN WHICH EVERY PAIR
OF VERTICES IS CONNECTED BY A
UNIQUE EDGE. EVERY VERTEX IS
DIRECTLY CONNECTED TO EVERY
OTHER VERTEX.
• EXAMPLE: A SMALL GROUP OF
FRIENDS WHERE EACH PERSON
KNOWS EVERY OTHER PERSON.
• DEFINITION: IN AN UNWEIGHTED
GRAPH, THE EDGES DO NOT HAVE
WEIGHTS. ALL EDGES ARE
CONSIDERED EQUAL.
• EXAMPLE: A SIMPLE SOCIAL
NETWORK, WHERE THE EDGES
REPRESENT CONNECTIONS
WITHOUT ANY STRENGTH OR
WEIGHT.
• DEFINITION: A WEIGHTED
GRAPH IS A GRAPH IN WHICH
EACH EDGE HAS A WEIGHT (OR
COST). THIS WEIGHT
REPRESENTS A QUANTITY, SUCH
AS DISTANCE, TIME, OR COST,
ASSOCIATED WITH THE EDGE.
• EXAMPLE: ROAD NETWORKS,
WHERE THE WEIGHT COULD
REPRESENT THE DISTANCE OR
TIME BETWEEN TWO
LOCATIONS.
ADJCENT NODES
• IF TWO NODES ARE
CONNECTED VIA AN EDGE
THEN THE NODES ARE
CALLED ADJCENT NODES
DEGREE OF A
NODE
• A Degree Of A Node Is The
Number Of Edges That Are
Connected With That Node.
• A Node With Degree 0 Is
Called An Isolated Node.
GRAPH
REPRESENTATION

o In graph theory, a graph representation is a technique to


store graph into the memory of computer.
o To represent a graph, we just need the set of vertices, and
for each vertex the neighbors of the vertex (vertices which is
directly connected to it by an edge). If it is a weighted graph,
then the weight will be associated with each edge .
o There are different ways to optimally represent a graph,
depending on the density of its edges, type of operations to
be performed and ease of use.
ADJACENCY MATRIX

o Adjacency matrix is a sequential representation.


o It is used to represent which nodes are adjacent to each other. i.e. is there any
edge connecting nodes
o In this representation, we have to construct a nXn matrix A. If there is any edge
from a vertex i tovertex j, then the corresponding element of A, a',/ = 1, otherwise
a',= 0.
o If there is any weighted graph then instead of Is and Os, we can store the weight of
the edge.
o Consider the following undirected graph representation:
A -- B A B C D
UNDIRECTED |
C -- D
A 0 1 1 0

GRAPH B 1 0 0 0
C 1 0 0 1
REPRESENTATION D 0 0 1 0

Explanation:
• The matrix element at row A, column B is 1, indicating an edge between A and B.
• The element at row B, column A is also 1 (since the graph is undirected, an edge from B
to A is also represented).
• The matrix element at row A, column C is 1, indicating an edge between A and C.
• The matrix element at row C, column A is also 1 (since the graph is undirected, an edge
from C to A is also represented).
• Similarly, the edge between C and D is represented in both the C→DC \to DC→D and
D→CD \to CD→C positions.
A→B→C→A A B C D

DIRECTED D
A 0 1 0 0

GRAPH B 0 0 1 0
C 1 0 0 1
REPRESENTATION D 0 0 1 0

Explanation:
• The matrix element at row A, column B is 1, indicating that there is a directed
edge from A to B.
• Similarly, the element at row B, column C is 1, showing an edge from B to C.
• The element at row C, column A is 1, indicating an edge from C to A.
• The element at row D, column C is 1, indicating an edge from D to C.
• All other matrix entries are 0, meaning there are no edges in those directions.
ADJACENCY LIST

o Adjacency list is a linked representation.


o In this representation, for each vertex in the graph, we maintain the list of
its neighbors. It means, every vertex of the graph contains list of its
adjacent vertices.
o We have an array of vertices which is indexed by the vertex number and for
each vertex v, the corresponding array element points to a singly linked list
of neighbors of v.
BREADTH-FIRST SEARCH (BFS)

o BFS (Breadth-First Search) is a graph traversal algorithm used to explore nodes level by
level. It visits all the neighbors of a node before moving to the next level.
🔹 How does BFS work?
o 1.Start from a source node.
o 2.Use a queue to keep track of the nodes to visit.
o 3.Mark the starting node as visited and enqueue it.
o 4.While the queue is not empty:
Dequeue a node.
Visit all its unvisited neighbors.
Mark them visited and enqueue them.
BREADTH-FIRST SEARCH (BFS)

o BFS (Breadth-First Search) is a graph traversal algorithm used to explore nodes level by
level. It visits all the neighbors of a node before moving to the next level.
🔹 How does BFS work?
o 1.Start from a source node.
o 2.Use a queue to keep track of the nodes to visit.
o 3.Mark the starting node as visited and enqueue it.
o 4.While the queue is not empty:
Dequeue a node.
Visit all its unvisited neighbors.
Mark them visited and enqueue them.
BREADTH-FIRST SEARCH (BFS)

✅ Step-by-step BFS Algorithm

1.queue Q is created
2.Mark all nodes as unvisited
3.Mark the starting node s as visited and enqueue it into Q
4.While the queue is not empty:
•Dequeue a node v from Q
•Visit node v
•For each neighbor u of v:
•If u is not visited:
•Mark u as visited
•Enqueue u into Q
DEPTH-FIRST SEARCH (DFS)

o DFS (Depth-First Search) is a graph or tree traversal algorithm that


explores as deeply as possible along each branch before backtracking.
o It is called Depth-First because it goes deep into the graph (or tree) before
exploring siblings.
o 📦 How DFS Works
1. Start from a selected node (usually called the source or root).
2. Visit the node and mark it as visited.
3. Explore one of its unvisited neighbors, and repeat step 2.
4. If there are no unvisited neighbors, backtrack to the previous node.
5. Repeat the process until all reachable nodes are visited.
DEPTH-FIRST SEARCH (DFS)

✅ Key Data Structures Used


• Uses a stack (LIFO) — either explicitly (using a stack) or via recursion (call stack).
• A visited array or set to keep track of visited nodes.
📌 Applications of DFS
• Finding connected components in a graph
• Topological sorting (in DAGs)
• Cycle detection
• Path finding (like maze solving)
• Artificial intelligence (game trees)
📌 WHAT IS DIJKSTRA’S ALGORITHM?
DIJKSTRA’S ALGORITHM IS USED TO FIND THE SHORTEST
PATH FROM A STARTING NODE TO ALL OTHER NODES IN A
WEIGHTED GRAPH (WITH NON-NEGATIVE WEIGHTS).
o IT IS A GREEDY ALGORITHM — IT ALWAYS CHOOSES THE
SHORTEST KNOWN PATH AT EACH STEP.
🧠 KEY CONCEPTS
• WORKS ON GRAPHS WITH NON-NEGATIVE WEIGHTS.
• RETURNS THE MINIMUM DISTANCE FROM
THE SOURCE TO EVERY OTHER VERTEX.
• COMMONLY USED IN ROUTING AND MAP NAVIGATION
SYSTEMS.
✅ Steps of Dijkstra’s Algorithm
1.Initialize:
•Distance to all nodes = ∞ (infinity), except the source node (distance = 0).
•Use a priority queue (or min-heap) to store nodes by current shortest distance.

2.Process nodes:
•Pick the node with the smallest distance from the queue.
•For each neighbor, calculate:
new_distance = current_distance + edge_weight
•If new_distance is less than previously known distance:
•Update the distance
•Add neighbor to the priority queue

3.Repeat until all nodes are processed.


THANK YOU

TANVI MADHWANI | VAIDEHI KACHAWA | UMESH TANK | UDIT PATEL | YASH


PATEL

You might also like