Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would you write a memoized, iterative version of the longest common subsequence algorithm? A memoized, recursive version looks as follows: def lcsLena (X,Y): gamma

How would you write a "memoized", iterative version of the longest common subsequence algorithm?

A memoized, recursive version looks as follows:

image text in transcribed

def lcsLena (X,Y): gamma make Table (len (X)+1 len (Y)+1) #cache for length values, with extra 0th row & column. return c(X,Y,len (x),len (Y) ,gamma) def c cache) if cache Ci] [j None if i 0 or j 0: cache [i] Cj] 0 elif xli-1] YDj-1]: We need to offset both i and j, because of the extra values cache [i] Cj] c (x,Y,i-1,j-1, cache 1 else a c cache) b c(x,Y,i, j 1, cache) if a b: cache [i] [1] a else cache [i] Cj] b return cache Llen(X)] Clen (Y)]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago