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
3241004551 [841]
2 years ago
5

Find the max and min of a set of values using recursion Find the max and min of a set of values using recursion. First input the

values. The first value inputted is the number of additional data items to input. For instance, if the input is: 3 1 2 3
Computers and Technology
1 answer:
matrenka [14]2 years ago
4 0

Answer:

This question is answered using Python programming language

def MaxSet(mylist, count):  

     if (count == 1):  

           return mylist[0]  

     return max(mylist[count - 1], MaxSet(mylist, count - 1))  

def MinSet(mylist, count):  

     if (count == 1):  

           return mylist[0]  

     return min(mylist[count - 1], MinSet(mylist, count - 1))  

count = int(input("Length of set: "))

mylist = []  

for i in range(count):

     inp= int(input("Input: "))

     mylist.append(inp)

   

print("Minimum: "+str(MinSet(mylist, count)) )

print("Maximum: "+str(MaxSet(mylist, count)) )

Explanation:

This defines the recursion that returns the maximum

def MaxSet(mylist, count):  

This following checks for the maximum using recursion

<em>      if (count == 1):  </em>

<em>            return mylist[0]  </em>

<em>      return max(mylist[count - 1], MaxSet(mylist, count - 1))  </em>

This defines the recursion that returns the minimum

def MinSet(mylist, count):  

This following checks for the minimum using recursion

<em>      if (count == 1):  </em>

<em>            return mylist[0]  </em>

<em>      return min(mylist[count - 1], MinSet(mylist, count - 1))  </em>

The main begins here

This prompts user for length of set

count = int(input("Length of set: "))

This defines an empty list

mylist = []  

The following iteration gets user input

<em>for i in range(count): </em>

<em>      inp= int(input("Input: ")) </em>

<em>      mylist.append(inp) </em>

This calls the minimum function    

print("Minimum: "+str(MinSet(mylist, count)) )

This calls the maximum function

print("Maximum: "+str(MaxSet(mylist, count)) )

You might be interested in
________________are programs that designed to help users to be more productive with their personal tasks
Sergio039 [100]
Answer is • designers •

Have a nice day
7 0
2 years ago
Read 2 more answers
An array UnsortedInt consists of integers in random order. Another array SortedInt consists of a sorted list of integers.
Basile [38]

Answer:

B. searching for a new element.

Explanation:

Searching for an element in a sorted array is denoted as:

                           O(log n)

It uses a binary search algorithm to seek for the element in the array. So it gives only a logarithmic increase as the search moves up the array.

To Insert a new element to an array, it tries to arrange the new element orderly is the array, checking from one element to another to see the position it fits.

It is denoted as O (n), and is slower than inserting in an unsorted array, which is denoted as O (1), because it does not care of the position of the new element.

The speed for computing the mean in both sorted and unsorted are the same.

3 0
2 years ago
1. The running configuration is also known as the _____________ (Select Two) a. Startup config b. Working configuration c. Curre
Shtirlitz [24]

Answer:

1. The running configuration is also known as the <u><em>b. working configuration</em></u>

<u><em>c. current configuration</em></u>

Explanation:

hopes this help (:

6 0
2 years ago
When working in outline mode, press __________ and click the eye icon to change only one layer back to preview mode.
Natasha2012 [34]

Answer:

Butt

Explanation:

erflies

4 0
2 years ago
In JavaScript, which of the statements below can be used for string declaration?
Katen [24]
For a string primitive, b. For a String object, d. If we're non-specific, a.
6 0
3 years ago
Other questions:
  • In Python,The sum of the elements in a tuple can be recusively calculated as follows:The sum of the elements in a tuple of size
    5·1 answer
  • In a system using the relocatable dynamic partitions scheme, given the following situation (and using decimal form): Job Q is lo
    5·1 answer
  • A chef writing up her famed recipe for beef stew realizes she has switched parsley and oregano everywhere in the recipe. The che
    13·1 answer
  • To check spelling errors in a document, the Word application uses the _____ to determine appropriate spelling.
    7·2 answers
  • Write assembly programs with the following I/O
    15·1 answer
  • How does a Cloud-first strategy approach a client's migration to the Cloud?
    11·1 answer
  • What is the positional weigh of the digit 7 in the octal number 7642 ?​
    15·1 answer
  • David plays racing games on his way to work. He uses the analog stick to navigate his vehicle through other artificial intellige
    7·2 answers
  • What are the steps to view two different versions of the same document at once?
    11·1 answer
  • What is the advantage of entering metadata for electronic records that you create
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!