Presentation is loading. Please wait.

Presentation is loading. Please wait.

授課教授:李錫智 Data Structures -4 th exam-. 1.[10] Suppose we have a text and a pattern shown in Fig.1. You apply the brute-force pattern matching algorithm.

Similar presentations


Presentation on theme: "授課教授:李錫智 Data Structures -4 th exam-. 1.[10] Suppose we have a text and a pattern shown in Fig.1. You apply the brute-force pattern matching algorithm."— Presentation transcript:

1 授課教授:李錫智 Data Structures -4 th exam-

2 1.[10] Suppose we have a text and a pattern shown in Fig.1. You apply the brute-force pattern matching algorithm to search for the first occurrence of the pattern in the text. How many comparisons between two characters are performed before you get the answer?

3 Ans: 27 Textabacaabadcabacabaabb 123456 abacab 7 abacab 89 abacab 10 abacab 1112 abacab 13141516 abacab 17 abacab 1819 abacab 20 abacab 21 abacab 222324252627 abacab

4 2.[10] Consider again the text and the pattern shown in Fig.1. You apply the Boyer-Moore algorithm to search for the first occurrence of the pattern in the text. A.[5] What is the last-occurrence function L, i.e., what are the values of L(a), L(b), L(c), and L(d)? B.[5] How many comparisons between two characters in the text and the pattern, respectively, are performed before you get the answer?

5 Ans: A. L(a)=4, L(b)=5, L(c)=3, L(d)=-1 B. Textabacaabadcabacabaabb 1 abacab 432 abacab 5 abacab 6 abacab 7 abacab 1312111098 abacab

6 3.[5] Draw a standard trie for the following set of strings: {abab, baba, aaccc, bcbc, ccaaa, ccab, bbaacc, cbcc, cbca, abaaa} Ans:

7 4.[5] Draw a compressed trie for the following set of strings: {abab, baba, aaccc, bcbc, ccaaa, ccab, bbaacc, cbcc, cbca, abaaa} Ans:

8 5.[10] List the BFS traversal sequence, starting from node 8, for the graph in Fig.2. When several nodes are acceptable, select first the node with the smallest number. Ans: 8, 5, 6, 10, 2, 3, 7, 9, 1, 4

9 6.[10] List the DFS traversal sequence, starting from node 8, for the graph in Fig.2. When several nodes are acceptable, select first the node with the smallest number. Ans: 8, 5, 2, 1, 3, 4, 9, 6, 7, 10

10 7.[10] Find the minimum spanning tree for Fig.3 using the Prim- Jarnik algorithm, starting with the node J. Please draw the intermediate result each time a new node and a new edge are added.

11 Ans: (1)(2) (3) (4)

12 Ans: (5) (6) (7) (8)

13 8.[10] Find the minimum spanning tree for Fig.3 using Kruskal’s algorithm. Please draw the intermediate result each time a new edge is added.

14 Ans: (1)(2) (3)(4)

15 Ans: (5) (6) (7)

16 9.[10] Consider again the text and the pattern shown in Fig.1. You apply the KMP algorithm to search for the first occurrence of the pattern in the text. A.[5] What is the failure function F, i.e., what are the values of F(0), F(1), F(2), F(3), F(4), and F(5)? B.[5] How many comparisons between two characters in the text and the pattern, respectively, are performed before you get the answer?

17 Ans: A. F(0)=0, F(1)=0, F(2)=1, F(3)=0, F(4)=1, F(5)=2 B. Textabacaabadcabacabaabb 123456 abacab 7 abacab 891011 abacab 12 abacab 13 abacab 14 abacab 151617181920 abacab

18 10.[10] Suppose you want to transmit the string “dogs do not spot hot pots or cats” with Huffman encoding. Note that there is a blank between a pair of two words, and blanks should also be transmitted. A.[5] What are the codes for the involved characters? B.[ 5]What is the string of bits transmitted for this communication along the communication channel?

19 Ans: A. B. 01011000001001111010110110100010001110110001100011100001110001 1100011000101111100100111000001000000001011 acghnrdpsto_ 111111224577 acghnrdpsto_ 0000000000010000100000110100001001010100010110011011 PS. _ 代表 space

20 11.[10] Find the shortest paths from node E to all the nodes in Fig.4. Please show the updated shortest distances each time a node is assured of its final answer.

21 Ans: (1)(2) (3)(4)

22 Ans: (5)(6) (7)

23 12.[10] Find the minimum spanning tree for Fig.3 using Baruvka’s algorithm as shown below. Please draw T 1 each time statement 4 is encountered. 1) Algorithm BaruvkaMST(G) 2) T 1  V {just the vertices of G} 3) T 2  V {just the vertices of G} 4) while T 1 has fewer than n-1 edges do \\ n is the number of vertices in G 5) for each connected component C in T 1 do 6) Let edge e be the smallest-weight edge of all the edges between C and the other connected components in T 1 7) if e is not already in T 2 then 8) Add edge e to T 2 9) T 1  T 2 10) return T 1

24 12. 1) Algorithm BaruvkaMST(G) 2) T 1  V {just the vertices of G} 3) T 2  V {just the vertices of G} 4) while T 1 has fewer than n-1 edges do \\ n is the number of vertices in G 5) for each connected component C in T 1 do 6) Let edge e be the smallest-weight edge of all the edges between C and the other connected components in T 1 7) if e is not already in T 2 then 8) Add edge e to T 2 9) T 1  T 2 10) return T 1

25 Ans: (1) (2) (3)


Download ppt "授課教授:李錫智 Data Structures -4 th exam-. 1.[10] Suppose we have a text and a pattern shown in Fig.1. You apply the brute-force pattern matching algorithm."

Similar presentations


Ads by Google