Design an airline system (graph theory, complexity analysis)
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-03-30
Problem Statement
Designing an airline management system that manages flights, airports, and routes. The system should support route queries, shortest paths, and availability checks, making it ideal for graph-based modeling.
✅ Functional Requirements
1.Airport Management
•Add, update, and remove airports.
•Each airport has metadata: airportCode, name, city, country.
2.Flight Management
•Add, update, and remove flights.
•Flight metadata: flightNumber, sourceAirport, destinationAirport, departureTime, arrivalTime, capacity, availableSeats.
3.Route Queries & Planning
•Find available flights between two airports.
•Compute shortest path / minimum hops / cheapest flight using graph traversal algorithms.
•Support direct and connecting flights.
4.Booking & Availability
•Book a seat on a flight → decrease availableSeats.
•Cancel a booking → increase availableSeats.
•Check availability of flights for a given date/time.
5.Optional Features
•Track passenger information.
•Generate flight schedules and updates.
•Predict route load using historical data.
🔐 Constraints & Assumptions
•Focus is on LLD, graph modeling, and algorithmic operations, not on payment processing.
•Assume flights are unidirectional edges in the graph.
•The system should handle thousands of airports and flights efficiently.
🧱 Key Components & Classes
1.Airport Class
1
2class Airport {
3private:
4 string airportCode;
5 string name;
6 string city;
7 string country;
8 vector<Flight*> outgoingFlights;
9public:
10 void addFlight(Flight* flight);
11 vector<Flight*> getOutgoingFlights();
12};1.Flight Class
1
2class Flight {
3private:
4 string flightNumber;
5 Airport* source;
6 Airport* destination;
7 DateTime departureTime;
8 DateTime arrivalTime;
9 int capacity;
10 int availableSeats;
11public:
12 bool bookSeat();
13 void cancelSeat();
14};1.AirlineSystem Class
•Core class managing airports, flights, and routes.
1
2class AirlineSystem {
3private:
4 map<string, Airport*> airports;
5public:
6 void addAirport(Airport* airport);
7 void addFlight(Flight* flight);
8 vector<Flight*> findFlights(string sourceCode, string destCode);
9 vector<string> findShortestRoute(string sourceCode, string destCode); // graph traversal
10};1.Booking Class (Optional)
•Tracks passenger bookings.
1
2class Booking {
3private:
4 string bookingId;
5 string passengerName;
6 Flight* flight;
7public:
8 void confirmBooking();
9 void cancelBooking();
10};🔄 Example Workflow
1.Admin adds airports → AirlineSystem.addAirport().
2.Admin adds flights → AirlineSystem.addFlight().
3.Passenger searches for flights → findFlights() returns available options.
4.Compute shortest route or minimum hops → findShortestRoute() using BFS/Dijkstra.
5.Passenger books a flight → Flight.bookSeat() updates availableSeats.
6.Optional: Cancel booking → Flight.cancelSeat() restores availability.
🧪 Expected Deliverables
•Class diagram showing Airport, Flight, AirlineSystem, and Booking.
•Implementation of airport/flight management, route queries, and booking operations.
•Test cases:
•Add airports and flights
•Find direct and connecting flights
•Shortest route computation using graph traversal
•Booking and seat availability updates
💡 Discussion Points
•Graph Modeling: airports as nodes, flights as edges.
•Complexity Analysis:
•BFS for shortest hops: O(V + E)
•Dijkstra for cheapest flight: O((V+E) log V) with priority queue
•Scalability: thousands of airports and flights.
•Concurrency: multiple users booking flights simultaneously.
•Extensibility: support multi-leg journeys, real-time seat updates.