Route Between Nodes
4.1 Route Between Nodes: Given a directed graph, design an algorithm to find out whether there is a route between two nodes
Approach 1: Brute force approach:
Look a look at each nodes pointers values. If it doesn't exist, then look at those pointers pointers values. Accumulate this process over time. Search the pointers accumulated values over time, searching through this array everytime until your search is exhausted. If one or the other original nodes intersection in there values, then the result is true.
Approach 2: Breadth first search
Iterate through the graph, marking nodes as visited to avoid repetition.
Notice how queue's are really nice in exploring and checking all adjacent nodes. Its a nice algorithm to know in general.
Last updated