Question
When we learn about Graph Traversals, one question that I'm sometimes asked by students is why we need them at all. Consider the two implementation
When we learn about Graph Traversals, one question that I'm sometimes asked by students is why we need them at all. Consider the two implementation strategies for graphs that we learned about previously: an adjacency matrix and adjacency lists. Both of them include a separate array-based structure in which information about every vertex is stored. So if our only goal is to visit every vertex, we can do that by just iterating through that array-based structure.
If visiting every vertex is as easy as iterating through them, then why do we need graph traversal algorithms such as depth-first and breadth-first? What purpose do they serve that just iterating through the vertices one at a time, without regard for the presence of edges, wouldn't?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started