0% found this document useful (0 votes)
6 views

GPT Breakdown

Assigment breakdown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

GPT Breakdown

Assigment breakdown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LO1: Examine abstract data types, concrete data structures, and algorithms

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

 Memory Stack Operations:


o Push: Adds a function call to the top of the stack.
o Pop: Removes the topmost function call (when a function finishes execution).
o Peek/Top: Views the most recent function call.
o isEmpty: Checks if the stack is empty.

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.

M2: Compare the performance of two sorting algorithms

 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).

LO2: Specify abstract data types and algorithms in formal notation

P3: Using an imperative definition, specify the abstract data type for a software stack

 ADT for Stack (in our bus reservation system):


o Operations:
 Push: Adds a new reservation change request.
 Pop: Removes the most recent change.
 Peek: Views the most recent reservation change.
o Definition:

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.

LO3: Implement complex data structures and algorithms

P4: Implement a complex ADT and algorithm in an executable programming language

 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 Code Example:

java
Copy code
Queue<Customer> reservationQueue = new LinkedList<>();
Stack<ChangeRequest> changeStack = new Stack<>();

public void reserveSeat(Customer customer) {


reservationQueue.add(customer);
notifyCustomer(customer, "Seat reserved.");
}

public void cancelReservation(Customer customer) {


reservationQueue.remove(customer);
notifyCustomer(customer, "Reservation cancelled.");
notifyNextCustomer();
}

P5: Implement error handling and report test results

 Error Handling: Implement try-catch blocks to handle exceptions such as seat


overbooking, invalid customer input, or empty queues.
o Example: Catching a NullPointerException if an empty queue is accessed.

Test Cases:

o Test ID: TC01


o Test Name: Reserve Seat
o Input: Customer A books a seat.
o Expected Output: Seat reserved message sent.
o Actual Output: Same.
o Pass/Fail: Pass.

M4: Demonstrate how the implementation of an ADT/algorithm solves a well-defined


problem

 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.

LO4: Assess the effectiveness of data structures and algorithms


P6: Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm

 Asymptotic Analysis: Evaluates the performance of an algorithm by considering its time


complexity in terms of input size (Big-O notation).
o Example: Sorting customers by age using Merge Sort (O(n log n)) is more
efficient than Bubble Sort (O(n²)) for large datasets.

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.

M5: Interpret what a trade-off is when specifying an ADT using an example

 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.

You might also like