1 / 25

Data Structures -4 th exam-

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

asta
Download Presentation

Data Structures -4 th exam-

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. [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

  4. [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. • [5] What is the last-occurrence function L, i.e., what are the values of L(a), L(b), L(c), and L(d)? • [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.

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

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

  8. [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. [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. [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. (1) (2) Ans: (3) (4)

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

  13. [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. (1) (2) Ans: (3) (4)

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

  16. [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. • [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)? • [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.

  18. [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. • [5] What are the codes for the involved characters? • [5]What is the string of bits transmitted for this communication along the communication channel?

  19. Ans: A. B. 010110000010011110101101101000100011101100011000111000011100011100011000101111100100111000001000000001011 PS. _代表space

  20. [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. (1) (2) Ans: (3) (4)

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

  23. [10] Find the minimum spanning tree for Fig.3 using Baruvka’s algorithm as shown below. Please draw T1 each time statement 4 is encountered. • AlgorithmBaruvkaMST(G) • T1V{just the vertices of G} • T2V{just the vertices of G} • whileT1 has fewer than n-1 edges do \\ n is the number of vertices in G • for each connected component C in T1do • Let edge e be the smallest-weight edge of all the edges between C and the other connected components in T1 • ife is not already in T2then • Add edge e to T2 • T1T2 • return T1

  24. AlgorithmBaruvkaMST(G) • T1V{just the vertices of G} • T2V{just the vertices of G} • whileT1 has fewer than n-1 edges do \\ n is the number of vertices in G • for each connected component C in T1do • Let edge e be the smallest-weight edge of all the edges between C and the other connected components in T1 • ife is not already in T2then • Add edge e to T2 • T1T2 • return T1

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

More Related