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
Find the area of square whose perimeter is 260.8m​
inessss [21]
4251.04

The perimeter (260.8) over 4 is equal to each side length (65.2)

65.2^2 = 4251.04
5 0
2 years ago
How would a programming language that allows programs to run on any operating system be classified?
Illusion [34]
Cross-platform.





--------------------
3 0
3 years ago
Identify the sampling technique used:A lobbyist for a major airspace firm assigns a number to each legislator and then uses a co
trapecia [35]

Answer:

Random Sampling

Explanation:

Random Sampling technique is being used in the given scenario.

3 0
3 years ago
What is MS-Word? Write some versions of MS-Word.
shtirl [24]
Ms- word it is , hope it was helpful
8 0
3 years ago
Read 2 more answers
What do we call the two parts of lift that goes down a mine
Blababa [14]
The sheave wheel is a pulley wheel that sits above the mine shaft. The hoist cable passes over the sheave wheel and then down the shaft of the mine.
(copied from google)
4 0
3 years ago
Read 2 more answers
Other questions:
  • A(n ____ with a drop down menu provides consistency in function and appearance making it easy for users to learn and work with t
    7·1 answer
  • Which task might be suitable for moving into a separate function so you can re-use it from multiple places in your code?
    11·1 answer
  • Question 1 (1 point)
    10·2 answers
  • To use the program service routines, the user's program makes requests to the operating system through the
    10·1 answer
  • Movies may depict larger-than-life situations, such as calamities, superheroes, and spaceships. A helps show such extraordinary
    11·1 answer
  • You work in a classified environment where Bell LaPadula MLS (Multilevel Security) model is employed. Your clearance is "SECRET"
    5·1 answer
  • Write a function to reverse a given string. The parameter to the function is a string. Function should store the reverse of the
    12·1 answer
  • Processor is used to process the data.<br>A)true <br>B)False​
    13·1 answer
  • What reforms were made by the British government in India after the war of independence? write any three
    5·1 answer
  • Can someone help me with this lab assignment? I really do not know what should I do?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!