We discuss how the IRCTC algorithm possibly works. It's a complex algorithm, but worth understanding!
Irctc Algorithm
Train ticketing system
How do we efficiently book tickets in the ticket booking system so the seats don't remain vacant?
It's a High-level design question.
Example: There are 10 stations and some person X books seats from 1 to 5 and some other person wants to book from 6 to 8. How do we handle that? How do we know who booked prior?
Here the exciting part is that we not only have to consider the allocations, but also we will have to search for trains.
We draw the UML diagram by considering the following:
•There is a Client who wants to book a seat through their web browser.
•The clients say that they want to book a journey with the specifications
• This is the case when the client wants to book a specific train.
• The other option is when the client searches for all trains available to reach the particular destination with the number of seats, and start date.
• The train should have information about the estimated time of arrival, estimated departure time, source, destinations, category and seats.
Multiple perspectives and multiple calculations..let's head to see the exact answer.
How do you book the seats?
The other interesting fact is that the centre of gravity has to be taken into account or the train will be heavier on one side alone.
If a single woman is travelling she needs to be placed with other women travelling on the same train.
All these are the considerations that need to be considered.
However, the brute force approach would be:
Book from A - B ( 2 seats)
The algorithm is like a rule engine. It goes through the preferences and chooses the best option for the client.
The time the rule engine runs to check all the preferences will become a matter of consideration here.
The duplication is good because it will make the search faster. Instead of a beat matrix, we can flatten it by making it an array.
So how do we approach this?
Let's head to the video!