wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the...

10
105-1 Data Structures Final 系系: 系系: 系系: 1. Consider the following AOE network: (10% ) (1)Show the table that obtain e() and l() for all activity. (2) List all critical activities and all critical paths. activ ity a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 a1 0 a1 1 a1 2 e(i) 0 0 0 6 3 5 8 8 8 12 13 8 l(i) 0 3 0 6 6 5 9 8 1 2 13 13 8

Transcript of wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the...

Page 1: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight

105-1 Data Structures Final

系級: 學號: 姓名:

1.Consider the following AOE network: (10% )

(1) Show the table that obtain e() and l() for all activity.(2) List all critical activities and all critical paths.

activity a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12

e(i) 0 0 0 6 3 5 8 8 8 12 13 8

l(i) 0 3 0 6 6 5 9 8 12 13 13 8

critical activities: a1, a3, a4, a6, a8, a11, a12

critical path: V0 – V1 – V4 – V7 – V8

Page 2: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight

V0 – V3 – V5 – V8 2.Consider the single-source shortest-paths problem: from a given vertex called the source in a weight di-graph G = (V, E), find shortest paths to all its other vertices. Dijkstra’s algorithm is a famous algorithm for this problem. However, the algorithm is applicable to graphs with some specified condition only. Under what condition Dijkstra’s algorithm will not work? Given an example to explain your answer. (10%)

3.Please fill out the table. (10%)

Stability Time complexity

Best Average Worst

Insertion Sort stable O(n) O(n2) O(n2)

Quick Sort untable O(nlogn) O(nlogn) O(n2)

Merge Sort stable O(nlogn) O(nlogn) O(nlogn)

Page 3: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight

Heap Sort untable O(nlogn) O(nlogn) O(nlogn)

Radix Sort stable O(nlogn) O(nlogn) O(nlogn)

4.Suppose you are given the following 10 numbers: (20%)55, 45, 25, 35, 85, 95, 65, 75, 105, 15(1) Please sort these numbers in increasing order using merge sort. Please show

necessary steps such that the use of merge sorting technique can be recognized.(2) Please sort these numbers in increasing order using quick sort. Please show

necessary steps such that the use of quick sorting technique can be recognized.

Page 4: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight

5.Please fill out the blank. (16%)Heap sort:void adjust(element a[], int root, int n){ int child, rootkey; element temp;

temp=a[root]; rootkey=a[root].key;child=2*root; //左子樹while (child <= n) {

if ((child < n) && ( _____ ))child++;

if (rootkey > a[child].key) /*比較樹根和最大子樹*/break;

else { //move to parent_____ ;child *= 2;

}}a[child/2] = temp;

}

a[child].key < a[child+1].key

a[child/2] = a[child];

void heapsort(element a[], int n){ int i, j;

element temp;for (i=n/2; i>0; i--)

_____ ;for (i=n-1; i>0; i--) {

_____ ;adjust(list, 1, i); }

}

Page 5: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight

adjust(list, i, n);

SWAP(list[1], list[i+1], temp);

6.Show why the best and the worst time complexity for the quick. You should explain (a case or example) and use math to prove them. (10%)

Page 6: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight
Page 7: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight
Page 8: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight

7.Consider the following weighted graph.

(1) Start from the vertex a and use Prim’s algorithm to find the minimum cost spanning tree. Show the actions step by step. (7%)

(2) Use Kruskal’s algorithm to find the minimum cost spanning tree. Show the actions step by step. (7%)

Page 9: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight

8.Assume that the data and key are both integers. The hash table size (HSize) is 10. The index runs from 0 to 9. Please fill in the content of the hash table if numbers 6, 3, 35, 15, 27, 95, and 23 are sequentially inserted into the hash table using the following scheme.(1) HF: key mod HSize, open addressing with linear probing. (5%)

0 1 2 3 4 5 6 7 8 9

(2) HF: key mod HSize, open addressing with quadratic probing. (5%)0 1 2 3 4 5 6 7 8 9

(1)

Page 10: wccclab.cs.nchu.edu.twwccclab.cs.nchu.edu.tw/.../final_answer.docx · Web viewConsider the single-source shortest-paths problem: from a given vertex called the source in a weight

0 1 2 3 4 5 6 7 8 9

3 23 35 6 15 27 95

(2)

0 1 2 3 4 5 6 7 8 9

23 3 15 35 6 27 95