Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
Modeling the spread of a virus like COVID-19 using recursion.
Let
N = total population (assumed constant, disregarding deaths, births, immigration, and emigration).
S
n
= number who are susceptible to the disease at time n (n is in weeks).
I
n
= number who are infected (and contagious) at time n.
R
n
= number who are recovered (and not contagiuous) at time n.
The total population is divided between these three groups:
N = S
n
+ I
n
+ R
n
There are several hidden assumptions here that may or may not apply to COVID-19, such as a recovered
person is assumed to not be able to get the disease a second time, at least within the time window being
examined.
On week 0 (the start), you assume a certain small number of people have the infection (just to get things
going). Everyone else is initially susceptible, and no one is recovered.
There are two constants of interest:
Let period = time period that it takes for an infected person to recover (recover meaning they become
not infectious to someone else).
Let ratio = infection ratio (an infected person can infect this many others in period weeks),
assuming the
entire population was susceptible)
.
We can deduce three equations that track how S, I, and R change from time period n to time period n+1:
First it may be helpful to define three intermediate variables.
The infection ratio is for the entire infection period, so the weekly infection ratio would be a fraction of
that, ratio / period. Also, since the infection ratio is the ratio if all the population was susceptible, the
effective ratio is really this ratio scaled down for the percent of the population that is susceptible, S
n
/ N:
(A) effectiveWeeklyRatio = ratio/period * S
n
/N
The number of new infections will be the number currently infected times the effectiveWeeklyRatio:
(B) newInfections = I
n
* effectiveWeeklyRatio
On average 1/period of the infected people will recover in a single time period:
(C) newRecovered = I
n
/ period
Using these intermediate variables you calculate new values for R, S, and I:
(1) R
n+1
= R
n
+ newRecovered
(2) S
n+1
= S
n
– newInfections
(3) I
n+1
= I
n
+ newInfections − newRecovered
Instead of using this equation, perhaps better:
(3) I
n+1
= N − R
n+1
− S
n+1
(keeps the total number N constant even after rounding errors)
You will also maintain a “total” variable to add together those that ever got the virus at any point.
total
+= newInfections
These equations lend themselves naturally to recursion. The recursive function is passed values of the
variables for the previous week and calculates new values for the variables for the current week.
For the this project, you will input a value for ratio.
You can assume N = 1000000 (one million) and period=1.0 (one week)
Use initial values of I=100, R=0, S=999900, week=0, and total=100 just to get things going.
Call a function named NextWeek recursively for each new week. Show in three columns the week, the
number of new infections, and the running total of new infections. Right justify each column in a field of
appropriate width. Stop when the number of new infections equals zero.
Note that most values are integers, except that period, ratio, and weeklyEffectiveRatio are floating-point
(doubles). You may need to force a division to be floating point, and you will need to round some
answers off to the nearest integer. To round a double to int, use #include <math.h>
(#include <cmath> for c++) and use the round() function. The function will return the total (all the
way back up the recursive tree so main can get it).
int NextWeek(I, R, S, N, total, ratio, period, week)
{
declare variables of appropiate type:
weeklyEffectiveRatio, newRecovered, newInfections
increment week
calc weeklyEffectiveRatio
calc newRecovered (remember to round to int)
calc newInfections (remember to round to int)
add newInfections to total
calc new values for I, R, S
print week, newInfections, total in asked for format
if (base case)
return total
return NextWeek(..)
}
COVID NOTES:
The estimates for ratio range from about 2.5 to about 5.
The estimates for the period that one is infectious vary widely, it is probably more than the 1.0 week
given here. Assuming you keep ratio the same, the period doesn’t affect the total that eventually get the
disease much, it just shortens or lengthens the total time for the course of the disease,.
Example output/input (assuming a value for r of 2.5),
showing the first few lines:
Enter r:
2.5
WEEK NEW CASES TOTAL CASES
---- ----------- -----------
1 250 350
2 625 975
3 1561 2536
4 3893 6429
5 9670 16099
(only first five weeks shown here, but program goes until zero new cases)
Note that there are two lines of header that are printed out once as literal strings (in main):
"
WEEK NEW CASES TOTAL CASES
"
"---- ----------- -----------"
Then for each week,
Right justified width 4 for the week
Right justified width 12 for new cases
Right justified width 12 for total cases
Submission
Submit one file in D2L under Assignments:
Submit your source code in one file (named with an extension .c for C, .cpp for C++).
I will run the program, so you don't need to supply the output
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
Knowledge Booster
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
- Computer Science You must count the number of strings of length 6 over the alphabet A = {x, y, z}. Any string of length 6 can be considered as a 6-tuple. For example, the string xyzy can be represented by the tuple (x,y,z,y). So the number of strings of length 6 over A equals the number of 6-tuples over A, which by product rule is N. Find N. (Use the following product rule for any finite set A and any natural number n : |A^n|=|A|^n)arrow_forwardThis problem is taken from the delightful book "Problems for Mathematicians, Young and Old" by Paul R. Halmos. Suppose that 931 tennis players want to play an elimination tournament. That means: they pair up, at random, for each round; if the number of players before the round begins is odd, one of them, chosen at random, sits out that round. The winners of each round, and the odd one who sat it out (if there was an odd one), play in the next round, till, finally, there is only one winner, the champion. What is the total number of matches to be played altogether, in all the rounds of the tournament? Your answer: Hint: This is much simpler than you think. When you see the answer you will say "of course".arrow_forwardConsider a recursive function, called f, that computes powers of 3 using only the + operator. Assume n > = 0. int f(int n) { if (n == 0) return 1; return f(n-1) + f(n-1) + f(n-1); } Give an optimized version of f, called g, where we save the result of the recursive call to a temporary variable t, then return t+t+t. i got int g(int n) { if (n == 0) return 1; int t = g(n - 1); return t+t+t; } so now Write a recurrence relation for T(n), the number addition operations performed by g(n) in terms of n.arrow_forward
- You are given a N*N maze with a rat placed at maze[0][0]. Find whether any path exist that rat can follow to reach its destination i.e. maze[N-1][N-1]. Rat can move in any direction ( left, right, up and down).Value of every cell in the maze can either be 0 or 1. Cells with value 0 are blocked means rat cannot enter into those cells and those with value 1 are open.Input FormatLine 1: Integer NNext N Lines: Each line will contain ith row elements (separated by space)Output Format :The output line contains true if any path exists for the rat to reach its destination otherwise print false.Sample Input 1 :31 0 11 0 11 1 1Sample Output 1 :trueSample Input 2 :31 0 11 0 10 1 1Sample Output 2 : false Solution: //// public class Solution { public static boolean ratInAMaze(int maze[][]){ int n = maze.length; int path[][] = new int[n][n]; return solveMaze(maze, 0, 0, path); } public static boolean solveMaze(int[][] maze, int i, int j, int[][] path) {//…arrow_forwardWrite in javaarrow_forwardGive a recursive definition for the set of all strings of a’s and b’s that begins with an a and ends in a b. Say, S = { ab, aab, abb, aaab, aabb, abbb, abab..} Let S be the set of all strings of a’s and b’s that begins with a and ends in a b. The recursive definition is as follows – Base:... Recursion: If u ∈ S, then... Restriction: There are no elements of S other than those obtained from the base and recursion of S.arrow_forward
- A set SS of strings of characters is defined recursively by aa and bb belong to SS . If xx belongs to SS , so does xbxb . Which one of the following strings belong to SS ? this is the Group of answer choices 1. aba 2. bbbbb 3. ab 4. aaab 5. aarrow_forwardComputer Science 1. Let Σ = {0, 1} be an alphabet.(a) Let w = 101 be a word over Σ. Compute |w|, the length of w.(b) List all of the words in Σ32. Let {a, b, c} be an alphabet. List all of the words in Σ23. Let Σ = {a, b} be an alphabet and let · denote concatenation. Compute (ba · ε) · abb,where ε is the empty word.4. Let Σ = {0, 1} be an alphabet and let L ⊆ {0, 1} ∗ be the language defined as L = {w ∈ {0, 1} ∗ |w = x10y, x, y ∈ {0, 1}∗}. (a) Determine whether 01 ∈ L.(b) Determine whether 0101 ∈ L. 5. Let Σ = {0, 1} be an alphabet and let L ⊆ Σ ∗ be the language consisting of all wordsover Σ that contain the substring 10. Construct a DFA that accepts L. Thank you in advancearrow_forwardUsing Dr Racket, write a tail recursive function called popadd that models a population with P people at time t = 0 and adds d people per yeararrow_forward
- @1st mp. 109.arrow_forwardQ. Given a 2d grid map of '1's (land) and '0's (water),count the number of islands.An island is surrounded by water and is formed byconnecting adjacent lands horizontally or vertically.You may assume all four edges of the grid are all surrounded by water. Example 1: 11110110101100000000Answer: 1 Example 2: 11000110000010000011Answer: 3""" def num_islands(grid): count = 0 for i in range(len(grid)): for j, col in enumerate(grid[i]): if col == 1: dfs(grid, i, j) count += 1 Please code it. .arrow_forwardImagine there are N teams competing in a tournament, and that each team plays each of the other teams once. If a tournament were to take place, it should be demonstrated (using an example) that every team would lose to at least one other team in the tournament.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education