Report
Report
Overview
The gatorTicketMaster project implements a seat reservation system that allows users to reserve, cancel,
update priorities, and manage waitlists for event seats. The program uses several core data structures, such
as Binary Min Heaps and a Red-Black tree, to manage seat reservations, cancellations, and the waitlist
efficiently.
Features:
Usage
Run the program by providing an input file as a command-line argument:
The input file should include commands to initialize seats, reserve, cancel, release, and manage the
waitlist, each separated by a newline.
Program Structure
● gatorTicketMaster Class: Manages seats, reservations, cancellations, priority updates, and
printing. This class holds instances of RedBlackTree and a priority queue for handling seat
reservations and waitlisted users.
● RedBlackTree Class: Stores reserved seats with efficient search, insertion, and deletion
operations.
● WaitlistUser Class: Manages waitlisted users, using a priority queue to ensure high-priority users
are served first.
1. gatorTicketMaster Class
// gatorTicketMaster class for seat reservation system
public class gatorTicketMaster {
// Constructor
public gatorTicketMaster();
// Adds more seats to the system and assigns them to waitlisted users if necessary
public void addSeats(int count);
2. WaitlistUser Class
// WaitlistUser class that stores user ID, priority, and timestamp
public static class WaitlistUser {
// Instance variables
private final int userId;
private int priority;
private final long timestamp;
// Constructor to initialize a WaitlistUser object with a userId and priority
public WaitlistUser(int userId, int priority);
3. RedBlackTree Class
// RedBlackTree class for managing reserved seats
public class RedBlackTree {
Class Descriptions
Class gatorTicketMaster
The main class manages the system by coordinating seat reservations, cancellations, waitlist entries, and
modifications to priority.
Fields:
Methods:
● initialize(int seatCount)
Initializes the system with a specified number of seats.
○ Input: seatCount - number of seats to initialize.
○ Output: Adds seats to availableSeats, clears waitlist and reserved seats.
● reserve(int userId, int userPriority)
Reserves a seat for a user or adds them to the waitlist if no seats are available.
○ Input: userId - unique identifier for the user; userPriority - user's priority level.
○ Output: If available, assigns a seat and stores it in reservedSeats; otherwise, adds user to
waitlist.
● cancel(int seatId, int userId)
Cancels a reservation for a user, returning the seat to available seats or assigning it to the
highest-priority waitlisted user.
○ Input: seatId - seat to be canceled; userId - user requesting cancellation.
○ Output: Frees the seat and reassigns it if needed; otherwise, returns it to availableSeats.
● addSeats(int count)
Adds additional seats and assigns them to the waitlist if users are waiting.
○ Input: count - number of additional seats to add.
○ Output: Assigns new seats to the waitlisted users or adds them to availableSeats.
● releaseSeats(int userId1, int userId2)
Releases seats reserved by users within the specified user ID range.
○ Input: userId1, userId2 - range of user IDs.
○ Output: Frees seats held by the users in the range and reassigns them based on waitlist
priorities.
● updatePriority(int userId, int newPriority)
Updates the priority of a user on the waitlist.
○ Input: userId - ID of the user whose priority needs updating; newPriority - the new
priority value.
○ Output: Removes and re-adds the user to waitlist with the updated priority.
● available()
Displays the count of available seats and the number of users in the waitlist.
○ Output: Prints available seats and waitlist size.
● exitWaitlist(int userId)
Removes a user from the waitlist.
○ Input: userId - ID of the user to be removed.
○ Output: Removes the specified user from the waitlist.
● printReservations()
Displays all seat reservations in ascending order.
○ Output: Prints reservedSeats list in a sorted order by seat ID.
Class RedBlackTree
A specialized data structure for storing and managing reservations with optimal performance for insertion,
deletion, and search operations.
Methods:
Class WaitlistUser
Manages information for users on the waitlist, including user ID, priority, and a timestamp to resolve
conflicts in priority.
Fields:
Methods:
● getUserId()
Returns the user ID.
○ Output: User ID of the waitlisted user.
● getPriority()
Returns the priority level of the user.
○ Output: Priority level of the user.
● setPriority(int priority)
Sets the priority level for the user.
○ Input: priority - new priority level for the user.
● getTimestamp()
Returns the timestamp associated with the user.
○ Output: Timestamp for waitlist ordering.
● initialize(int seatCount):
○ Time Complexity: O(seatCount log seatCount)O(seatCount log seatCount)O(seatCount
log seatCount) (due to adding seats to the priority queue).
○ Space Complexity: O(seatCount)O(seatCount)O(seatCount) for storing the available
seats.
● reserve(int userId, int userPriority):
○ Time Complexity: O(logn)O(log n)O(logn) for adding a seat to the Red-Black Tree if
available or adding to the priority queue if full.
○ Space Complexity: O(1)O(1)O(1), but with additional O(logn)O(log n)O(logn) space if
the seat is added to the priority queue.
● cancel(int seatId, int userId):
○ Time Complexity: O(logn)O(log n)O(logn) for removing a seat from the Red-Black
Tree, followed by O(logn)O(log n)O(logn) for adjusting the waitlist or the priority queue.
○ Space Complexity: O(1)O(1)O(1), as this operation does not store additional elements.
● addSeats(int count):
○ Time Complexity: O(countlogn)O(count \log n)O(count logn), where n is the size of the
Red-Black Tree, for adding new seats and handling any waitlisted users.
○ Space Complexity: O(count)O(count)O(count) for storing new seats in the queue.
● releaseSeats(int userId1, int userId2):
○ TimeComplexity:O((userId2−userId1)logn)O((userId2-userId1)logn)O((userId2−userId1
)logn), where n is the number of reservations being canceled.
○ Space Complexity: O(userId2−userId1)O(userId2 - userId1)O(userId2−userId1), since
this operation may store several seats for redistribution or return to availability.
● updatePriority(int userId, int newPriority):
○ Time Complexity: O(n)O(n)O(n) for locating the user in the waitlist, given a linear
search.
○ Space Complexity: O(1)O(1)O(1) if the update is done directly without duplicating list
data.
● available():
○ Time Complexity: O(1)O(1)O(1) for simply reporting counts.
○ Space Complexity: O(1)O(1)O(1).
● exitWaitlist(int userId):
○ Time Complexity: O(n)O(n)O(n), since we iterate through the waitlist to find and
remove the user.
○ Space Complexity: O(1)O(1)O(1), as the list size only reduces without any new
allocations.
● printReservations():
○ Time Complexity: O(n)O(n)O(n), where n is the number of reserved seats, as it requires
an inorder traversal of the Red-Black Tree.
○ Space Complexity: O(n)O(n)O(n), for maintaining the list of reservations for printing.
2. RedBlackTree Class
3. WaitlistUser Class
● The WaitlistUser class maintains a priority-based timestamp list using a priority queue. All
operations that involve priority changes are O(logn)O(log n)O(log n) due to the properties of a
priority queue.
Summary
The overall performance of this gatorTicketMaster ticket management system primarily depends on the
number of users and seats due to the Red-Black Tree and Priority Queue operations, both of which are
O(logn)O(log n)O(log n) in time complexity for typical operations. The space complexity for most
operations remains efficient, as data is stored in-place without excess overhead, other than for printing or
counting items.