Question: Problem 2 There are n students enter the classroom at random times. For each i {1n} , let student i enters at time s_i and

Problem 2 There are n students enter the classroom at random times. For each i {1n} , let student i enters at time s_i and exits at time e_i (assume e_i > s_i for all i), and all the s_i , e_i are distinct. In the morning, the Air Condition is off, and the first person who enters the room switches the AC on. For electricity consumption purposes, if person i leaves the room at time e_i and there is no one else present in the classroom at time e_i , then the student i will switch the AC off. The next person to enter the class room will then switch the AC on again. For the set of given values (s_1,e_1), (s_2,e_2), (s_n,e_n) we want to find the number of times the AC get switched on. Design the following algorithms, and prove the correctness and analysis the running time of each algorithm. Your solution can be written in one of the following ways English words (with details) Pseudo code Actual source code A (n^2 ) algorithm that calculates the number of times the AC get switched on. (when does one turn the AC?) An O(nlogn) algorithms that calculates the number of times the AC get switched on (help: why not sort all s_iand e_i in a single augmented array first)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!