There are n people entering and exiting a room. For each i e (1,. .., n),...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
There are n people entering and exiting a room. For each i e (1,. .., n), person i enters at time ai and exits at time bi (assume bi > ai for all i), and all the ai , bi are distinct. At the beginning of the day, the lights in the room are switched off, and the first person who enters the room switches them on. In order to conserve electricity, if person i leaves the room at time bi and there is no one else present in the room at time bi , then person i will switch the lights off. The next person to enter will then switch them on again. Given the values (a1, b1),(a2, b2), ..(an, bn), we want to find the number of times the lights get switched on. I got this algorithm in O(nlogn) using mergesort with help from someone in this page, but i dont know how to write a code for a complexity O(n^2), i was trying to use bubble sort for ordering the array like i did in the past algorithm but i got some cases where my code doesnt work. This is the answer i got for O(nlogn), how could i write it for a complexity O(n^2) ? The algorithm can be shown as: Create array numbers with values ai's and bi's Sort array numbers let x = 0 let count = 0 for each element in numbers repeat: if element is entry time then: if x is O then: count = count + 1 X = x +1 if element is exit time then: X = x -1 Display value of count as number of times light get switched on There are n people entering and exiting a room. For each i e (1,. .., n), person i enters at time ai and exits at time bi (assume bi > ai for all i), and all the ai , bi are distinct. At the beginning of the day, the lights in the room are switched off, and the first person who enters the room switches them on. In order to conserve electricity, if person i leaves the room at time bi and there is no one else present in the room at time bi , then person i will switch the lights off. The next person to enter will then switch them on again. Given the values (a1, b1),(a2, b2), ..(an, bn), we want to find the number of times the lights get switched on. I got this algorithm in O(nlogn) using mergesort with help from someone in this page, but i dont know how to write a code for a complexity O(n^2), i was trying to use bubble sort for ordering the array like i did in the past algorithm but i got some cases where my code doesnt work. This is the answer i got for O(nlogn), how could i write it for a complexity O(n^2) ? The algorithm can be shown as: Create array numbers with values ai's and bi's Sort array numbers let x = 0 let count = 0 for each element in numbers repeat: if element is entry time then: if x is O then: count = count + 1 X = x +1 if element is exit time then: X = x -1 Display value of count as number of times light get switched on There are n people entering and exiting a room. For each i e (1,. .., n), person i enters at time ai and exits at time bi (assume bi > ai for all i), and all the ai , bi are distinct. At the beginning of the day, the lights in the room are switched off, and the first person who enters the room switches them on. In order to conserve electricity, if person i leaves the room at time bi and there is no one else present in the room at time bi , then person i will switch the lights off. The next person to enter will then switch them on again. Given the values (a1, b1),(a2, b2), ..(an, bn), we want to find the number of times the lights get switched on. I got this algorithm in O(nlogn) using mergesort with help from someone in this page, but i dont know how to write a code for a complexity O(n^2), i was trying to use bubble sort for ordering the array like i did in the past algorithm but i got some cases where my code doesnt work. This is the answer i got for O(nlogn), how could i write it for a complexity O(n^2) ? The algorithm can be shown as: Create array numbers with values ai's and bi's Sort array numbers let x = 0 let count = 0 for each element in numbers repeat: if element is entry time then: if x is O then: count = count + 1 X = x +1 if element is exit time then: X = x -1 Display value of count as number of times light get switched on There are n people entering and exiting a room. For each i e (1,. .., n), person i enters at time ai and exits at time bi (assume bi > ai for all i), and all the ai , bi are distinct. At the beginning of the day, the lights in the room are switched off, and the first person who enters the room switches them on. In order to conserve electricity, if person i leaves the room at time bi and there is no one else present in the room at time bi , then person i will switch the lights off. The next person to enter will then switch them on again. Given the values (a1, b1),(a2, b2), ..(an, bn), we want to find the number of times the lights get switched on. I got this algorithm in O(nlogn) using mergesort with help from someone in this page, but i dont know how to write a code for a complexity O(n^2), i was trying to use bubble sort for ordering the array like i did in the past algorithm but i got some cases where my code doesnt work. This is the answer i got for O(nlogn), how could i write it for a complexity O(n^2) ? The algorithm can be shown as: Create array numbers with values ai's and bi's Sort array numbers let x = 0 let count = 0 for each element in numbers repeat: if element is entry time then: if x is O then: count = count + 1 X = x +1 if element is exit time then: X = x -1 Display value of count as number of times light get switched on There are n people entering and exiting a room. For each i e (1,. .., n), person i enters at time ai and exits at time bi (assume bi > ai for all i), and all the ai , bi are distinct. At the beginning of the day, the lights in the room are switched off, and the first person who enters the room switches them on. In order to conserve electricity, if person i leaves the room at time bi and there is no one else present in the room at time bi , then person i will switch the lights off. The next person to enter will then switch them on again. Given the values (a1, b1),(a2, b2), ..(an, bn), we want to find the number of times the lights get switched on. I got this algorithm in O(nlogn) using mergesort with help from someone in this page, but i dont know how to write a code for a complexity O(n^2), i was trying to use bubble sort for ordering the array like i did in the past algorithm but i got some cases where my code doesnt work. This is the answer i got for O(nlogn), how could i write it for a complexity O(n^2) ? The algorithm can be shown as: Create array numbers with values ai's and bi's Sort array numbers let x = 0 let count = 0 for each element in numbers repeat: if element is entry time then: if x is O then: count = count + 1 X = x +1 if element is exit time then: X = x -1 Display value of count as number of times light get switched on There are n people entering and exiting a room. For each i e (1,. .., n), person i enters at time ai and exits at time bi (assume bi > ai for all i), and all the ai , bi are distinct. At the beginning of the day, the lights in the room are switched off, and the first person who enters the room switches them on. In order to conserve electricity, if person i leaves the room at time bi and there is no one else present in the room at time bi , then person i will switch the lights off. The next person to enter will then switch them on again. Given the values (a1, b1),(a2, b2), ..(an, bn), we want to find the number of times the lights get switched on. I got this algorithm in O(nlogn) using mergesort with help from someone in this page, but i dont know how to write a code for a complexity O(n^2), i was trying to use bubble sort for ordering the array like i did in the past algorithm but i got some cases where my code doesnt work. This is the answer i got for O(nlogn), how could i write it for a complexity O(n^2) ? The algorithm can be shown as: Create array numbers with values ai's and bi's Sort array numbers let x = 0 let count = 0 for each element in numbers repeat: if element is entry time then: if x is O then: count = count + 1 X = x +1 if element is exit time then: X = x -1 Display value of count as number of times light get switched on There are n people entering and exiting a room. For each i e (1,. .., n), person i enters at time ai and exits at time bi (assume bi > ai for all i), and all the ai , bi are distinct. At the beginning of the day, the lights in the room are switched off, and the first person who enters the room switches them on. In order to conserve electricity, if person i leaves the room at time bi and there is no one else present in the room at time bi , then person i will switch the lights off. The next person to enter will then switch them on again. Given the values (a1, b1),(a2, b2), ..(an, bn), we want to find the number of times the lights get switched on. I got this algorithm in O(nlogn) using mergesort with help from someone in this page, but i dont know how to write a code for a complexity O(n^2), i was trying to use bubble sort for ordering the array like i did in the past algorithm but i got some cases where my code doesnt work. This is the answer i got for O(nlogn), how could i write it for a complexity O(n^2) ? The algorithm can be shown as: Create array numbers with values ai's and bi's Sort array numbers let x = 0 let count = 0 for each element in numbers repeat: if element is entry time then: if x is O then: count = count + 1 X = x +1 if element is exit time then: X = x -1 Display value of count as number of times light get switched on There are n people entering and exiting a room. For each i e (1,. .., n), person i enters at time ai and exits at time bi (assume bi > ai for all i), and all the ai , bi are distinct. At the beginning of the day, the lights in the room are switched off, and the first person who enters the room switches them on. In order to conserve electricity, if person i leaves the room at time bi and there is no one else present in the room at time bi , then person i will switch the lights off. The next person to enter will then switch them on again. Given the values (a1, b1),(a2, b2), ..(an, bn), we want to find the number of times the lights get switched on. I got this algorithm in O(nlogn) using mergesort with help from someone in this page, but i dont know how to write a code for a complexity O(n^2), i was trying to use bubble sort for ordering the array like i did in the past algorithm but i got some cases where my code doesnt work. This is the answer i got for O(nlogn), how could i write it for a complexity O(n^2) ? The algorithm can be shown as: Create array numbers with values ai's and bi's Sort array numbers let x = 0 let count = 0 for each element in numbers repeat: if element is entry time then: if x is O then: count = count + 1 X = x +1 if element is exit time then: X = x -1 Display value of count as number of times light get switched on
Expert Answer:
Answer rating: 100% (QA)
The algorithm can be written using below idea 1 There are n entry times ais and n exit times bis ... View the full answer
Related Book For
College Algebra Graphs and Models
ISBN: 978-0321845405
5th edition
Authors: Marvin L. Bittinger, Judith A. Beecher, David J. Ellenbogen, Judith A. Penna
Posted Date:
Students also viewed these finance questions
-
There are n people eligible to vote in a certain election. Voting requires registration. Decisions are made independently. Each of the n people will register with probability p1. Given that a person...
-
There are n people eligible to vote in a certain election. Voting requires registration. Decisions are made independently. Each of the n people will register with probability p1. Given that a person...
-
Number of Handshakes. If there are n people in a room, the number N of possible handshakes by all the people in the room is given by the function For what number of n people is 66 ( N ( 300? n("-1)...
-
In 1991, good x cost $5 and good y cost $1. They now cost $9 and $5 respectively. In 1991 the consumption bundle of x and y was 4 x s and 5 y s. It is now 9 x s and 7 y s. Calculate the Laspeyres...
-
Using AS and AD analysis, explain what effects, if any, the following changes have on each nation's GDP Price Index and real GDP. Explain your answer, and draw the appropriate supply and demand...
-
Suppose you and a friend, each of mass \(60 \mathrm{~kg}\), go to the park and get on a 4.0-m-diameter merry-go-round. You stand on the outside edge of the merry-go-round, while your friend pushes so...
-
Consider a steam engine that operates in a Rankine cycle as shown in Figure 10.40: The turbine exhaust is a saturated vapor. (a) Find the saturation temperature of the turbine exhaust. (b) For an...
-
The post-closing trial balance for Cortez Co. is as follows. The subsidiary ledgers contain the following information: (1) accounts receivable'J. Anders $2,500, F. Cone $7,500, T. Dudley $5,000; (2)...
-
Solve the initial value problem dy(x)+3a y(x) = cos (5x) e (-23). y(x)= y (0)=-1
-
Rovio has shifted their products between games, activity parks, movies, licensing etc., how have they handled different steps in the entrepreneurial process?
-
BGR Corp, a U.S. business, wants to establish a base in a certain foreign nation but finds the only way to do business there is to pay off certain persons "unofficially" on a regular basis. In bold...
-
What is the magnitude of the impulse component that is perpendicular to the wall? [J = -2.5 kgm/s] 8. A 35.0 g bullet is traveling nearly horizontally at 465 m/s. It ricochets off a piece of metal...
-
Alan Taylor is settling a $18,930 loan due today by making 6 equal annual payments. Click here to view factor tables. What payments must Alan Taylor make to settle the loan at an interest rate of 8%,...
-
To find the distance across a lake, a surveyor took the measurements in the figure shown. Use these measurements to determine how far it is across the lake. a= yd (Round the answer to the nearest...
-
Discuss the importance of visual merchandising to Walmart's success in the retail marketplace. Identify what you consider to be one example of failed merchandising in your store. Explain why you...
-
An oil company purchased an option on land in Alaska. Preliminary geologic studies assigned the following prior probabilities. a. What is the probability of finding oil (to 2 decimals)?...
-
A vehicle distributor in the United States has purchase contracts with the Ca. Europa Motors of Great Britain, the distributor purchased on July 2, 1999 a batch of 80 sedan vehicles for the total...
-
The ultimate goal of Google, Bing, and other consumer search engines is to provide users with search listings that contain useful information on the topic of their search. What recommendations would...
-
Find the zeros of the polynomial function and state the multiplicity of each. a) f(x) = (x + 3)2 (x - 1) b) f (x) = (x + 5)3 (x - 4) (x + 1)2 c) f (x) = - 2(x - 4) (x - 4) (x - 4) (x + 6)
-
Find the inverse of the given one-to-one function f. Give the domain and the range of f and of f-1 and then graph both f and f-1 on the same set of axes a. f (x) = 2 - 5x b. f (x) = (x - 3) / (x + 2)
-
The amount of spending on antipsychotic drugs, used to treat schizophrenia and other conditions, recently edged out cholesterol medications at the top of U.S. sales charts. The function a(x) = 1.24x...
-
(a) Among 880 smart phones sold by a retailer, 72 required repairs under the warranty. Estimate the probability that a new phone, which has just been sold, will require repairs under the warranty....
-
A car rental agency has 19 compact cars and 12 intermediate-size cars. If four of the cars are randomly selected for a safety check, what is the probability of getting two of each kind?
-
With reference to Exercise 3.34, suppose that the questionnaire filled in by one of the 150 persons is to be double-checked. If it is chosen in such a way that each questionnaire has a probability of...
Study smarter with the SolutionInn App