0% found this document useful (0 votes)
2 views15 pages

Graph Data Structure

A graph is a collection of nodes and edges that models relationships between objects, with types including directed, undirected, weighted, and unweighted graphs. Graphs can be represented in memory using adjacency matrices or adjacency lists, and traversal algorithms like Depth First Search (DFS) and Breadth First Search (BFS) are used to explore their structure. Applications of graph data structures span various fields such as social networks, transportation routes, and game pathfinding.
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)
2 views15 pages

Graph Data Structure

A graph is a collection of nodes and edges that models relationships between objects, with types including directed, undirected, weighted, and unweighted graphs. Graphs can be represented in memory using adjacency matrices or adjacency lists, and traversal algorithms like Depth First Search (DFS) and Breadth First Search (BFS) are used to explore their structure. Applications of graph data structures span various fields such as social networks, transportation routes, and game pathfinding.
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/ 15

Presented by

M Usman(15434)
Muneeb Ahmad(15435)
M Saad(15432)
Taha Saeed(15433)
NaheemUllah(15436)
Graph data structure
What is a Graph?

• graph is a collection of nodes(vertices) and edges


connecting pairs of nodes.
• It models relationship between objects.
• Graphs can represent networks such as social connections,
roads or computer networks.
Types of graph

• Directed: Edges have direction (A → B).


• Undirected: Edges have no direction (A —
B).
• Weighted: Edges have values like cost or
distance.
• Unweighted: All edges are equal.
Graph representation

graph representation refers to how graph is


stored in memory.
• Adjacency matrix: A 2D table where each cell
shows if there is a connection between two
nodes.
• (1=connected , 0=not connected)
Adjacency matrix
Adjacency list

• Each vertex stores a list of its directly


connected vertices(neighbours).
• Memory efficient especially for sparse
graph(graph with few edges).
Adjacency list
Graph traversal algorithm

• A method to visit all nodes in a graph


systematically.
• Helps explore or search the graph’s structure.
• Used in tasks like finding paths,checking
connectivity and searching.
Graph traversal algorthm

Depth first search(DFS)


• A graph traversal method that explores deep
into each path before backtracking.
• Starts from a selected node and visits
unvisited neighbours recursively.
• Continues until all reachable nodes are
visited.
Graph traversal algorithm

DFS(algorithm)
• Start from a node.
• Mark the node as visited.
• Go to the next unvisited neighbor.
• Repeat the process for each new node.
• If no more neighbors, go back (backtrack) and
try others.
Graph traversal algorithm

Breadth first search(BFS)


• Breadth First Search (BFS) visits all nodes
level by level, starting from a node and
exploring its neighbors before moving deeper.
Graph traversal algorithm

BFS (algorithm)
• Start with the first node; put it in a queue.
• Mark this node as visited.
• Repeat until the queue is empty:
a. Take the front node from the queue.
b. Look at all its neighbors.
c. For each neighbor not visited yet:
- Mark it visited.
- Add it to the queue.
Graph traversal algorithm
Applications of graph data structure

• Social networks
• Web page links
• Transportation routes
• Network data routing
• Recommendations
• Task scheduling
• Circuit design
• Game pathfinding

You might also like