You are on page 1of 6

Module Activities:

1. Demonstrate understanding of DFS code

Original Case for DFS The graph connections

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

2. Demonstrate understanding of BFS code


Default case for BFS, prints in order of search as it passes through nodes, unlike DFS that prints
furthest point of search first.

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.

If adjacent vertices can be given alternating colours then we return true.

5. Demonstrate understanding of SCC code


The default given SCC example, each line showing cycles that can be connected, each line being a
different DFS tree, creating a DFS forest when you combine them
Expanded the code to work with the Australian cities database given earlier in the notebook. As The
entire program is only one way, no cycles, having very very poor SCC, each node is on its own line,
creating an inefficient DFS forest that’s no better than a standards BFS.

You might also like