Graph Data Structure
Graph Data Structure
M Usman(15434)
Muneeb Ahmad(15435)
M Saad(15432)
Taha Saeed(15433)
NaheemUllah(15436)
Graph data structure
What is a Graph?
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
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