GPT Breakdown
GPT Breakdown
P1: Create a design specification for data structures explaining the valid operations
Data Structures: Use a Queue for customer registration and seat reservations, a List for
bus registrations, and stacks for managing changes (undo/cancel).
Operations:
o Queue Operations: Enqueue (reserve seat), Dequeue (cancel reservation), Peek
(view next reservation).
o List Operations: Add (register bus), Search (search bus), Remove (unregister
bus).
o Stack Operations: Push (new action), Pop (undo), Peek (view last action).
P2: Determine the operations of a memory stack and how it is used to implement function
calls
Example: In a browser, the stack manages history by pushing pages as they are visited
and popping them when the user goes back.
M1: Illustrate a concrete data structure for a First In First Out (FIFO) queue
Queue Operations:
o Enqueue: Adds a new customer to the reservation system.
o Dequeue: Removes the customer when they cancel a reservation.
o Peek/Front: Views the first customer in the queue.
o Poll: Retrieves and removes the first customer.
o Size: Checks the number of customers in the queue.
Example: When a customer books a bus seat, they are added to the queue. If they cancel,
the next customer is notified and dequeued.
Bubble Sort (O(n²)): Slower, especially for large datasets. It repeatedly swaps adjacent
elements until sorted.
Merge Sort (O(n log n)): Faster for larger datasets as it divides the array into smaller
arrays and merges them back.
Performance Comparison:
o Bubble Sort is inefficient for large data but easy to implement.
o Merge Sort is more efficient for large datasets but uses more memory (recursive
calls).
P3: Using an imperative definition, specify the abstract data type for a software stack
java
Copy code
public class ReservationStack {
private Stack<ReservationChange> stack = new Stack<>();
public void pushChange(ReservationChange change)
{ stack.push(change); }
public ReservationChange popChange() { return stack.pop(); }
public ReservationChange peekChange() { return stack.peek(); }
}
M3: Examine the advantages of encapsulation and information hiding when using an ADT
Encapsulation: Hides the internal workings of the ADT (such as stack operations). Users
only interact with public methods, ensuring data integrity.
Information Hiding: Prevents unauthorized access to the internal structure of the stack,
making the system more secure and easier to maintain.
Advantages:
o Reduces complexity for the user (they don’t need to understand the stack’s
internal workings).
o Enhances security and prevents accidental data corruption.
Bus Seat Reservation System: Implement a Queue for seat reservations and a Stack for
managing reservation changes.
o Queue: Manages customers waiting for seats.
o Stack: Manages customer requests for seat changes.
java
Copy code
Queue<Customer> reservationQueue = new LinkedList<>();
Stack<ChangeRequest> changeStack = new Stack<>();
Test Cases:
Problem Solved: The queue ADT efficiently handles seat reservations in a First-In-First-
Out manner, ensuring fairness. The stack manages reservation changes and cancellations.
Illustration: If a customer cancels, the queue ensures the next customer is promptly
notified, and the stack keeps track of changes.
P7: Determine two ways in which the efficiency of an algorithm can be measured
1. Time Complexity: How long the algorithm takes to complete based on input size.
o Example: Searching for a bus by number using linear search (O(n)) vs. binary
search (O(log n)).
2. Space Complexity: The amount of memory an algorithm uses.
o Example: Merge Sort uses more space (due to recursion) than Bubble Sort, which
sorts in place.
Trade-off Example: Using a stack to manage reservation changes (LIFO) allows quick
access to the most recent change, but it cannot easily access older changes (FIFO
operations would require a queue).
Trade-off Discussion: A stack is fast for recent operations but isn’t suitable for accessing
older records, which might require additional memory or data structures like a list or
queue.