Download 105-1 Data Structures Quiz2 系級: 學號: 姓名: 1. The following

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Lattice model (finance) wikipedia , lookup

Quadtree wikipedia , lookup

Red–black tree wikipedia , lookup

B-tree wikipedia , lookup

Interval tree wikipedia , lookup

Binary tree wikipedia , lookup

Binary search tree wikipedia , lookup

Transcript
105-1 Data Structures Quiz2
系級:
學號:
姓名:
1.
The following directed graph is an AOE network which represents a project from its
starting to its finishing. Compute the earliest time (ee), latest time (le), and the allowed
slack of each activity. Then determine which activities are critical.
You should show the two tables (vertex & activity) and the critical activities. (10%)
Vertex
V0
V1
V2
V3
V4
V5
V6
V7
V8
V9
ee
0
6
10
4
14
14
18
24
23
28
le
0
7
10
4
14
14
18
24
25
28
activity a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17
ee
0
0
0
6
6
4
10 10
4
14
14
14
14
18
18
24
23
le
1
2
0
9
7
4
10 12 11
14
16
14
18
18
20
24
25
slack
1
2
0
3
1
0
0
0
2
0
4
0
2
0
2
critical activities:
a3, a6, a7, a10, a12, a14, a16
2
7
2.
(1) Insert the following elements into an initially empty binary search tree with the
specified order: 15, 29, 68, 52, 21, 7, 2, 60, 59. Drew the binary search tree after all
elements are inserted. (5%)
(2) Delete 7 and 29 from the binary search tree in the previous question. Draw the binary
search tree after these 2 deletions. You should draw all possible answers. (5%)
3.
A job priority queue is implemented using a Min-Heap in which a lower key value
means a higher priority. The jobs are entered and stored in the Min-Heap as shown in
the following array Q. (every questions you should show the Min-Heap)
index
keyvalue
0 1 2 3
4
5
6
7
8
9
10 11 12 13 14 15 16
6 8 10 12 24 15 13 20 18 26
(1) Next job is extracted from the job queue for execution. What is the value of Q[4] in
the remaining job queue? (5%)
(2) After (1) is executed, next job is extracted from the job queue for execution. What
is the value of Q[5] in the remaining job queue? (5%)
(3) After (2) is executed, a new job with priority 11 is inserted into the job queue. What
is the value of Q[9] in the remaining job queue? (5%)
4.
Use two different kinds of data structures (Adjacency Matrix and Adjacency List) to
represent the following graph. (10%)
5.
Consider the following weighted graph G(V, E) presented by the adjacency matrix.
G=
A
B
40
C
∞
D
∞
E
F
A
0
21
12
7
∞
B
0
5
C
40
∞
0
10
∞
11
∞
5
D
∞
10
∞
0
18
14
7
12
∞
E
18
0
33
F
21
11
∞
14
33
0
(1) Please find the vertex sequence derived by DFS and BFS respectively. Note that we
assume that node A is the root. You should draw the graph. (10%)
(2) Please apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note
that you must show your actions step by step. (5%)
6.
Given the weighted, directed graph below.
Using Dijkstra’s algorithm, find the shortest path starting from vertex A to all other
vertexes. Assume A is the first vertex added to the set S in finding the shortest paths.
Show the table. (10%)
iteration
S
selected
init
A
B
C
D
E
F
G
H
0
7
15
5
7
15
5
18
7
13
5
18
5
18
1
A
G
0
2
AG
D
0
10
3
AGD
B
0
10
12
7
13
4
AGDB
C
0
10
12
7
13
15
5
18
5
AGDBC
E
0
10
12
7
13
15
5
17
6
AGDBCE
F
0
10
12
7
13
15
5
17
7.
Please fill out the blank.
Searching a Binary Search Tree: (10%)
tree_pointer search(tree_pointer root, int key)
{
/* return a pointer to the node that contains key. If there is no such node, return
NULL */
if (!root) return NULL;
if (key == root->data) return root;
if (key < root->data)
return search( _____ , key);
return search( _____ , key);
}
root->left_child
root->right_child
Algorithm for All Pairs Shortest Paths: (10%)
void allcosts(int cost[][MAX_VERTICES], int distance[][MAX_VERTICES], int n)
{
int i, j, k;
for (i=0; i<n; i++)
for (j=0; j<n; j++)
_____ ;
for(k=0; k<n; k++)
for (i=0; i<n; i++)
for (j=0; j<n; j++)
if ( _____ < distance[i][j])
distance[i][j] = _____ ;
}
distance[i][j] = cost[i][j]
distance[i][k]+distance[k][j]
distance[i][k]+distance[k][j]
8.
(1) Find all articulation points in Figure 1. (5%)
(2) Show the dfn (depth first number) and low values for each node. The node’s order
of Depth First Search is 5-4-2-1-3-6-8-9-7. (5%)