1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
KonstantinChe [14]
3 years ago
10

Give a recursive implementation for the function: def is_sorted(lst, low, high) This function is given a list of numbers, lst, a

s well as two indices: low and high (low ≤ high), which indicate the range of the indices for the elements that should to be considered. When called, the function should determine if the elements that are placed at the low, low+1, …, high positions, are in an (ascending) sorted order. That is, it should return True if-and-only-if lst[low] ≤ lst[low+1] ≤ … ≤ lst[high] For example, if lst = [1, 3, 6, 8, 12, 15, 31], the call is_sorted(lst, 0, 6), will return True. Implementation requirements: Your function should run in worst case linear time. That is, if n is the size of the range low, low+1, …, high, calling is_sorted(lst, low, high) will run in �(�). Note: Write your implementation.
Computers and Technology
1 answer:
vaieri [72.5K]3 years ago
7 0

Answer:

# recursive method to find if list is in ascending order

def is_sorted(list, low, high):

   if low >= high:     # if reached end of list

       return True

   if list[low] > list[low+1]:     # if item at low is greater than low+1

       return False                # return false

   return True and is_sorted(list, low+1, high)    # or return True and recursion call to low+1

Explanation:

You might be interested in
This tag is used to change the appearance of your text on your web page
zaharov [31]

Answer:

b.font tag

is used to change the appearance of your text on your web page

8 0
3 years ago
Select the correct answer.
Vedmedyk [2.9K]
D because of the sun
6 0
3 years ago
Write an algorithm that prints out all the subsets of 3 elements of a set of n elements. The elements of the set are stored in a
Ksenya-84 [330]

void Print_3_Element_Subsets(int n,const element_type S[])

{

if(n<3) // condition to check if list have less than 3 elements

{

print("No subset found");

}

for(int i =0; i < n ; i++)

{

for(int j =i+1; j < n ; j++)

{

for(int k =j+1; k < n ; k++)

{

print(S[i],S[j],S[k]);

}

}

}

}

C++ Implementation;

#include<cstdlib>

#include<time.h>

using namespace std;

int S1[5]= {1,2,3,4,5};

int n1 = 5;

int S2[2]={1,2};

int n2 = 2;

void Print_3_Element_Subsets(int n,const int S[])

{

if(n<3) // condition to check if list have less than 3 elements

{

printf("No subset found\n");

}

printf("3 Subsets are\n");

for(int i =0; i < n ; i++)

{

for(int j =i+1; j < n ; j++)

{

for(int k =j+1; k < n ; k++)

{

cout<<S[i]<<" "<<S[j]<<" "<<S[k]<<endl;

}

}

}

}

int main()

{

cout<<"Case 1"<<endl;

Print_3_Element_Subsets(n1,S1);

cout<<endl<<"Case 2"<<endl;

Print_3_Element_Subsets(n2,S2);

}

OUTPUT

Case 1

3 Subsets are

1 2 3

1 2 4

1 2 5

1 3 4

1 3 5

1 4 5

2 3 4

2 3 5

2 4 5

3 4 5

Case 2

No subset found

3 Subsets are

--------------------------------

Process exited after 0.0137 seconds with return value 0

Press any key to continue . . .

7 0
3 years ago
Who is the father of modern computer?​
nydimaria [60]

Answer:

I would say Alan Turing is the father of the modern computer

7 0
3 years ago
Read 2 more answers
Question #2
UNO [17]

Explanation:

by staying late to help people aswell as being their and putting full effort into it

because the others arent helping they are only only just reminding

4 0
3 years ago
Read 2 more answers
Other questions:
  • A wireless (radio) transmission of data can only travel a short distance.<br><br> True or false?
    9·1 answer
  • Why won't my laptop charge?
    6·1 answer
  • According to Holpp and Kelly's approaches to developing vision, the benchmarking approach is more internally focused, whereas th
    6·1 answer
  • Fill in the blank.
    7·1 answer
  • Emerson needs to tell his browser how to display a web page. Which tool will he use?
    8·2 answers
  • In 1-2 pages, identify a social networking technology and identify at least 10 security and/or privacy risks the technology has
    8·1 answer
  • There are two main advantages to using multiple threads in a process: 1) Less work involved in creating a new thread rather than
    7·1 answer
  • It is unlawful in the State of Florida for any person, ______________________, to be a passenger in the front seat of a motor ve
    7·1 answer
  • Compare the freedom available to the American media with the freedom available to media in other parts of the world. How does a
    8·1 answer
  • A technician wants to replace a failing power supply on a high-end gaming computer. which form factor should the technician be l
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!