Btech Aiml Unit 2 Sem 2
Btech Aiml Unit 2 Sem 2
Abstract Data Type (ADT) – The List ADT – The Stack ADT: Definition, Array representation of
stack, Operations on stack: Infix, prefix, and postfix notations Conversion of an arithmetic
Expression from Infix to postfix. Applications of stacks. The Queue ADT: Definition, Array
representation of queue, Types of queues: Simple queue, circular queue, double ended queue
(de-queue) priority queue, operations on all types of Queues.
🔹 Applications of Stack
1. Expression Evaluation (Postfix, Prefix)
2. Function Calls (Recursion uses stack internally)
3. Undo/Redo Operations in Editors
4. Backtracking (Maze solving, DFS in graphs)
5. Memory Management (Handling function calls in RAM
✅ Real-life Examples:
● Queue in a ticket counter – The first person in the queue is served first.
● Print Queue – The first document sent for printing is printed first.
🔹 Applications of Queue
1. CPU Scheduling (Round Robin Algorithm).
2. Printer Queue (First document gets printed first).
3. Network Packet Handling (Data transmission uses queues).
4. Breadth-First Search (Graph traversal).
Types of Queues and Their Operations
🔹 1. Simple Queue (Linear Queue)
A simple queue follows the FIFO (First In, First Out) principle.
🔹 2. Circular Queue
A circular queue solves the problem of wasted space in a simple queue by connecting the
end to the beginning.
📌 Deque Operations
● enqueueFront(value): Inserts an element at the front.
● enqueueRear(value): Inserts an element at the rear.
● dequeueFront(): Removes an element from the front.
● dequeueRear(): Removes an element from the rear.
🔹 4. Priority Queue
A priority queue is a special type of queue where each element has a priority, and elements
with higher priority are dequeued first.
● If two elements have the same priority, they follow FIFO order.
● Can be implemented using arrays, linked lists, or heaps.