1 A Linear Space Algorithm for Computing Maximal Common Subsequences Author: D.S. Hirschberg Publisher: Communications of the ACM 1975 Presenter: Han-Chen.

Slides:



Advertisements
Similar presentations
Xiaoming Sun Tsinghua University David Woodruff MIT
Advertisements

Introduction to Algorithms 6.046J/18.401J/SMA5503
An Array-Based Algorithm for Simultaneous Multidimensional Aggregates By Yihong Zhao, Prasad M. Desphande and Jeffrey F. Naughton Presented by Kia Hall.
Longest Common Subsequence
Dynamic Programming Nithya Tarek. Dynamic Programming Dynamic programming solves problems by combining the solutions to sub problems. Paradigms: Divide.
Introduction to Bioinformatics Algorithms Divide & Conquer Algorithms.
Introduction to Bioinformatics Algorithms Divide & Conquer Algorithms.
Introduction to Bioinformatics Algorithms Divide & Conquer Algorithms.
CPSC 335 Dynamic Programming Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Overview What is Dynamic Programming? A Sequence of 4 Steps
CS 2210 (22C:19) Discrete Structures Advanced Counting
T(n) = 4 T(n/3) +  (n). T(n) = 2 T(n/2) +  (n)
Inexact Matching of Strings General Problem –Input Strings S and T –Questions How distant is S from T? How similar is S to T? Solution Technique –Dynamic.
Analysys & Complexity of Algorithms Big Oh Notation.
Complexity 7-1 Complexity Andrei Bulatov Complexity of Problems.
Advanced Topics in Algorithms and Data Structures Page 1 Parallel merging through partitioning The partitioning strategy consists of: Breaking up the given.
Simulating a CRCW algorithm with an EREW algorithm Efficient Parallel Algorithms COMP308.
CS 253: Algorithms Chapter 7 Mergesort Quicksort Credit: Dr. George Bebis.
IP Address Lookup for Internet Routers Using Balanced Binary Search with Prefix Vector Author: Hyesook Lim, Hyeong-gee Kim, Changhoon Publisher: IEEE TRANSACTIONS.
Ugo Montanari On the optimal approximation of descrete functions with low- dimentional tables.
Fall 2004COMP 3351 Recursively Enumerable and Recursive Languages.
Complexity 5-1 Complexity Andrei Bulatov Complexity of Problems.
Dynamic Programming Reading Material: Chapter 7..
Space Efficient Alignment Algorithms and Affine Gap Penalties
Space Efficient Alignment Algorithms Dr. Nancy Warter-Perez June 24, 2005.
Recursively Enumerable and Recursive Languages
Sequence Alignment Cont’d. Sequence Alignment -AGGCTATCACCTGACCTCCAGGCCGA--TGCCC--- TAG-CTATCAC--GACCGC--GGTCGATTTGCCCGAC Definition Given two strings.
Parallel Merging Advanced Algorithms & Data Structures Lecture Theme 15 Prof. Dr. Th. Ottmann Summer Semester 2006.
Sequence Alignment Variations Computing alignments using only O(m) space rather than O(mn) space. Computing alignments with bounded difference Exclusion.
5 - 1 § 5 The Divide-and-Conquer Strategy e.g. find the maximum of a set S of n numbers.
Bit Complexity of Breaking and Achieving Symmetry in Chains and Rings.
CS2420: Lecture 9 Vladimir Kulyukin Computer Science Department Utah State University.
Dynamic Programming Reading Material: Chapter 7 Sections and 6.
1 Reducibility. 2 Problem is reduced to problem If we can solve problem then we can solve problem.
Space Efficient Alignment Algorithms Dr. Nancy Warter-Perez.
1 Dynamic Programming 2012/11/20. P.2 Dynamic Programming (DP) Dynamic programming Dynamic programming is typically applied to optimization problems.
Dynamic Programming – Part 2 Introduction to Algorithms Dynamic Programming – Part 2 CSE 680 Prof. Roger Crawfis.
Lecture 2 We have given O(n 3 ), O(n 2 ), O(nlogn) algorithms for the max sub-range problem. This time, a linear time algorithm! The idea is as follows:
Dynamic Programming UNC Chapel Hill Z. Guo.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Dynamic Programming.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 28, 2014.
CS 8833 Algorithms Algorithms Dynamic Programming.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 21, 2014.
6/4/ ITCS 6114 Dynamic programming Longest Common Subsequence.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
1/24 Introduction to Graphs. 2/24 Graph Definition Graph : consists of vertices and edges. Each edge must start and end at a vertex. Graph G = (V, E)
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Introduction to Bioinformatics Algorithms Divide & Conquer Algorithms.
Introduction to Algorithms Jiafen Liu Sept
Space Efficient Alignment Algorithms and Affine Gap Penalties Dr. Nancy Warter-Perez.
Tim Roughgarden Introduction Merge Sort (Analysis ) Design and Analysis of Algorithms I.
Chapter 7 Dynamic Programming 7.1 Introduction 7.2 The Longest Common Subsequence Problem 7.3 Matrix Chain Multiplication 7.4 The dynamic Programming Paradigm.
Algorithms for the Maximum Subarray Problem Based on Matrix Multiplication Authours : Hisao Tamaki & Takeshi Tokuyama Speaker : Rung-Ren Lin.
Part 2 # 68 Longest Common Subsequence T.H. Cormen et al., Introduction to Algorithms, MIT press, 3/e, 2009, pp Example: X=abadcda, Y=acbacadb.
Recursively Enumerable and Recursive Languages
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
Example 2 You are traveling by a canoe down a river and there are n trading posts along the way. Before starting your journey, you are given for each 1
Dynamic Programming General Idea
ICS 353: Design and Analysis of Algorithms
Lecture No 6 Advance Analysis of Institute of Southern Punjab Multan
ICS 353: Design and Analysis of Algorithms
Dynamic Programming General Idea
Introduction to Algorithms: Dynamic Programming
Longest common subsequence (LCS)
Advanced Analysis of Algorithms
Topic: Divide and Conquer
Dynamic Programming.
Presentation transcript:

1 A Linear Space Algorithm for Computing Maximal Common Subsequences Author: D.S. Hirschberg Publisher: Communications of the ACM 1975 Presenter: Han-Chen Chen Date:2010/04/07

2 Outline Introduction Algorithm A Algorithm B Algorithm C

3 Introduction LCS (Longest Common Subsequence) of two strings has been solved in quadratic time and space. We present an algorithm which will solve this problem in quadratic time and in linear space.

4 Algorithm A Input string A 1m and B 1n output matrix L

5 Analysis of Algorithm A Time Complexity : execute m*n times → O(mn) Space Complexity : input arrays m + n output array (m+1)*(n+1) space require → O(mn)

6 Algorithm B (I) Space require : O(m+n) It can output the max common length but cannot record the max common subsequence.

7 Algorithm B (II) Input string A 1m and B 1n output matrix LL

8 Analysis of Algorithm B Time Complexity : execute m*n times → O(mn) Space Complexity : input arrays m + n output array n+1 space require → O(m+n)

9 Algorithm C Divide and conquer i=m/2 String B String A Find j 1 1 n m ALG B A 1i B 1j B j+1,n A i+1,m

10 Algorithm C L(i,j) j=0 … n the maximum lengths of common subsequence A 1i and B 1j L*(i,j) j=0 … n the maximum lengths of common subsequence A m,i+1 and B n,j+1 Define M(i) = max{ L(i,j) + L*(i,j) } 0 ≦ j ≦ n Theorem M(i) = L(m,n) Proof: for all L(i,j) + L*(i,j) ≦ L(m,n) S(i,j) : any maximal common subsequence of A 1i and B 1j S*(i,j) : any maximal common subsequence of A i+1,m and B j+1,n Then C= S(i,j) || S*(i,j) is a common subsequence of A 1m and B 1n of length M(i). Thus L(m,n) ≧ L(i,j) + L*(i,j)

11 Algorithm C exist some L(i,j) + L*(i,j) ≧ L(m,n) S(m,n) : any maximal common subsequence of A 1m and B 1n S(m,n) is a subsequence of A 1m so S(m,n) = S 1 || S 2 that S 1 is a subsequence of A 1i, S 2 is a subsequence of A i+1,m Also S(m,n) is a subsequence of B 1n so there exists j such that S 1 is a subsequence of B 1j and S 2 is a subsequence of B j+1,n By definition of L and L*, |S 1 | ≦ L(i,j) and |S 2 | ≦ L*(i,j) Thus L(m,n) = |S(m,n)| = |S 1 | + |S 2 | ≦ L(i,j) + L*(i,j) So M(i) = max{ L(i,j) + L*(i,j) } = L(m,n)

12 Algorithm C m,i+1

13 Algorithm C

14 Algorithm C i=m/ … … L2 L1

15 Analysis of Algorithm C (I) Time analysis: O(mn) + O(1/2mn) + O(1/4mn) + … = O(mn(1+1/2+1/4+…)) = O(mn)

16 Analysis of Algorithm C (II) Space analysis: we calls ALG B use temporary storage which is m and n. Exclusive of recursive calls to ALG C, ALG C uses a constant amount of memory space. There are 2m-1 calls to ALG C, so ALG C require memory space O(m+n).

17 Proof 2m-1 calls to ALG C Let m ≦ 2 r m=1 there are 2*1 – 1 = 1 call to ALG C Assume m ≦ 2 r = M there are 2m-1 calls to ALG C For m’ = 2 r+1 = 2M. First call ALG C to partition 2 part, each calls call 2m-1 times ALG C. So there are 1 + (2m-1) + (2m-1) = 4m - 1 = 2m’ – 1 calls.