Write in python programming language: The Longest Subsequence Problem is a well-studied problem in Computer Science, where given a sequence of distinct positive integers, the goal is to output the longest subsequence whose elements appear from smallest to largest, or from largest to smallest. For example, consider the sequence S= [9,7,4,10,6,8,2,1,3,5]. The longest increasing subsequence of S has length three ([4,6,8] or [2,3,5]), and the longest decreasing subsequence of S has length five([9,7,4,2,1] or [9,7,6,2,1]). And if we have the sequence S = [531,339,298,247,246,195,104,73,52,31], then the length of the longest increasing subsequence is 1 and the length of the longest decreasing subsequence is 10. Question: Find a sequence with nine distinct integers for which the length of the longest increasing subsequence is 3, and the length of the longest decreasing subsequence is 3. Briefly explain how youconstructed your sequence. Let S be a sequence with ten distinct integers. Prove by Contradiction that there must exist an increasing subsequence of length 4 (or more) or a decreasing subsequence of length 4 (or more). Hint: for each integer k in the sequence you found in the first part, define the ordered pair (x(k), y(k)), where x(k) is the length of the longest increasing subsequence beginning withk, and y(k) is the length of the longest decreasing subsequence beginning withk. You should notice that each of yourordered pairs is different. Explain why this is not a coincidence, i.e., why it is impossible for two different numbers in your sequence to be represented by the same ordered pair (x(k), y(k)).

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 24PE
icon
Related questions
Question

Write in python programming language:

The Longest Subsequence Problem is a well-studied problem in Computer Science, where given a sequence of distinct positive integers, the goal is to output the longest subsequence whose elements appear from smallest to largest, or from largest to smallest. For example, consider the sequence S= [9,7,4,10,6,8,2,1,3,5]. The longest increasing subsequence of S has length three ([4,6,8] or [2,3,5]), and the longest decreasing subsequence of S has length five([9,7,4,2,1] or [9,7,6,2,1]). And if we have the sequence S = [531,339,298,247,246,195,104,73,52,31], then the length of the longest increasing subsequence is 1 and the length of the longest decreasing subsequence is 10.

Question:

  • Find a sequence with nine distinct integers for which the length of the longest increasing subsequence is 3, and the length of the longest decreasing subsequence is 3. Briefly explain how youconstructed your sequence.
  • Let S be a sequence with ten distinct integers. Prove by Contradiction that there must exist an increasing subsequence of length 4 (or more) or a decreasing subsequence of length 4 (or more).

Hint: for each integer k in the sequence you found in the first part, define the ordered pair (x(k), y(k)), where x(k) is the length of the longest increasing subsequence beginning withk, and y(k) is the length of the longest decreasing subsequence beginning withk. You should notice that each of yourordered pairs is different. Explain why this is not a coincidence, i.e., why it is impossible for two different numbers in your sequence to be represented by the same ordered pair (x(k), y(k)).

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning