Module 10 - Graphs Operation and Traversal
Module 10 - Graphs Operation and Traversal
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
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.
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.
Course Module