(Solve in Dev c++) Given a schedule containing the arrival and departure time of trains in a station. Find the minimum number of platforms needed to avoid delay in any train’s arrival. The idea is to merge the arrival and deprature time of trains and consider them in sorted order. Maintain a counter to count the number of trains present at the station at any point. The counter also represents the total number of platforms needed at that time. · If the train is scheduled to arrive next, increase the counter by one and update the minimum platforms needed if the count is more than the minimum platforms needed so far. · If the train is scheduled to depart next, decrease the counter by 1. One special case needs to be handled – when two trains are scheduled to arrive and depart simultaneously, depart the train first.
(Solve in Dev c++) Given a schedule containing the arrival and departure time of trains in a station. Find the minimum number of platforms needed to avoid delay in any train’s arrival. The idea is to merge the arrival and deprature time of trains and consider them in sorted order. Maintain a counter to count the number of trains present at the station at any point. The counter also represents the total number of platforms needed at that time. · If the train is scheduled to arrive next, increase the counter by one and update the minimum platforms needed if the count is more than the minimum platforms needed so far. · If the train is scheduled to depart next, decrease the counter by 1. One special case needs to be handled – when two trains are scheduled to arrive and depart simultaneously, depart the train first.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
(Solve in Dev c++)
Given a schedule containing the arrival and departure time of trains in a station. Find the minimum number of platforms needed to avoid delay in any train’s arrival.
The idea is to merge the arrival and deprature time of trains and consider them in sorted order. Maintain a counter to count the number of trains present at the station at any point. The counter also represents the total number of platforms needed at that time.
-
· If the train is scheduled to arrive next, increase the counter by one and update the minimum platforms needed if the count is more than the minimum platforms needed so far.
-
· If the train is scheduled to depart next, decrease the counter by 1.
One special case needs to be handled – when two trains are scheduled to arrive and depart simultaneously, depart the train first.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps