03 - Depth First Search (Solution)

03 - Depth First Search (Solution) - The Hong Kong...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The Hong Kong University of Science & Technology COMP 271: Design and Analysis of Algorithms Fall 2007 Tutorial 3: Depth First Search (Solution) Below are the solution to the problems of the tutorial. Question 1 : (a) Show the tree produced by Depth-First Search (DFS) when it is run on the graph G (shown in the figure below), using vertex a as the source. Please also show the assigned time stamps (discovery and finishing time) for each vertex. Note: You must follow the order of vertices in the adjacency list shown in the table below. a: b: c: d: e: f: g: h: i: −→ −→ −→ −→ −→ −→ −→ −→ −→ b, c, d a, e, f a, d, g a, c, g, h b, f, i b, e, g c, d, f d e a b e i f c g Graph G d h Step 0: Step 1: (1, a b e i 1 a d g h e i b f c g d h c f Step 2: (1, Step 3: (1, a (2, (2, a d (3, b e i Step 4: c f g b h e i f c g d h (1, Step 5: (1, a (2, (2, a d (3, b (3, c f g b h e i f (4, c g (5, d h e i Step 6: (4, (1, Step 7: (1, a (2, (2, a (7, b (3, c (6, d (3, b h e i 2 c (6, d g (5, e i f (4, g (5, f (4, h Step 8: (1, Step 9: (1, a (2, (7, (2, a (7, b (3, c (6, d (3, b h (8, c (6, d g (5, e i Step 10: (2, f (4, g (5, e i f (4, h (8,9) (1, a (7,10) Step 11: (1, a (2, (7,10) b (3, c (6, d (3, b h (8,9) c (6,11) d g (5, e i Step 12: f (4, g (5, e i f (4, h (8,9) (1, Step 13: (1, a (2, (7,10) (2, a (7,10) b (3, c (6,11) d (3, b h (8,9) c (6,11) d g (5,12) e i f (4, g (5,12) e i 3 f (4,13) h (8,9) Step 14: (2, (1, a (7,10) Step 15: (2, (1, a (7,10) b (3, c (6,11) d (3, b h (8,9) c (6,11) d g (5,12) e i (14, f (4,13) g (5,12) e i f (4,13) (14,15) h (8,9) Step 16: (1, a (2, (7,10) Step 17: (2,17) (1, a (7,10) b (3,16) c (6,11) d (3,16) b h (8,9) c (6,11) d g (5,12) e i f (4,13) (14,15) (1,18) g (5,12) e i f (4,13) (14,15) (1,18) h (8,9) Step 18: (2,17) Result: (7,10) (2,17) a b (3,16) a (7,10) c (6,11) d (3,16) b h (8,9) c (6,11) d g (5,12) e i f (4,13) (14,15) g (5,12) e i 4 f (4,13) (14,15) h (8,9) (b) In the DFS tree of part(a), show the edges of the graph G which are not present in the DFS tree by dashed lines. DFS Tree: (1,18) a (2,17) (7,10) Tree edge d g (5,12) b (3,16) c (6,11) Back edge h (8,9) e i f (4,13) (14,15) 5 ...
View Full Document

This note was uploaded on 10/18/2009 for the course COMP 271 taught by Professor Arya during the Spring '07 term at HKUST.

Ask a homework question - tutors are online