授課教授:李錫智 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.

Slides:



Advertisements
Similar presentations
Decision Maths Networks Kruskals Algorithm Wiltshire Networks A Network is a weighted graph, which just means there is a number associated with each.
Advertisements

Lecture 15. Graph Algorithms
Graph Theory Arnold Mesa. Basic Concepts n A graph G = (V,E) is defined by a set of vertices and edges v3 v1 v2Vertex (v1) Edge (e1) A Graph with 3 vertices.
Prof. Sin-Min Lee Department of Computer Science
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs - II CS 2110, Spring Where did I leave that book?
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Tries Search for ‘bell’ O(n) by KMP algorithm O(dm) in a trie Tries
Chapter 3 The Greedy Method 3.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Goodrich, Tamassia String Processing1 Pattern Matching.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Graph Theory TreesAlgorithms. Graphs: Basic Definitions 4 n Let n be the number of nodes (stations) and e be the number of edges (links). n A graph is.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
Minimum Spanning Trees What is a MST (Minimum Spanning Tree) and how to find it with Prim’s algorithm and Kruskal’s algorithm.
Lecture 23. Greedy Algorithms
Copyright © Cengage Learning. All rights reserved.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Week -7-8 Topic - Graph Algorithms CSE – 5311 Prepared by:- Sushruth Puttaswamy Lekhendro Lisham.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
SPANNING TREES Lecture 21 CS2110 – Spring
Chapter 2 Graph Algorithms.
CSC401 – Analysis of Algorithms Chapter 9 Text Processing
Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we can find a path that goes over all.
Dijkstra’s Algorithm. Announcements Assignment #2 Due Tonight Exams Graded Assignment #3 Posted.
Prim's Algorithm This algorithm starts with one node. It then, one by one, adds a node that is unconnected to the new graph to the new graph, each time.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Kruskal’s and Dijkstra’s Algorithm.  Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
Runtime O(VE), for +/- edges, Detects existence of neg. loops
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Introduction to computers 103 學年度 上學期 Solution of Homework_ch12 授課教授:李錫智.
Data Structures -Final exam- 2015/6/22 授課教授:李錫智. Question 1. Let a hash table have 13 entries. Suppose we have 10 integer keys: 68, 100, 58, 80, 72, 101,
Minimum Spanning Tree: Prim’s & Kruskal’s Algorithms Presenter: Michal Karpinski.
Huffman’s Algorithm 11/02/ Weighted 2-tree A weighted 2-tree T is an extended binary tree with n external nodes and each of the external nodes is.
Depth-First Search Lecture 21: Graph Traversals
Spanning Tree Algorithms William T. Trotter and Mitchel T. Keller Math 3012 – Applied Combinatorics Spring 2009.
Prims Algorithm for finding a minimum spanning tree
Tree Diagrams A tree is a connected graph in which every edge is a bridge. There can NEVER be a circuit in a tree diagram!
Data Structures -3 rd exam- 授課教授:李錫智. 1.[10] Suppose we want to implement a queue by using the following List operations: getLength(); remove(position);
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
1.[10] Suppose we have 14 integers: 10, 100, 30, 130, 80, 50, 140, 20, 60, 70, 120, 40, 90, 110. Please create a 2-3 tree by inserting one integer at a.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
COMP9024: Data Structures and Algorithms
Minimum Spanning Trees
Chapter 5 : Trees.
Greedy Technique.
Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
COMP9024: Data Structures and Algorithms
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Graph Algorithm.
Spanning Trees.
Minimum Spanning Tree.
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Minimum Spanning Trees
Spanning Trees.
Louisiana Travels.
Networks Kruskal’s Algorithm
Prim’s algorithm for minimum spanning trees
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

授課教授:李錫智 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 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?

Ans: 27 Textabacaabadcabacabaabb abacab 7 abacab 89 abacab 10 abacab 1112 abacab abacab 17 abacab 1819 abacab 20 abacab 21 abacab abacab

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?

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 abacab

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

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

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

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

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.

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

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

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.

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

Ans: (5) (6) (7)

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?

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

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?

Ans: A. B acghnrdpsto_ acghnrdpsto_ PS. _ 代表 space

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.

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

Ans: (5)(6) (7)

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

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

Ans: (1) (2) (3)