def find_max(nums: [int]) -> int:
'''
Finds the maximum value in the given list of integers,
or None if the list is empty
'''
largest = None

for num in nums:
if largest == None or num > largest:
largest = num

return largest

Rewrite the find_max function so that it uses recursion to work its way through the list instead of using a loop. Your rewritten function should accept the same kinds of inputs (i.e., a one-dimensional list of integers) and generate the same outputs. In your view, is this a problem that's well-suited to a recursive solution in Python.

Answers

Answer 1

Answer:

The program in recursion is:

def find_max(nums):

    if len(nums) == 0:

         return "None"

    elif len(nums) == 1:

         return nums[0]

    else:

         return max(nums[0],find_max(nums[1:]))

Explanation:

This line defines the function

def find_max(nums):

This checks if the list is empty.

    if len(nums) == 0:

If yes, it returns "None"

         return "None"

If the list has just one element

    elif len(nums) == 1:

It returns the only element as the maximum

         return nums[0]

If the list has numerous elemente

    else:

The maximum is determined recursively

         return max(nums[0],find_max(nums[1:]))

To the (b) part:

This program does not necessarily need to be done recursively because the max built-in function can be used to determine the maximum of the list in just one line of code and it is more efficient.


Related Questions

1. Discuss the pros and cons of human-computer interaction technology?
2. Discuss the ACID database properties in details ​

Answers

!

gcoo!!Exykgvyukhhytocfplanationufvhyg:

how do I make my own algorithms ​

Answers

Answer:

Step 1: Determine the goal of the algorithm. ...

Step 2: Access historic and current data. ...

Step 3: Choose the right model(s) ...

Step 4: Fine tuning. ...

Step 5: Visualise your results. ...

Step 6: Running your algorithm continuously.

Get a basic understanding of the algorithm.
Find some different learning sources.
Break the algorithm into chunks.
Start with a simple example.
Validate with a trusted implementation.
Write up your process.

To lose weight, you must _______.

a.
increase exercise and increase caloric intake
b.
increase exercise and decrease caloric intake
c.
decrease exercise and increase caloric intake
d.
decrease exercise and decrease caloric intake

Answers

Answer:

B

Explanation:

because you need to exercise and eat or drink less calories

Answer: b. increase exercise and decrease caloric intake

Explanation:

In case of a suspected data breach, what course of action should a chief information security officer (CISO) take

Answers

Answer

1. Assemble his team

2. Find reason for breach

3. Evaluate what was lost

4. Ensure password change

Explanation:

In case of a suspected breach, the Chief information security officer should first of all assemble his incidence response team. This team should have representatives from all areas of the organization.

Then the reason for the breach and how access was gained has to be found out. An evaluation of what has been lost in the breach would be carried out and it's likely impact on the company.

In case credentials were stolen the CISO has to ensure that the employees change passwords. Also he has to notify all the necessary parties about the breach.

The CISO has to ensure that all employees are trained properly on security and they comply to security policies.

Fill in this function that takes three parameters, two Strings and an int. 4- // Write some test function calls here! The Strings are the message that should be printed. You should alternate printMessage("Hi", "Karel", 5); between the Strings after each line. The int represents the total number of lines that should be printed. public void printMessage(String lineOne, String lineTwo, in For example, if you were to call 19.
printMessage("Hi", "Karel", 5);
// Start here! 12 the function should produce the following output:
Hi
Karel
Hi
Kare

Answers

Answer:

The function in Java is as follows:

public static void printMessage(String lineOne, String lineTwo, int lines){

       for(int i = 1;i<=lines;i++){

           if(i%2 == 1){

               System.out.println(lineOne);

           }

           else{

               System.out.println(lineTwo);

           }

       }

   }

Explanation:

This defines the function

public static void printMessage(String lineOne, String lineTwo, int lines){

This iterates through the number of lines

       for(int i = 1;i<=lines;i++){

String lineOne is printed on odd lines i.e. 1,3,5....

      if(i%2 == 1){

               System.out.println(lineOne);

           }

String lineTwo is printed on even lines i.e. 2,4,6....

           else{

               System.out.println(lineTwo);

           }

       }

   }

To call the function from main, use:

printMessage("Hi", "Karel", 5);

An alternative design for a canary mechanism place the NULL value just below the return address. What is the rationale for this design decision

Answers

Answer:

This is to prevent attacks using the strcpy() and other methods that would return while copying a null character.

Explanation:

Canary is a mechanism used to monitor and prevent buffer overflow. The alternative canary design that places a null value just before the return address is called the terminator canary.

Though the mechanism prevents string attacks, the drawback of the technique is that the value of the canary is known which makes it easy for attackers to overwrite the canary.

Explain the three major Subassembly
of a computer Keyboard​

Answers

The keyboard is divided into four sections: alphabetical keys, function keys, cursor keys, and the numeric keypad.  Additional special-purpose keys perform specialized functions.  The mouse is a pointing device used to input data.  Input devices enable you to input data and commands into the computer.

The  three major Subassembly of a computer Keyboard​ are as follows;  alphabetical keys, function keys, and the numeric keypad.

What are the three major Subassembly of a computer Keyboard​?

The keyboard is divided into four components as; alphabetical keys, function keys, cursor keys, and the numeric keypad.

An Keyboard is an input Device used to enter characters and functions into the computer system by pressing buttons.

An Keyboard is a panel of keys that operate a computer or typewriter.

Additional special-purpose keys perform specialized functions.

The mouse is a pointing device used to input data.

The Input devices enable to input data and commands into the computer.

The  three major Subassembly of a computer Keyboard​ are as follows;  alphabetical keys, function keys, and the numeric keypad.

Learn more about the keybord here;

https://brainly.com/question/24921064

#SPJ2

What is the advantage of using shortcuts

Answers

Answer: There can be advantages and disadvantages.

for example, if you were in the woods with a pathway, and a clear way that might be faster and a shorter way of getting out. You may take the shortcut leading to where you didn't want to go leading to you getting lost or, it could be the same time but with more challenges.

An example of shortcuts to it's advantage is when you're reading a text and you don't understand the word. It's much easier when you hear it being read out to you when the reader uses tone to kind of give you a hint if the connotation is negative or positive, A good example of this is the word unique let's use this sentence "She was very unique, and that's what made her cool!" We can use the words "cool" to see that unique is a positive connotation! For the word cool can usually mean that something is real nice or it's something/someone you'd typically like to be around. So therefore these are just a few examples of the advantages and disadvantages of shortcuts.

how would i change this:
" try:
userChoice = input("Would you like to Add or Multipy?(A/M): ")
except:
print("Please enter 'A' or 'M'") "

so it only allows me to put "A" or "M" so that it runs the except part

Answers

You wouldnt use a try and except statement. Use a loop.

Other Questions
Work out the area of the trapezium ABDE.9 cm6 cm How does the work of a reviewer differ from the work of a critic? While waiting for the results of my math test, I paced the hallwayrestlesslyWhat feeling does the underlined word suggest?Select one:gloominesswearinessanxiety What was an important strategy used by the Romans to unify their empires? * 4 points building a large network of roads and bridges using powerful navies to protect sea trade routes supporting free-market economies by minting silver coins granting citizenship and voting rights to conquered peoples To lose weight, you must _______.a.increase exercise and increase caloric intakeb.increase exercise and decrease caloric intakec.decrease exercise and increase caloric intaked.decrease exercise and decrease caloric intake When plotting points on the coordinate plane below, which point would lie on the y-axis?? PLEASE HELP ME OUT !! create a table for y=-3x + 1 In scene 3 of the Act 1 why is there a conflict between mr. van daan and anne frank I need an example of a proportional relationship QUICK PLZZ ANYONE? I need it can anyone plz answer this? write an essay explaining why leaders must be careful with the power they are given. why is energy an essential part of human life pedro tiene que leer un libro de 360 hojas el primer dia leyo 2/5 del libro el segundo dia 1/4 del libro el 3 dia lo termino cuantas hojasleyo por dia Explain the concept of Happy Atoms as it relates to why atoms bond together. If a woman get 7000 dollars for every 3 hour how much will she make for 81 hours Alexander Ill used harsh measures. List and describe. what were ideas that conflicted with the catholic church called What is the group containing nitrogen called ? A. Nucleic Avis group. B. Amino group. C. Polypeptide group. D. Saccharide group. The terms are default, grace period, late payment fee, over the limit fee, and bad credit Imagine that you are given the graph of a brand new parent function, y = P(x), that you have never seen before. You are then asked to graph y = P(x) + 3. Explain how you would go about graphing this new function.