Data Structure and Algorithm - Practice Homework 4 | CS 303, Assignments of Computer Science

Material Type: Assignment; Class: Algorithms and Data Structures; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Spring 2008;

Typology: Assignments

Pre 2010

Uploaded on 04/12/2010

koofers-user-rqb
koofers-user-rqb 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 303L Data Structure and Algorithm
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
1.
A
H
GF
ED
CB
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
-
pf3

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