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
Once the data center routes to the destination server that hosts the website, whats the next step in the internet process?
Pavlova-9 [17]

User’s browser renders HTML code from destination server into web page

4 0
2 years ago
What is a fire wall and how does it work
Ostrovityanka [42]

Answer:

a firewall is a network security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules

8 0
3 years ago
Which task is not possible with VLOOKUP?
Flauer [41]

Answer:c

Explanation:

4 0
3 years ago
Read 2 more answers
WHAT DOES INFORMATION TECHNOLOGY DO??<br> Do they offer services or products
notsponge [240]
Yes

Explanation: Information technology, or IT, describes any technology that powers or enables the storage, processing and information flow within an organization. Anything involved with computers, software, networks, intranets, Web sites, servers, databases and telecommunications falls under the IT umbrella.
4 0
2 years ago
Helen is filling her persönal details on her résumé. Which detail should she include in this section?
svetoff [14.1K]

I would think option A.

b doesn't give enough information and c would go under last work experience

4 0
2 years ago
Other questions:
  • What type of attack intercepts communication between parties to steal or manipulate the data?
    13·1 answer
  • Wireless network devices use ________ to communicate with each other.
    9·2 answers
  • How are different types of cars similar and different?
    10·1 answer
  • The type of database that is connected by a company's local area networks is a(n:
    11·1 answer
  • As u type where does excel display the entry
    10·1 answer
  • What is the answer to 4.9 Code Practice: Question 2
    14·1 answer
  • Write a static method reOrder56(int[] nums) that return an array that contains exactly the same numbers as the given array, but
    10·1 answer
  • I really need help in this!!!
    11·1 answer
  • Five uses of the operating system​
    10·2 answers
  • Osing Commands
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!