12
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%) Vert ex 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 acti vity a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 a1 0 a1 1 a1 2 a1 3 a1 4 a1 5 a1 6 a1 7 ee 0 0 0 6 6 4 1 0 1 0 4 14 14 14 14 18 18 24 23 le 1 2 0 9 7 4 1 0 1 2 1 1 14 16 14 18 18 20 24 25 slac 1 2 0 3 1 0 0 2 7 0 2 0 4 0 2 0 2

wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

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 V9ee 0 6 10 4 14 14 18 24 23 28le 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 2 7 0 2 0 4 0 2 0 2

critical activities:

Page 2: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

a3, a6, a7, a10, a12, a14, a16

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%)

Page 3: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

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 0 1 2 3 4 5 6 7 8 9 10 11 12 13 1 15 16

Page 4: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

4keyvalue

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

Page 5: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

represent the following graph. (10%)

5.

Page 6: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

Consider the following weighted graph G(V, E) presented by the adjacency matrix.G =

A B C D E FA 0 40 ∞ ∞ 7 21B 40 0 5 12 ∞ 11C ∞ 5 0 10 ∞ ∞D ∞ 12 10 0 18 14E 7 ∞ ∞ 18 0 33F 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%)

Page 7: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

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 A B C D E F G H

init 0 7 15 51 A G 0 7 15 5 182 AG D 0 10 7 13 5 183 AGD B 0 10 12 7 13 5 184 AGDB C 0 10 12 7 13 15 5 185 AGDBC E 0 10 12 7 13 15 5 176 AGDBCE F 0 10 12 7 13 15 5 17

Page 8: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

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]

Page 9: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your

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%)

Page 10: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../quiz2_answer.docx · Web viewPlease apply Kruskal’s algorithm to drive the minimum cost spanning tree. Note that you must show your