210 likes | 400 Vues
CHAPTER 2. The Basic Concepts of Algorithms. The Minimal Spanning Tree Problem. Spanning tree Prim ’ s Algorithm Kruskal ’ s Algorithm. The Longest Common Subsequence Problem. S1 : ABDDRGTY S2 : CDEDRGRT DRT DRGT DDRGT. The Dynamic Programming Strategy.
E N D
CHAPTER 2 The Basic Concepts of Algorithms
The Minimal Spanning Tree Problem • Spanning tree • Prim’s Algorithm • Kruskal’s Algorithm
The Longest Common Subsequence Problem • S1 : ABDDRGTY • S2 : CDEDRGRT DRT DRGT DDRGT
The Dynamic Programming Strategy • If we go through a vertex X, we should find a shortest route from X to T.
Application of the Dynamic Programming Strategy to Solve the LCS problem • LCS(i,j)=LCS(i-1,j-1)+1 if max{LCS(i-1,j),LCS(i,j-1)} if LCS(0,0)=LCS(1,0)=LCS(0,1)=0
The Time-Complexity of Algorithms • Find a LCS : best case: O( ) average Case: O( ) worst case: O( ) Quicksort : best case: O( n log n ) average Case: O( n log n ) worst case: O( )
The 2-Dimensional Maxima Finding Problem and the Divide and Conquer Strategy • A point( ) is said to dominate another point( ) if , .If a point is not dominated by any point ,is called a maxima.
The Selection Problem and the Prune and Search Strategy • Give a set S of n numbers,there is a number p which divides S into three subsets S1,S2and S3. case1:the size of S is greater than k.Kth smallest of S must be located in S1 ,prune away S2 and S3. case2:the condition of Case1 is not valid.But the size of S1 and S2 is greater than k.the kth smallest number of S must be equal to p. case3:none of the conditions of case1 and case2 is valid.In this case,the kth smallest number of S must be located in S3 and we can prune away S1 and S2
The NP-Complete Problems • NP problems are all decision problems • Nearly all of the decision problems are NP problems.
CHAPTER 3 String Matching
3.1 Basic Terminologies of Strings • |S|=sting S 的長度 “AGCTTGATT” • Substring, “GCTT”“TTG” • Subsequences, “ACT”“GTT” • Prefix of string “AGCT”“AG” • Suffix of string “GATT”“TT”
The KMP Algorithm • Knuth, Morris, Pratt in 1977 • Case1:the fist symbol of P dose not appear again in P. • Case2:the first symbol of P appears again in P.
Case3:not only the first symbol of P appears in P,prefixes of P appear in P twice.
If a mismatch occurs when is compared with ,then align with if j!=1 and align with if j=1.
The Boyer-Moore Algorithm • Boyer,Moore in 1977,more efficient in practice than KMP • Bad Character Rule:Align with ,where j’ is the rightmost position of in P. • Good Suffix rule 1:Align with , where j’ is the largest position such that is a suffix of and
Good suffix Rule 2:Align with ,where j’ is the largest position such that is a suffix of • Function G: (a) be the largest k such that is a suffix of and ,0 if there is no such k. (b) be the largest k such that is a suffix of ; 0 if there is no such k. (c). G(j)={m - max{ , }}
Suffix Trees and suffix Arrays • Suffixes suffix tree
Approximate String Matching • Case 1: E(i,j)=E(i-1,j-1) • Csse 2: E(i,j)={E(i-1,j),E(i,j-1)}+1