Professional Documents
Culture Documents
Graphs Activity
Graphs Activity
Case 1 shows starting from partway down the tree. Can, see it prints all achievable location. Sydney,
cairns and Melbourne cannot be achieved due to the one way back that cannot be done and are not
printed.
If we start at a dead end such as Perth we can check that the only printed node is the node we tell it
to start at.
Check that DFS also works with the websites provided later in the code
Case 1, starting search at Brisbane. Correctly prints in right order and doesn’t print unreachable
nodes.
Case 2, started at dead end, does not back track or print any other nodes.
3. Design an algorithm for bi-directional search
Have 2 BFS running at the same time, one searching from the src node and the othere from the
destination node. They run in opposite directions, trying to find a path to the opposite node, src to
dest and dest to src. When they find a node that matches the path is then returned for how to
travel from one node to the next. If no path is possible then it returns false.
4. Design algorithm to determine if a graph is bi-partite
Create an array to store vertices if coloured. Assign a colour to the source and then create a queue
of vertex numbers and then start travelling through the tree with BFS. If a self loop is identified it
returns false. If an edge between 2 nodes exists and is not coloured then assign alternative colours
to each node. If edge does exist and is coloured then return false and ignore edge.