Data Structures and Algorithms · Unit 3
Linear Data Structures: Stacks and Queues
Exam-focused notes for Linear Data Structures: Stacks and Queues (Data Structures and Algorithms, BIT201): what the TU syllabus asks and how it has actually been tested, with 12 solved past questions from this unit.
What this unit covers
- Stack definition and operations
- Queue definition and operations
- Differentiation between stack and queue
- Simple queue implementation
- Circular queue advantages and implementation
- Priority queue definition and implementation
- Queue implementation using linked list
- Stack implementation using linked list
- Infix to postfix conversion using stack
- Postfix expression evaluation algorithm
Circular queue advantages and implementation
Why do we need circular queue? Explain. [5]
In a simple linear queue implemented using an array, two pointers are maintained: - Front - points to the first element - Rear - points to the last element Consider a queue of size 5: After Enqueue A, B, C, D, E and then Dequeue A, B: Now if we try to Enque...
Full solved answer →What is circular queue? How can you implement circular queue? [5]
A circular queue is a linear data structure that follows the FIFO (First In First Out) principle, but the last position is connected back to the first position to form a circle. It overcomes the major limitation of a simple (linear) queue where memory space...
Full solved answer →Why circular queue is advantageous over linear queue? Write algorithm for enqueue and is full operation for circular queue. [5]
In a linear queue, once the rear pointer reaches the last index of the array, no more elements can be inserted even if there are empty slots at the front (created after dequeue operations). This leads to wastage of memory space. A circular queue solves this...
Full solved answer →Infix to postfix conversion using stack
Convert the infix expression 7 * 8 + 10 - 2 to postfix using stack. [5]
Infix expression to convert: $$7 8 + 10 - 2$$ Operator precedence: - , / : higher - +, - : lower Associativity: left to right. --- 1. Scan tokens left to right. 2. Operand → append to output. 3. Operator → pop operators from stack with precedence greater th...
Full solved answer →Explain algorithm to convert an infix expression to postfix using stack? Use this algorithm to convert (A+B)*C-D to postfix.[10]
- Infix expression to convert: $(A+B)C-D$ - Data structure to use: Stack - Task: (a) explain the algorithm, (b) apply it to the given expression. All required data is present. --- Operator Precedence --------------------- ^ 3 (highest) , / 2 +, - 1 ( inside...
Full solved answer →Simple queue implementation
What is simple queue? Describe about any three types of graphs. [2+3]
--- A simple queue (also called a linear queue) is a linear data structure that follows the FIFO (First In First Out) principle, meaning the element inserted first is the element removed first. Key characteristics: - Elements are inserted from the REAR end ...
Full solved answer →Postfix expression evaluation algorithm
What is stack? Explain different stack operations. Explain algorithm to evaluate postfix expression.[10]
--- A stack is a linear data structure that follows the LIFO (Last In, First Out) principle. This means the element inserted last is the first one to be removed. A stack can be visualized as a pile of plates: you add a plate on top and also remove from the ...
Full solved answer →Queue implementation using linked list
How can we use linked list to implement queue? Explain. [5]
A queue is a linear data structure that follows the FIFO (First In, First Out) principle. Using a linked list to implement a queue allows dynamic memory allocation, avoiding the fixed-size limitation of array-based queues. --- Each node in the linked list c...
Full solved answer →How can you implement queue using linked list? Explain. [5]
A queue is a linear data structure that follows the FIFO (First In, First Out) principle. Using a linked list to implement a queue allows dynamic memory allocation, avoiding the fixed-size limitation of array-based queues. Two pointers are maintained: - FRO...
Full solved answer →Priority queue definition and implementation
Explain priority queue with example. What is circular queue? [5]
A priority queue is a special type of queue in which each element is associated with a priority value, and elements are served (removed) based on their priority rather than their insertion order. - An element with higher priority is dequeued before an eleme...
Full solved answer →Define priority queue. How do you implement priority queue? Explain. [5]
A priority queue is an abstract data type (ADT) similar to a regular queue, but each element has an associated priority value. Elements are served (removed) based on their priority rather than their insertion order: - The element with the highest priority i...
Full solved answer →Differentiation between stack and queue
Differentiate stack with queue? Trace an algorithm for converting infix expression to postfix for the following infix expression: (A+B)*(C$(D-E)+F)-G[10]
Feature Stack Queue --------- Principle LIFO (Last In First Out) FIFO (First In First Out) Insertion/Deletion Both at the same end (top) Insertion at rear, deletion at front Operations PUSH (insert), POP (delete) ENQUEUE (insert), DEQUEUE (delete) Number of...
Full solved answer →Make Unit 3 stick
Practice BIT201 with flashcards & quizzes