We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It's definitely doable in Python. I peeked at your code and the main culprits slowing things down are checkVisitedStatus and findFirstUnvisited which both iterate over the entire vertex list and are called many times. You don't really need either of them. Just iterate over all the vertices in the graph once, calling DFS on each vertex that hasn't been visited, and skipping over the ones that have. At the end of the loop, you will have visited every vertex.
Roads and Libraries
You are viewing a single comment's thread. Return to all comments →
It's definitely doable in Python. I peeked at your code and the main culprits slowing things down are checkVisitedStatus and findFirstUnvisited which both iterate over the entire vertex list and are called many times. You don't really need either of them. Just iterate over all the vertices in the graph once, calling DFS on each vertex that hasn't been visited, and skipping over the ones that have. At the end of the loop, you will have visited every vertex.