Winter 2016 COMP-250: Introduction to Computer Science. Lecture 23, April 5, 2016

Similar documents
FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

Fingerprint idea. Assume:

Module 9: Tries and String Matching

Module 9: Tries and String Matching

Last time: introduced our first computational model the DFA.

DFA (Deterministic Finite Automata) q a

Where did dynamic programming come from?

a b c cat CAT A B C Aa Bb Cc cat cat Lesson 1 (Part 1) Verbal lesson: Capital Letters Make The Same Sound Lesson 1 (Part 1) continued...

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

Data Structures and Algorithm. Xiaoqing Zheng

CPE702 Algorithm Analysis and Design Week 11 String Processing

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

COMP108 Algorithmic Foundations

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

Lecture 11 Waves in Periodic Potentials Today: Questions you should be able to address after today s lecture:

More Foundations. Undirected Graphs. Degree. A Theorem. Graphs, Products, & Relations

Multi-Section Coupled Line Couplers

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Homework 3 Solutions

The Course covers: Lexical Analysis Syntax Analysis Semantic Analysis Runtime environments Code Generation Code Optimization. CS 540 Spring 2013 GMU 2

Notes on Finite Automata Department of Computer Science Professor Goldberg Textbooks: Introduction to the Theory of Computation by Michael Sipser

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

QUESTIONS BEGIN HERE!

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Chem 104A, Fall 2016, Midterm 1 Key

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

INTEGRALS. Chapter 7. d dx. 7.1 Overview Let d dx F (x) = f (x). Then, we write f ( x)

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?

, between the vertical lines x a and x b. Given a demand curve, having price as a function of quantity, p f (x) at height k is the curve f ( x,

1 Nondeterministic Finite Automata

Designing finite automata II

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

Finite-State Automata: Recap

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

1 Introduction to Modulo 7 Arithmetic

Section 3: Antiderivatives of Formulas

Finite Automata. d: Q S Q. Finite automaton is M=(Q, S, d, q 0, F) Ex: an FA that accepts all odd-length strings of zeros: q 0 q 1. q i. q k.

CSI35 Chapter 11 Review

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

CS 461, Lecture 17. Today s Outline. Example Run

Minimum Spanning Trees

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

CS September 2018

Balanced binary search trees

Some Theory of Computation Exercises Week 1

TOPIC 5: INTEGRATION

Ch 1.2: Solutions of Some Differential Equations

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

Bases for Vector Spaces

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

Weighted Matching and Linear Programming

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15

Instructions for Section 1

Deterministic Finite-State Automata

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

Math 4310 Solutions to homework 1 Due 9/1/16

QUESTIONS BEGIN HERE!

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

Surface maps into free groups

I. The Connection between Spectroscopy and Quantum Mechanics

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Formal languages, automata, and theory of computation

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

First Midterm Examination

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

Homework #3. 1 x. dx. It therefore follows that a sum of the

Using the Printable Sticker Function. Using the Edit Screen. Computer. Tablet. ScanNCutCanvas

Errata for Second Edition, First Printing

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

Pattern Matching. a b a c a a b. a b a c a b. a b a c a b. Pattern Matching 1

ME 522 PRINCIPLES OF ROBOTICS. FIRST MIDTERM EXAMINATION April 19, M. Kemal Özgören

Let's start with an example:

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

1 From NFA to regular expression

Gold s algorithm. Acknowledgements. Why would this be true? Gold's Algorithm. 1 Key ideas. Strings as states

Thoery of Automata CS402

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7

Elliptical motion, gravity, etc

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

Search sequence databases 3 10/25/2016

Chapter 16. 1) is a particular point on the graph of the function. 1. y, where x y 1

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

Seven-Segment Display Driver

Planar Upward Drawings

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

Transcription:

Wintr 2016 COMP-250: Introduction to Computr Scinc Lctur 23, April 5, 2016

Commnt out input siz 2) Writ ny lgorithm tht runs in tim Θ(n 2 log 2 n) in wors cs. Explin why this is its running tim. I don t cr wht it dos. I only cr out its running tim WhtEvr(int m) FOR i=1 TO m FOR j=1 TO m x=m; WHILE x>1 DO { x=x/2; y=m; WHILE y>1 DO y=y/2 } n = m ~ log m. Thrfor running tim is Θ(m 2 log 2 m)= Θ(2 2n n 2 )

Commnt out input siz 2) Writ ny lgorithm tht runs in tim Θ(n 2 log 2 n) in wors cs. Explin why this is its running tim. I don t cr wht it dos. I only cr out its running tim WhtEvr(int[] A) n = A.lngth; FOR i=1 TO n FOR j=1 TO n x=n; WHILE x>1 DO { x=x/2; y=n; WHILE y>1 DO y=y/2 }

Pulic Announcmnt

STRINGS AND PATTERN MATCHING Brut Forc,Rin-Krp, Knuth-Morris-Prtt Rgulr Exprssions

Th Knuth-Morris-Prtt Algorithm Th Knuth-Morris-Prtt (KMP) string srching lgorithm diffrs from th rut-forc lgorithm y kping trck of informtion gind from prvious comprisons. Afilur function (f) is computd tht indicts how much of th lst comprison cn rusd if it fils. Spcificlly, f is dfind to th longst prfix of th pttrn P[0,..,j] tht is lso suffix of P[1,..,j] - Not: not suffix of P[0,..,j]

Th Knuth-Morris-Prtt Algorithm Th Spcificlly, Knuth-Morris-Prtt f dfind to (KMP) th string longst srching prfix of lgorithm th pttrn diffrs P[0,..,j] from tht th is lso rut-forc suffix lgorithm of P[1,..,j] y kping - Not: not trck suffix of informtion of P[0,..,j] gind from prvious comprisons. Exmpl: Afilur - vlu of function th KMP (f) filur is computd function: tht indicts how much of th lst comprison cn rusd if it fils. j 0 1 2 3 4 5 Spcificlly, P[j] f is dfind to th longst prfix c of th pttrn P[0,..,j] tht is lso suffix of P[1,..,j] f(j) 0 0 1 2 3 0 - Not: not suffix of P[0,..,j] This shows how much of th ginning of th string mtchs up to th portion immditly prcding fild comprison. - if th comprison fils t (4), w know th, in positions 2,3 is idnticl to positions 0,1

Th KMP Algorithm (contd.) th KMP string mtching lgorithm: Psudo-Cod Algorithm KMPMtch(T,P) Input: Strings T (txt) with n chrctrs nd P (pttrn) with m chrctrs. Output: Strting indx of th first sustring of T mtching P, or n indiction tht P is not sustring of T. f KMPFilurFunction(P) {uild filur function} i 0 j 0 whil i < n do if P[j] = T[i] thn if j = m - 1 thn rturn i - m - 1 { mtch} i i + 1 j j + 1 ls if j > 0 thn {no mtch, ut w hv dvncd} j f(j-1) {j indxs just ftr mtching prfix in P} ls i i + 1 rturn Thr is no sustring of T mtching P

Th KMP Algorithm (contd.) Th KMP filur function: Psudo-Cod Algorithm KMPFilurFunction(P); Input: String P (pttrn) with m chrctrs Ouput: Th fliur function f for P, which mps j to th lngth of th longst prfix of P tht is suffix of P[1,..,j] i 1 j 0 whil i m-1 do if P[j] = P[i] thn {w hv mtchd j + 1 chrctrs} f(i) j + 1 i i + 1 j j + 1 ls if j > 0 thn {j indxs just ftr prfix of P tht mtchs} j f(j-1) ls {thr is no mtch} f(i) 0 i i + 1

Th KMP Algorithm (contd.) A grphicl rprsnttion of th KMP string srching lgorithm c c c c 1 2 3 4 5 6 c 7 c no comprison ndd hr 8 9 10 11 12 c 13 c 14 15 16 17 18 c 19

Th KMP Algorithm (contd.) Tim Complxity Anlysis dfin k = i - j In vry itrtion through th whil loop, on of thr things hppns. - 1) if T[i] = P[j], thn i incrss y 1, s dos j k rmins th sm. - 2) if T[i]!= P[j] nd j > 0, thn i dos not chng nd k incrss y t lst 1, sinc k chngs from i - j to i - f(j-1) - 3) if T[i]!= P[j] nd j = 0, thn i incrss y 1 nd k incrss y 1 sinc j rmins th sm.

Th KMP Algorithm (contd.) Tim Complxity Anlysis Thus, ch tim through th loop, ithr i or k incrss y t lst 1, so th grtst possil numr of loops is 2n This of cours ssums tht f hs lrdy n computd. Howvr, f is computd in much th sm mnnr s KMPMtch so th tim complxity rgumnt is nlogous. KMPFilurFunction is O(m) Totl Tim Complxity: O(n + m)

Rgulr Exprssions nottion for dscriing st of strings, possily of infinit siz ε dnots th mpty string + c dnots th st {, c} * dnots th st {ε,,,,...} Exmpls - (+)* ll th strings from th lpht {,} - *(*)** strings with n vn numr of s - (+)*sun(+)* strings contining th pttrn sun - (+)(+)(+) 4-lttr strings nding in

Finit Stt Automton mchin for procssing strings 0 1 3 2 1 0 6 4 2 3 5 1, Composition of FSA s

Wintr 2016 COMP-250: Introduction to Computr Scinc Lctur 23, April 5, 2016