Question

Scheme Programming Write a polynomial time scheme program to find the longest non-decreasing subsequent of a...

Scheme Programming

Write a polynomial time scheme program to find the longest non-decreasing subsequent of a list of numbers. For example:

(longest ''(2 4 3 1 2 1 3 6 1 3 2 1 2 33 4 2 4 10 11 7)) --> (1 1 1 1 2 4 4 10 11).

Do not use side-effecting functions (i.e., functions with exclamation point in their names such as set!), sequencing, iteration (e.g., do, for-each) or vectors. Do not use input/output mechanisms other than the regular read-eval-print loop. You are allowed to use some additional built-in list operations, e.g., reverse, list-ref, map, list, let, let*, length, append, cons, car, cdr, boolean operations, null?, equal?, etc.

Homework Answers

Answer #1

Time complexity : O(n^2) - polynomial

#include<bits/stdc++.h> 
using namespace std; 
        
/* lis() returns the length of the longest increasing subsequence in arr[] of size n */

int lis( int arr[], int n ) 
{ 
        int lis[n]; 

        lis[0] = 1; 

        for (int i = 1; i < n; i++ ) 
        { 
                lis[i] = 1; 
                for (int j = 0; j < i; j++ ) 
                        if ( arr[i] > arr[j] && lis[i] < lis[j] + 1) 
                                lis[i] = lis[j] + 1; 
        } 

        return *max_element(lis, lis+n); 
} 
        
int main() 
{ 
        int t;
    cin>>t;
    while(t--)
    {
        int n;
    cin>>n; 
        int arr[n]; 
        for(int i=0;i<n;i++)
    {
       cin>>arr[i];
    } 
        
    printf("Length of lis is %d\n", lis( arr, n ) ); 
    }
        return 0; 
}
Know the answer?
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
Similar Questions
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking...
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking a user-given number, and adding up all of the numbers between 1 and the given number. So if someone inputs 12, it should add 1 + 2 + 3 + 4 + … 9 + 10 + 11 + 12, and return the answer. However, you’ll be using two different methods to do this. The first method should utilize either a for loop or...
Program has to be written in ML language. Write functions in ML to do the following:...
Program has to be written in ML language. Write functions in ML to do the following: 1. Given a list, return that list with its first and third elements deleted. Assume the length of the list is at least 3. 2. Given a list of real pairs, return the list containing the larger element in each pair. Examples: larger_in_pair([]) = [] larger_in_pair([(1.0,2.5),(4.7,3.6),(5.5,8.8)] = [2.5,4.7,8.8] 3. Given two lists of integers, return the list of the sums of the elements in...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class and a Node class (please name your classes exactly ​as I did here). Please follow the below specifications for the two classes. Node.cpp ● This must be a generic class. ● Should contain a generic member variable that holds the nodes value. ● Should contain a next and prev Node* as denoted here. ● All member variables should be private. ● Use public and...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
A newly developed hospital requires an Electronic Decision Support System (DSS) for clinicians. This DSS is...
A newly developed hospital requires an Electronic Decision Support System (DSS) for clinicians. This DSS is required to have all the necessary features to help the practice. Develop a Software Requirements Specification (SRS) document that identifies all the necessary requirements for the system. This document must strictly follow the IEEE template uploaded on canvas. However, there may be sections in the template that may not apply to the project, these sections can be eliminated. Use the template below to answer...
Write a program of wordSearch puzzle that use the following text file as an input. The...
Write a program of wordSearch puzzle that use the following text file as an input. The output should be like this: PIXEL found (left) at (0,9). ( Use JAVA Array ) .Please do not use arrylist and the likes! Hints • The puzzle can be represented as a right-sized two-dimensional array of characters (char). • A String can be converted into a right-sized array of characters via the String method toCharArray. . A word can occur in any of 8...
You are required to write a Business Plan Report and you are advised to follow the...
You are required to write a Business Plan Report and you are advised to follow the below given outline.  Part I- Product/service idea Business Plan Report (40%) To make the best impression, a business plan should follow a convention structure, such as the outline shown below. Cover page Table of contents 1. Executive Summary  A succinct highlight of the overall plan- include ownership structure, business address, product/service, the management team and strategy and strengths. 2. Industry Analysis ...
What tools could AA leaders have used to increase their awareness of internal and external issues?...
What tools could AA leaders have used to increase their awareness of internal and external issues? ???ALASKA AIRLINES: NAVIGATING CHANGE In the autumn of 2007, Alaska Airlines executives adjourned at the end of a long and stressful day in the midst of a multi-day strategic planning session. Most headed outside to relax, unwind and enjoy a bonfire on the shore of Semiahmoo Spit, outside the meeting venue in Blaine, a seaport town in northwest Washington state. Meanwhile, several members of...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT