0% found this document useful (0 votes)
4 views

Module 10 - Graphs Operation and Traversal

The document outlines graph operations and traversal techniques in data structures, detailing operations such as inserting and deleting vertices and edges. It explains two primary traversal algorithms: Breadth-First Search (BFS) and Depth-First Search (DFS), including their respective steps and requirements. Additionally, it provides references for further reading on graph theory and data structures.

Uploaded by

Loki Legends
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Module 10 - Graphs Operation and Traversal

The document outlines graph operations and traversal techniques in data structures, detailing operations such as inserting and deleting vertices and edges. It explains two primary traversal algorithms: Breadth-First Search (BFS) and Depth-First Search (DFS), including their respective steps and requirements. Additionally, it provides references for further reading on graph theory and data structures.

Uploaded by

Loki Legends
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

IT07-IT07L Data Structure and Algorithm

1
Module 10: Graph Operations and Traversal

Graph Operations
In the mathematical field of graph theory, graph operations are operations which produce
new graphs from initial ones.

The operations you perform on the graphs in data structures are listed below:

• Insert vertex
• Delete vertex
• Insert edge
• Delete edge

You will go over each operation in detail one by one:

Insert Vertex
When you add a vertex that after introducing one or more vertices or nodes, the graph's
size grows by one, increasing the matrix's size by one at the row and column levels.

Delete Vertex
• Deleting a vertex refers to removing a specific node or vertex from a graph that has been
saved.
• If a removed node appears in the graph, the matrix returns that node. If a deleted node
does not appear in the graph, the matrix returns the node not available.
Course Module

Insert Edge
Connecting two provided vertices can be used to add an edge to a graph.

Delete
Edge
The connection between the vertices or nodes can be removed to delete an edge.
IT07-IT07L Data Structure and Algorithm
3
Module 10: Graph Operations and Traversal
Graph Traversal Algorithm
The process of visiting or updating each vertex in a graph is known as graph traversal. The
sequence in which they visit the vertices is used to classify such traversals. Graph traversal
is a subset of tree traversal.

There are two techniques to implement a graph traversal algorithm:


• Breadth-first search
• Depth-first search.

Breadth-First Search or BFS


BFS is a search technique for finding a node in a graph data structure that meets a set of
criteria.
• It begins at the root of the graph and investigates all nodes at the current depth level
before moving on to nodes at the next depth level.
• To maintain track of the child nodes that have been encountered but not yet inspected,
more memory, generally you require a queue.

Algorithm of breadth-first search


Step 1: Consider the graph you want to navigate.
Step 2: Select any vertex in your graph, say v1, from which you want to traverse the graph.
Step 3: Examine any two data structures for traversing the graph.

Course Module
• Visited array (size of the graph)
• Queue data structure
Step 4: Starting from the vertex, you will add to the visited array, and afterward, you will
v1's adjacent vertices to the queue data structure.
Step 5: Now, using the FIFO concept, you must remove the element from the queue, put it
into the visited array, and then return to the queue to add the adjacent vertices of the
removed element.
Step 6: Repeat step 5 until the queue is not empty and no vertex is left to be visited.

Depth-First Search or DFS


DFS is a search technique for finding a node in a graph data structure that meets a set of
criteria.
• The depth-first search (DFS) algorithm traverses or explores data structures such as trees
and graphs. The DFS algorithm begins at the root node and examines each branch as far
as feasible before backtracking.
• To maintain track of the child nodes that have been encountered but not yet inspected,
more memory, generally a stack, is required.

Algorithm of depth-first search


Step 1: Consider the graph you want to navigate.
Step 2: Select any vertex in our graph, say v1, from which you want to begin traversing the
graph.
Step 3: Examine any two data structures for traversing the graph.
• Visited array (size of the graph)
• Stack data structure
IT07-IT07L Data Structure and Algorithm
5
Module 10: Graph Operations and Traversal
Step 4: Insert v1 into the array's first block and push all the adjacent nodes or vertices of
vertex v1 into the stack.
Step 5: Now, using the FIFO principle, pop the topmost element and put it into the visited
array, pushing all of the popped element's nearby nodes into it.
Step 6: If the topmost element of the stack is already present in the array, discard it instead
of inserting it into the visited array.
Step 7: Repeat step 6 until the stack data structure isn't empty.

References and Supplementary Materials


Online Supplementary Reading Materials
1. Ravikiran A S. (Dec. 8, 2022). Your One-Stop Solution for Graphs In Data Structures.
Retrieved from: https://www.simplilearn.com/tutorials/data-structure
tutorial/graphs-in-data-structure
2. Tutorials Point. (n.d.). Graph Theory - Fundamentals. Retrieved from:
https://www.tutorialspoint.com/graph_theory/graph_theory_fundamentals.htm

Course Module

You might also like