Partial preview of the text
Download Data Structure and Algorithm - Practice Homework 4 | CS 303 and more Assignments Computer Science in PDF only on Docsity!
March 7, 2008
Homework 4
(Due on March 20, 2008)
Assuming that the edges are chosen based on the node priority (e.g. 𝐴𝐵 is chosen before 𝐴𝐶;
𝐵𝐷 is chosen before 𝐵𝐸), and assuming the search remembers previous-visited nodes and will
not repeat them. Please answer the questions on the basis of the given graphs
A
H
F G
D E
B C
I
J K
L M
Starting from A (the green node)
(a) Please represent the graph with array approach
Solution:
A B C D E F G H I J K L M
A - 1 1 0 0 0 0 0 0 0 0 0 0
B 1 - 0 1 1 0 0 0 0 0 0 0 0
C 1 0 - 0 0 0 0 0 0 0 0 0 0
D 0 1 0 - 0 0 0 0 0 0 0 0 0
E 0 1 0 0 - 1 1 0 0 0 0 0 0
F 0 0 0 0 1 - 0 0 0 0 0 0 0
G 0 0 0 0 1 0 - 1 1 0 0 0 0
H 0 0 0 0 0 0 1 - 0 1 1 0 0
I 0 0 0 0 0 0 1 0 - 0 0 0 0
J 0 0 0 0 0 0 0 1 0 - 0 1 1
K 0 0 0 0 0 0 0 1 0 0 - 0 0
L 0 0 0 0 0 0 0 0 0 1 0 - 0
M 0 0 0 0 0 0 0 0 0 1 0 0 -
March 7, 2008
(b) Please represent the graph with list approach
Solution:
LIST
A B, C
B A, D, E
C A
D B
E B, F, G
F E
G E, H, I
H G, J ,K
I G
J H, L, M
K H
L J
M J
(c) What is the order of node exploring by depth first search?
Solution: ABDEFGHJLMKIC
(d) What is the order of node exploring by breadth first search?
Solution: ABCDEFGHIJKLM