0% found this document useful (0 votes)
3 views7 pages

Report

The gatorTicketMaster project is a seat reservation system that allows users to reserve, cancel, and manage waitlists for event seats using data structures like Binary Min Heaps and Red-Black trees. Key features include seat initialization, user reservation, dynamic priority updates, and reporting of seat availability. The system's performance is primarily determined by the number of users and seats, with typical operations having a time complexity of O(log n).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Report

The gatorTicketMaster project is a seat reservation system that allows users to reserve, cancel, and manage waitlists for event seats using data structures like Binary Min Heaps and Red-Black trees. Key features include seat initialization, user reservation, dynamic priority updates, and reporting of seat availability. The system's performance is primarily determined by the number of users and seats, with typical operations having a time complexity of O(log n).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Gator Ticket Master

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:

●​ Seat initialization and addition of extra seats


●​ User reservation and cancellation
●​ Waitlist management with prioritized entry based on user-provided priority
●​ Seat release by user ID range
●​ Dynamic priority updates for waitlisted users
●​ Reporting of available seats and waitlist status

Usage
Run the program by providing an input file as a command-line argument:

java gatorTicketMaster inputFile.txt

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.

Class and Function Prototypes

1. gatorTicketMaster Class
// gatorTicketMaster class for seat reservation system
public class gatorTicketMaster {

// Constructor
public gatorTicketMaster();

// Initializes the system with a number of seats


public void initialize(int seatCount);

// Reserves a seat for a user with a given priority


public void reserve(int userId, int userPriority);

// Cancels a user's reservation and reassigns the seat if necessary


public void cancel(int seatId, int userId);

// Adds more seats to the system and assigns them to waitlisted users if necessary
public void addSeats(int count);

// Releases seats for users in the given range of user IDs


public void releaseSeats(int userId1, int userId2);

// Updates the priority of a user on the waitlist


public void updatePriority(int userId, int newPriority);

// Displays the number of available seats and users on the waitlist


public void available();

// Removes a user from the waitlist


public void exitWaitlist(int userId);

// Prints the list of seat reservations


public void printReservations();

// Main function that processes input commands from a file


public static void main(String[] args);
}

2. WaitlistUser Class
// WaitlistUser class that stores user ID, priority, and timestamp
public static class WaitlistUser {

// Static counter to generate unique timestamps for users


private static long counter = 0;

// 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);

// Getter for userId


public int getUserId();

// Getter for priority


public int getPriority();

// Setter for priority


public void setPriority(int priority);

// Getter for timestamp


public long getTimestamp();
}

3. RedBlackTree Class
// RedBlackTree class for managing reserved seats
public class RedBlackTree {

// Node class for storing seat reservations


private class Node {
int seatId;
int userId;
Node left, right, parent;
boolean color; // Red or Black

public Node(int seatId, int userId);


}

// Constructor for RedBlackTree


public RedBlackTree();

// Inserts a new reservation into the tree


public void insert(int userId, int seatId);

// Removes a reservation for a given user


public void remove(int userId);

// Performs in-order traversal and prints reservations


public void printTree();

// Returns the maximum seatId in the tree


public int getMaxSeatId();

// Returns the size of the tree (number of reserved seats)


public int size();
}

Class Descriptions
Class gatorTicketMaster

The main class manages the system by coordinating seat reservations, cancellations, waitlist entries, and
modifications to priority.

Fields:

●​ availableSeats: A priority queue to store available seat numbers in ascending order.


●​ reservedSeats: A red-black tree (RedBlackTree) to manage user-to-seat reservations.
●​ waitlist: A priority queue of WaitlistUser objects, ordered by priority and timestamp.

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:

●​ insert(int userId, int seatId)​


Adds a user and their reserved seat to the tree.
○​ Input: userId - ID of the user; seatId - reserved seat ID.
○​ Output: Adds a node with userId and seatId to reservedSeats.
●​ remove(int userId)​
Removes a user from reservedSeats, freeing their seat.
○​ Input: userId - ID of the user to remove.
○​ Output: Returns the seat ID associated with the user if found; otherwise, returns null.
●​ printTree()​
Prints the tree in ascending order by seat ID.
○​ Output: Displays seat assignments in ascending order.
●​ getMaxSeatId()​
Finds the highest seat ID in the tree.
○​ Output: Returns the highest seat ID in the tree.

Class WaitlistUser

Manages information for users on the waitlist, including user ID, priority, and a timestamp to resolve
conflicts in priority.

Fields:

●​ userId: ID of the user on the waitlist.


●​ priority: Priority level of the user.
●​ timestamp: Auto-incremented timestamp to resolve conflicts when users share the same priority
level.

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.

Time and Space Complexity Analysis


1. gatorTicketMaster Class

●​ 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(log⁡n)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(log⁡n)O(log n)O(logn) space if
the seat is added to the priority queue.
●​ cancel(int seatId, int userId):
○​ Time Complexity: O(log⁡n)O(log n)O(logn) for removing a seat from the Red-Black
Tree, followed by O(log⁡n)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(countlog⁡n)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)log⁡n)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

●​ Insertion (insert(int userId, int seatId)):


○​ Time Complexity: O(log⁡n)O(log n)O(log n), as each insertion requires balancing the
Red-Black Tree.
○​ Space Complexity: O(1)O(1)O(1), as the tree structure is maintained in-place.
●​ Deletion (remove(int userId)):
○​ Time Complexity: O(log⁡n)O(\log n)O(log n), since we search for the node, delete it, and
potentially balance the tree.
○​ Space Complexity: O(1)O(1)O(1), as it modifies the tree in place without extra storage.
●​ Minimum Node Retrieval (minimum(Node node)):
○​ Time Complexity: O(log⁡n)O(log n)O(log n), as we traverse the left-most branch of the
tree.
○​ Space Complexity: O(1)O(1)O(1).
●​ Inorder Traversal for Printing (inorderHelper(Node node, HashMap<Integer, Integer>
printmap)):
○​ Time Complexity: O(n)O(n)O(n), where n is the number of nodes in the tree.
○​ Space Complexity: O(n)O(n)O(n), for storing the results in printmap.

3. WaitlistUser Class

●​ The WaitlistUser class maintains a priority-based timestamp list using a priority queue. All
operations that involve priority changes are O(log⁡n)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(log⁡n)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.

You might also like