Question

Let S be a sequence of n distinct integers stored in an array as array elements...

Let S be a sequence of n distinct integers stored in an array as array elements S[1], S[2], · · · , S[n]. Use the technique of dynamic programming to find the length of a longest ascending subsequence of entries in S. For example, if the entries of S are 11, 17, 5, 8, 6, 4, 7, 12, 3, then one longest ascending subsequence is 5, 6, 7, 12.

Specifically:

(a) define a proper function and find the recurrence for this function;

(b) show that the principle of optimality holds with respect to the function;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution

Lets consider Ci is the length of a longest increasing sub sequence in S[1,...i] it will end at

xi=s[i] where 1<=i<=n

the meaning of the S[i] is the last element in the longest   increasing sub sequence in the S[1,...i]

Now the recurrence is

First we need to compute C1,C2,C3,...Cn

then we need to find max1<=i<=n{Ci}

if you compute Ci that will take O(i) time

It will take O(n2) times to get all of the Ci

For finding the max it need O(n) time

So,

the total time is O(n2)

For finding ascending sub sequence,we need to book keeping like the following

First we need to Create an array K[1,2...n] such that

K[i] contains k in that

S[k]<S[i]

&

Ci=Ck+1

--

all the best

If the Cm is the largest among the values C1,C2,C3,....Cn

then the last value in the longest ascending subsequence is S[m]

&

We find the subsequence recursively from Ck[m]

Add a comment
Know the answer?
Add Answer to:
Let S be a sequence of n distinct integers stored in an array as array elements...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (20 points) You are given an array A of distinct integers of size n. The sequence...

    (20 points) You are given an array A of distinct integers of size n. The sequence A[1], A[2], ..., A[n] is unimodal if for some index k between 1 and n the values increase up to position k and then decrease the reminder of the way until position n. (example 1, 4, 5, 7, 9, 10, 13, 14, 8, 6, 4, 3, 2 where the values increase until 14 and then decrease until 1). (a) Propose a recursive algorithm to...

  • Please help with #6 'rove: Given a sequence of n2 +1 distinct integers, either there is an increasing subsequence of n+1 terms or a decreasing subsequence of n +1 terms. 'rove: Given...

    Please help with #6 'rove: Given a sequence of n2 +1 distinct integers, either there is an increasing subsequence of n+1 terms or a decreasing subsequence of n +1 terms. 'rove: Given a sequence of n2 +1 distinct integers, either there is an increasing subsequence of n+1 terms or a decreasing subsequence of n +1 terms.

  • Suppose you are given an array of n integers a1, a2, ..., an. You need to...

    Suppose you are given an array of n integers a1, a2, ..., an. You need to find out the length of its longest sub-array (not necessarily contiguous) such that all elements in the sub-array are sorted in non-decreasing order. For example, the length of longest sub-array for {5, 10, 9, 13, 12, 25, 19, 70} is 6 and one such sub-array is {5, 10, 13, 19, 70}. Note you may have multiple solutions for this case. Use dynamic programming to...

  • Suppose you are given an array of n integers ai, az, ..., an. You need to...

    Suppose you are given an array of n integers ai, az, ..., an. You need to find out the length of its longest sub-array (not necessarily contiguous) such that all elements in the sub-array are sorted in non-decreasing order. For example, the length of longest sub-array for (5, 10, 9, 13, 12, 25, 19, 30) is 5 and one such sub-array is (5, 10, 13, 19, 303. Note you may have multiple solutions for this case. Use dynamic programming to...

  • ALGORITHM PROBLEM: A) Significant Inversions: We are given a sequence of n arbitrary but distinct real...

    ALGORITHM PROBLEM: A) Significant Inversions: We are given a sequence of n arbitrary but distinct real numbers <a1 , a2 ,..., an>. We define a significant inversion to be a pair i < j such that ai > 2 aj . Design and analyze an O(n log n) time algorithm to count the number of significant inversions in the given sequence. [Hint: Use divide-&-conquer. Do the “combine” step carefully] B) The Maximum-Sum Monotone Sub-Array Problem: Input: An array A[1..n] of...

  • 6. Let T(1..n] be a sorted array of distinct integers, some of which may be negative....

    6. Let T(1..n] be a sorted array of distinct integers, some of which may be negative. Give an algorithm that can find an index i such that 1 <i<n and T[i] = i, provided such an index exists. Your algorithm should take a time in O(lg n) in the worst case. Answers must be proven (or at least well justified)

  • Part-1: find the longest block (subsequence of elements with same value) in an array. Part-2: find...

    Part-1: find the longest block (subsequence of elements with same value) in an array. Part-2: find all subsequences in an array of int that add up to a given sum. */ #include <iostream> #include <cstdlib> using namespace std; void printSeq(int* a, int s, int e); // -------------------------------------------- functions to be implemented by you void longestBlock(const int* a, int n, int& s, int& e) { // s = start index of the block // e = end index of the block...

  • 7. (10) Given an array of integers A[1..n], such that, for all i, 1 <i< n,...

    7. (10) Given an array of integers A[1..n], such that, for all i, 1 <i< n, we have |Ali]- Ali+1]| < 1. Let A[1] = and Alny such that r < y. Using the divide-and-conquer technique, describe in English algorithm to find j such that Alj] z for a given value z, xz < y. Show that your algorithm's running time is o(n) and that it is correct o(n) search an 2 8. (10) Solve the recurrence in asymptotically tight...

  • In assembly language, reverse an array of integers: # The array will be stored in memory...

    In assembly language, reverse an array of integers: # The array will be stored in memory # The location of arr[0] is SP # The location of arr[1] is SP+1 # The location of arr[2] is SP+2 # ... and so on # The size of the array N will be stored in SP-1 # The SP register may be initialized to any value 2: 1024; # Initialize the SP register to 1024 (start of the array) # ALL other...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT