Java program

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Java program
Consider a crèche that experienced a
sudden outbreak of an infection. This
infection caused n number of babies to get
sick at different periods (NB: n is an
integer).
For each i = 1, ... ,n, a baby that enters the
crèche at time a, leaves at time d¡ >= a₁,
suppose we are interested in knowing how
many distinct pairs of babies are ever at the
crèche at the same time? (NB: pair (i, j) is
the same as pair (j, i)).
For example, consider Table 2: Suppose
there are 5 babies with the following
arrival and departure times:
Table2: Babies Arrival and Departure
Times at the Crèche
Baby
1
2
3
4
5
Arrival time
(a;)
2
3
8
10
7
Departure
time (d;)
6
9
11
11
Transcribed Image Text:Consider a crèche that experienced a sudden outbreak of an infection. This infection caused n number of babies to get sick at different periods (NB: n is an integer). For each i = 1, ... ,n, a baby that enters the crèche at time a, leaves at time d¡ >= a₁, suppose we are interested in knowing how many distinct pairs of babies are ever at the crèche at the same time? (NB: pair (i, j) is the same as pair (j, i)). For example, consider Table 2: Suppose there are 5 babies with the following arrival and departure times: Table2: Babies Arrival and Departure Times at the Crèche Baby 1 2 3 4 5 Arrival time (a;) 2 3 8 10 7 Departure time (d;) 6 9 11 11
In table 2, clearly, Baby1 arrived at time 2
and left at time 4, but note that Baby 2 also
arrived at time 3, which is before Baby 1
left the crèche. Hence, the number of
distinct pairs of babies who are at the
crèche simultaneously is three:
These pairs are {(1, 2), (4, 5), (3, 5)}
Considering the input (a₁, d₁) (a₂, d₂)... ( An
dn) as earlier described, there is a
straightforward algorithm that takes about
n² time complexity to compute the number
of pairs of babies that are at the crèche at
the same time.
Your task is to:
1) Give the algorithm (step by step)
and explain/justify why it takes
about n² time complexity.
2) Write a program called
"contactTracing.java", which
implements the algorithm in 1.
a) Ask the user to input the
number of babies in the
creche
b) Followed by arrival and
departure times (separated by
",") for each baby
c) Store these data into a data
structure
Transcribed Image Text:In table 2, clearly, Baby1 arrived at time 2 and left at time 4, but note that Baby 2 also arrived at time 3, which is before Baby 1 left the crèche. Hence, the number of distinct pairs of babies who are at the crèche simultaneously is three: These pairs are {(1, 2), (4, 5), (3, 5)} Considering the input (a₁, d₁) (a₂, d₂)... ( An dn) as earlier described, there is a straightforward algorithm that takes about n² time complexity to compute the number of pairs of babies that are at the crèche at the same time. Your task is to: 1) Give the algorithm (step by step) and explain/justify why it takes about n² time complexity. 2) Write a program called "contactTracing.java", which implements the algorithm in 1. a) Ask the user to input the number of babies in the creche b) Followed by arrival and departure times (separated by ",") for each baby c) Store these data into a data structure
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY