You are on page 1of 2

Faculty of Computer Science and Engineering Department of Computer Science

DATA STRUCTURES & ALGORITHMS


Tutorial 5 Questions Graph
Required Questions Question 1. Given the graph in Figure 1, complete the following tasks: a. Find a1. All noncyclic paths from A to D a2. All noncyclic paths from B to H a3. All noncyclic paths from E to C b. Give the adjacency matrix representation of the graph. c. Give the adjacency list representation of the graph. d. Give the depth-first traversal of the graph (supposed we start from A). e. Give the breadth-first traversal of the graph (supposed we start from A).
A B C D

E G

Figure 1

Question 2. Given the graph in Figure 2, complete the following tasks: a. Give the adjacency matrix representation of the graph. b. Give the adjacency list representation of the graph. c. Find the shortest path between node E and all other nodes in the above graph. Question 3. Given the graph in Figure 3, generate the corresponding topology order using depth-first search and breadth-first search.
B A C D Figure 2

E G

Figure 3

Faculty of Computer Science and Engineering Department of Computer Science Advanced Question Question 4. A mouse wants to go through a maze as described in Figure 4. When choosing between multiples nodes, the mouse always take the node appearing first in alphabetical order. When meets the dead end, the mouse turns back and choose another possible path. For example, if starting from A and wanting to go to O, the path that the mouse follow will be: A >> B >> C >> D >> (back to) C >> G >> F >> H >> I >> (back to) H >> J >> K >> (back to) J >> L >> M >> (back to) L >> N >> (back to) L >> O

Figure 4

Write an algorithm that prints out all of the nodes that the mouse will visit in proper order.
Algorithm printOut (val M <Maze>, Start <Node>, Goal <Node>) Pre Start and Goal are two nodes in Maze Return None