A chemistry teacher asked her class to answer the following question: If I put 10 bacteria on the classroom doorknob tonight, how many bacteria will be on the doorknob by the time we come to school tomorrow? In order to answer this question, you need to know a few things: Each bacterium (a single bacteria) can create 2 more bacteria every hour This means that after one hour, the doorknob will have 10 + 10 * 2 = 30 bacteria, since we started with 10 bacteria and each of those created 2 more. This means that after two hours, the doorknob will have 30 + 30 * 2 = 90, since there were 30 bacteria at the beginning of hour two, and during that hour each bacteria created 2 more bacteria. Continuing this pattern, the number of bacteria on the doorknob after N hours is numberOfBacteriaLastHour + numberOfBacteriaLastHour * 2 However, if we wanted to know how many bacteria are alive after 12 hours, we need to know how many bacteria were alive at hour 11. To find out how many bacteria are alive at hour 11, we need to figure out how many were alive at hour 10. Do you see how we can use recursion to solve this problem? Write a recursive function that computes the number of bacteria alive after N hours. The function signature is public static int numBacteriaAlive(int hour)

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question

A chemistry teacher asked her class to answer the following question:

If I put 10 bacteria on the classroom doorknob tonight, how many bacteria will be on the doorknob by the time we come to school tomorrow?

In order to answer this question, you need to know a few things:

  1. Each bacterium (a single bacteria) can create 2 more bacteria every hour
  2. This means that after one hour, the doorknob will have 10 + 10 * 2 = 30 bacteria, since we started with 10 bacteria and each of those created 2 more.
  3. This means that after two hours, the doorknob will have 30 + 30 * 2 = 90, since there were 30 bacteria at the beginning of hour two, and during that hour each bacteria created 2 more bacteria.
  4. Continuing this pattern, the number of bacteria on the doorknob after N hours is
    numberOfBacteriaLastHour + numberOfBacteriaLastHour * 2
  5. However, if we wanted to know how many bacteria are alive after 12 hours, we need to know how many bacteria were alive at hour 11. To find out how many bacteria are alive at hour 11, we need to figure out how many were alive at hour 10. Do you see how we can use recursion to solve this problem?


Write a recursive function that computes the number of bacteria alive after N hours.
The function signature is

public static int numBacteriaAlive(int hour)

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Probability Problems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole