1. Stack and Queue
• Introduction, Representation, Operations &
Applications
• Presented by [Your Name]
2. Stack - Introduction
• A stack is a linear data structure that follows
the LIFO (Last In First Out) principle.
• Real-life Example: Stack of plates
•
A stack is a collection of elements with two principal operations: push and pop. It follows the LIFO
principle, where the last element added is the first to be removed.
3. Stack - Representation
• Can be represented using:
• - Arrays
• - Linked List
• Top of stack points to the most recently added
element.
•
Stacks can be implemented using arrays or linked lists. The 'top' pointer keeps track of the last inserted
element.
4. Stack - Operations
• 1. push(element): Add element to top
• 2. pop(): Remove top element
• 3. peek(): View top element
• 4. isEmpty(): Check if stack is empty
5. Applications of Stack
• - Expression Evaluation (Postfix/Infix)
• - Undo operations in text editors
• - Recursive Function Calls
• - Backtracking Algorithms
•
Used in expression parsing, recursive function calls, undo mechanisms, and backtracking algorithms.
6. Queue - Introduction
• A queue is a linear data structure that follows
the FIFO (First In First Out) principle.
• Real-life Example: Queue at a ticket counter
7. Queue - Representation
• Can be represented using:
• - Arrays
• - Linked Lists
• Maintains front and rear pointers
•
Queues use two pointers: 'front' and 'rear' for tracking the first and last elements. Implemented using
arrays or linked lists.
8. Queue - Operations
• 1. enqueue(element): Add to rear
• 2. dequeue(): Remove from front
• 3. peek(): View front element
• 4. isEmpty(): Check if queue is empty
9. Types of Queue
• - Simple Queue
• - Circular Queue
• - Priority Queue
• - Double-Ended Queue (Deque)
•
1. Simple Queue: FIFO structure
2. Circular Queue: Efficient space usage
3. Priority Queue: Based on priority
4. Deque: Insert/delete from both ends.
10. Applications of Queue
• - CPU & Disk Scheduling
• - Print Spooling
• - Handling Asynchronous Data
• - Call Center Systems
•
Used in scheduling (CPU, disk), print jobs, asynchronous data, and systems like call centers.
12. Stack - Java Pseudocode
• class Stack {
• int[] stack = new int[100];
• int top = -1;
• void push(int x) {
• stack[++top] = x;
• }
• int pop() {
• return stack[top--];
• }
• int peek() {
• return stack[top];
• }
13. Queue - Java Pseudocode
• class Queue {
• int[] queue = new int[100];
• int front = 0, rear = -1;
• void enqueue(int x) {
• queue[++rear] = x;
• }
• int dequeue() {
• return queue[front++];
• }
• int peek() {
• return queue[front];
• }
14. Stack - Explanation
• A stack is a collection of elements with two
principal operations: push (to insert an
element) and pop (to remove the top
element). It operates on the LIFO principle,
meaning the last element added is the first to
be removed.
15. Stack - Representation Explanation
• Stacks can be implemented using arrays or
linked lists. In an array-based implementation,
a single variable 'top' is used to track the last
inserted element. In a linked list, each node
points to the next, and the top points to the
last inserted node.
16. Stack - Applications Explanation
• Stacks are used in many areas like expression
parsing, function call management in
recursion, undo features in applications, and
backtracking algorithms such as maze solving.
17. Queue - Representation
Explanation
• Queues are implemented using arrays or
linked lists. It uses two pointers: front (points
to the first element) and rear (points to the
last element). This setup helps manage
insertion and deletion from opposite ends
efficiently.
18. Types of Queue - Explanation
• 1. Simple Queue: FIFO structure.
• 2. Circular Queue: Connects end to front for
efficient space use.
• 3. Priority Queue: Elements are processed
based on priority.
• 4. Deque: Double-ended queue allowing
insertion/deletion from both ends.
19. Queue - Applications Explanation
• Queues are used in scheduling algorithms
(CPU, disk), managing print jobs,
asynchronous data transfer, and in real-world
scenarios like call centers or waiting lines
where order must be preserved.