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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started