HW9 - v matches the text character just read. The start...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Fall Semester 2008 CS300 Algorithms Homework #9 (due 12/05) 1. There are two approaches to the pattern-matching problem: a finite automaton and a flowchart. The finite automaton, or flowchart, has three types of nodes: A start node. A stop node denoted by “*”, which means “A match was found.” Some read nodes, which mean “Read the next text character. If there are no further characters in the text string, halt; there is no match.” (a) Draw the finite automaton for the pattern P = ‘ AABBAAB 0 , where Σ = { A,B } . From each read node, the arrow labeled with the character just read leads to another node. (b) Convert the finite automaton constructed in (a) to the KMP(Knuth-Morris-Pratt) flowchart. Every node v , except the first and the last ones, represents one character of the pattern. The arrows from v are classified into success link or fail link indicating whether the character of
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: v matches the text character just read. The start node means “Read the next character.” 2. Let X = x 1 x 2 ··· x n and Y = y 1 y 2 ··· y n be two character strings. We say that X is a cyclic shift of Y if there is r such that X = y r +1 ··· y n y 1 ··· y r . Give an O ( n ) algorithm to determine whether X is a cyclic shift of Y . 3. Let [ x 1 ,x 2 , ··· ,x n ] be a sequence of numbers. A subsequence of length k is a sequence [ x i 1 ,x i 2 , ··· x i k ], where 1 ≤ i 1 < i 2 < ··· < i k ≤ n . The subsequence is called increasing if x i 1 < x i 2 < ··· < x i k . (For example, both [1 , 2 , 4 , 7] and [1 , 3 , 9] are increasing subse-quences of [1 , 3 , 2 , 4 , 9 , 7 , 3].) Explain how to use dynamic programming to find the longest increasing subsequence of a given sequence [ x 1 ,x 2 , ··· ,x n ] in O ( n 2 ) time. 1...
View Full Document

Ask a homework question - tutors are online