Skip to content
Official PYQ · 2003

GATE CS 2003 Q69 — Algorithm Design: Greedy Techniques

Explain with AI

The following are the starting and ending times of activities A,B,C,D,E,F,GA, B, C, D, E, F, G and HH respectively in chronological order: “as bs cs ae ds ce es fs be de gs ee fe hs ge he”“a_s \: b_s \: c_s \: a_e \: d_s \: c_e \: e_s \: f_s \: b_e \: d_e \: g_s \: e_e \: f_e \: h_s \: g_e \: h_e”. Here, xsx_s denotes the starting time and xex_e denotes the ending time of activity X. We need to schedule the activities in a set of rooms available to us. An activity can be scheduled in a room only if the room is reserved for the activity for its entire duration. What is the minimum number of rooms required?

Choose one option
View worked solution

Answer: B

This problem is a classic instance of the Interval Partitioning (or Room Scheduling) problem. The minimum number of rooms required to schedule all activities is equal to the maximum number of overlapping activities at any single point in time.

We can find this by simulating the timeline chronologically and tracking the set of active activities at each step:

Event Action Active Activities Room Count
asa_sStart AA{A}\{A\}1
bsb_sStart BB{A,B}\{A, B\}2
csc_sStart CC{A,B,C}\{A, B, C\}3
aea_eEnd AA{B,C}\{B, C\}2
dsd_sStart DD{B,C,D}\{B, C, D\}3
cec_eEnd CC{B,D}\{B, D\}2
ese_sStart EE{B,D,E}\{B, D, E\}3
fsf_sStart FF{B,D,E,F}\{B, D, E, F\}4 (Max)
beb_eEnd BB{D,E,F}\{D, E, F\}3
ded_eEnd DD{E,F}\{E, F\}2
gsg_sStart GG{E,F,G}\{E, F, G\}3
eee_eEnd EE{F,G}\{F, G\}2
fef_eEnd FF{G}\{G\}1
hsh_sStart HH{G,H}\{G, H\}2
geg_eEnd GG{H}\{H\}1
heh_eEnd HH∅\emptyset0

The maximum number of concurrent activities is 44 (which occurs when activity FF starts while B,D,B, D, and EE are still running). Thus, the minimum number of rooms required is 44.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Algorithm Design: Greedy Techniques questions