所屬科目:交大◆資工◆資料結構與演算法
1. (5%) In the Knuth-Morris-Pratt string-pattern matching algorithm, we need a failure function. Compute the failure function for the following pattern.
2. (5%) In a binary tree, there may be many null pointers. We may use these pointers to point to in-order predecessors and successors. These pointers are called thread pointers. Draw all the thread pointers in the following binary tree.
(d)n2log(5n)=θ(n2).
(e) n0.999 log n=θ(n2).
(2). Assume there is a total ordering of data, and your application requires frequent range queries to the data (i.e. retrieving data with keys in the range [lower _bound, upper _bound]). Range query to your data can be efficiently implemented with the data structure _____.
(1). After the tree rotations, the parent of node 4 will be node _____
(2). After the tree rotations, the parent of node 7 will be node _____
Let's apply the following additional tree rotations in sequence left_rorate(1)→ right_rorate(4)→ left_rorate(6)→ right_rorate(3).
(3). After the seven tree rotations are applied to T, an in-order traversal of T will output a sequence of the tree nodes as _____
(1). Draw the hash table after the insertions _____
(2). What is the worst-case time complexity for searching in a hash table of size N _____
(3). What is the best-case time complexity for searching in a hash table of size N _____
(1). After the call to xsort returns, the content of the data [ ] array will be _____ (You have to list all 10 elements of the data I ] array sequentially, starting from data [0],data [1],,.,etc.)
(2). How many times will the function part it ion be invoked? _____ times.
(3). The worst-case time complexity of the xsort function for an input array data [ ] with size elements is _____
10. (5%) Figure 7 presents the code for computing the number of connected components in an undirected graph. In the code, the undirected graph is stored in the form of adjacency lists. The graph has N vertices, which correspond to vert ices [N] at Line 25. Each vertex is a tVertex structure as given at Line 9~20. The function ConnectUndirected (v1, v2) is used for creating an undirected edge between vertex v1 and vertex V2. The function NumberOfComponents ( ) at Line 36 will return the number of connected components in the graph. Please complete the code by filling the blanks in Figure 7. There are a total of three blanks at Line 30,32, and 43 to be filled.In the following problem 1 1-15, til in the blanks. Please try to keep all t u answers on the same sheet of the answer book. Each problem is worth 5 points. No partial credit will be given for only one correct blank. However you do not have to provide any justification.
11. (5%)Suppose that the amount of flow in the maximum flow from source to sink in the network G=(V,E) is f, and that all capacities are integral. Suppose n = |V| and m = |E|. How long would it take at this maximum flow using the Ford-Fulkerson algorithm?_____. Suppose the minimum s-t cut in the network G has x arcs. Suppose that one adds y units of capacity to each arc of G, creating a transformed network G'. The capacity of the minimum cut of G' is at most _____.
12. The running time of Kruskal's algorithm for a connected undirected weighted graph G=(V,E) is _____. Suppose that all edge weights in a graph G are integers in the range from 1 to |V|. How fast can you make Kruskal's algorithm run?_____
13.(5%) If some of the edge weights in a graph are negative, the shortest path can be obtained using's algorithm by first adding a large constant C to each edge weight, where C is large every resulting edge weight will be nonnegative (True or False). _____The Bellman-Ford algorithm is not suitable if the input graph has negative-weight edges (True or False)._____
14. (5%) Given a graph as below. Show the weight on the edge between Node x and Node y after reweighting using Johnson's algorithm. _____ Show the fifth row of an adjacent matrix (with order of u, v, x, y,z) after using the Floyd-Warshall Shortest Paths algorithm with the intermediate Node u._____
15. (5%) You are the program chair of a conference! Part of your job is to assign papers to 6 papers P1,P2,P3, P4,P5, P6 and 3 reviewers R1, R2, R3. Initially, each reviewer constructs a list of papers he is willing to review as followings: R1 ={P1,P3, P5, P6},R2 ={P1, P2,P4},R3={P1,P2,P3,P4, P5, P6}. An assignment of papers to reviewers is valid if each paper is assigned to at least 2distinct reviewers that are willing to review that paper. The maximum number of papers assigned to anyer should not be greater than 4. You would like to maximize the total number of pap are validly assigned. Please model this problem using a s-t flow network G = (V, E) (Draw a flow network with capacity labeling)._____ What is the maximum number of papers that can be validly assigned?_____
17. (5%) Consider the problem of finding a vector (X1, X2, X3, X4, X5 ) satisfying the following constraints such that X1 + X2 + X3 + X4 + X5 is maximized, where xi - 0 for i=1,...,5. What are the maximum value and the corresponding vector?