Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Use Exercise 16to construct a dynamic programming algorithm for computing the length of a longest common subsequence of two sequencesa1,a2,....,amand b1,b2,....,bn, storing the values ofL(i,j)as they are found.

Short Answer

Expert verified

An algorithm for determining the longest common subsequence of 2sequences is,

Li,j=maxLi,j-1,i-1,j

Step by step solution

01

Given information

We have given that,

The 2sequences are, a1,a2,....,amandb1,b2,....,bn .

02

Definition and formula to be used

In mathematics, the term "dynamic programming" refers to the process of breaking down a decision into a series of decision steps over time in order to simplify it, this is accomplished by creating a series of value functions V1,V2,...,Vn,each of which takes y as an argument and represents the state of the system at time ifrom 1to n.

We will use the formula of Dynamic programming algorithm

Fn=Fn-1+Fn-2

With base values FO=0and F1is equal to1 .

03

Calculation

We can use dynamic programming to create an algorithm for calculating the length of a common subsequence of two sequences

a1,a2,....,amand b1,b2,....,bn

As shown below.

Procedure longest subsequence is,

a1,a2,....,am,b1,b2,....,bn

For i=1tom

Li,0=0

For,

j=1ton

L0,j=0

For

i=1tom

And

j=1ton

If ai=bj

Then

Li,j=Li-1,j-1+1

Else

Li,j=maxLi,j-1,Li-1,j

Return

Thus, an algorithm for determining a longest common subsequence of two sequences is,

Li,j=maxLi,j-1,i-1,j

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

A sequence \({a_1},{a_2},.....,{a_n}\) is unimodal if and only if there is an index \(m,1 \le m \le n,\) such that \({a_i} < {a_i} + 1\) when \(1{1 < i < m}\) and \({a_i} > {a_{i + 1}}\) when \(m \le i < n\). That is, the terms of the sequence strictly increase until the \(m\)th term and they strictly decrease after it, which implies that \({a_m}\) is the largest term. In this exercise, \({a_m}\) will always denote the largest term of the unimodal sequence \({a_1},{a_2},.....,{a_n}\).

a) Show that \({a_m}\) is the unique term of the sequence that is greater than both the term immediately preceding it and the term immediately following it.

b) Show that if \({a_i} < {a_i} + 1\) where \(1 \le i < n\), then \(i + 1 \le m \le n\).

c) Show that if \({a_i} > {a_{i + 1}}\) where \(1 \le i < n\), then \(1 \le m \le i\).

d) Develop a divide-and-conquer algorithm for locating the index \(m\). (Hint: Suppose that \(i < m < j\). Use parts (a), (b), and (c) to determine whether \(((i + j)/2) + 1 \le m \le n,\) \(1 \le m \le ((i + j)/2) - 1,\) or \(m = ((i + j)/2)\)

Solve the recurrence relationan=an-13an-22 if a0=2anda1=2 . (See the hint for Exercise 9.)

How many operations are needed to multiply two \(32 \times 32\) matrices using the algorithm referred to in Example 5?

47. A new employee at an exciting new software company starts with a salary of550,000and is promised that at the end of each year her salary will be double her salary of the previous year, with an extra increment of$ 10,000 for each year she has been with the company.

a) Construct a recurrence relation for her salary for hern th year of employment.

b) Solve this recurrence relation to find her salary for hern th year of employment.

Some linear recurrence relations that do not have constant coefficients can be systematically solved. This is the case for recurrence relations of the form \(f(n){a_n} = g(n){a_{n - 1}} + h(n)\)Exercises 48-50 illustrate this.

Suppose that f(n)=f(n/3)+1when is a positive integer divisible by 3, and f(1)=1. Find:

a)f(3).

b)f(27).

c)localid="1668607414775" f(729).

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free