Chapter 4 – Queue
1. Algorithm to Check Whether a String is Palindrome or Not.
>>Algorithm:
1. Initialize two pointers: start = 0, end = length-1.
2. While start < end:
If string[start] != string[end] → Not palindrome.
Increment start, decrement end.
3. If loop finishes → Palindrome.
2. What is Queue? Define Queue
A queue is a linear data structure that follows the FIFO (First In,
First Out) principle.
Insertion → Enqueue (rear end)
Deletion → Dequeue (front end)
3. What is Deque? Define Deque
>>A Deque (Double-Ended Queue) is a linear data structure that
allows insertion and deletion at both front and rear ends.
4. Difference Between Queue and Deque
Queue Deque
Insertion only at rear Insertion at both ends
Deletion only at front Deletion at both ends
Simpler structure More flexible structure
5. Difference Between Stack and Queue
Stack Queue
LIFO principle FIFO principle
Push & Pop Enqueue & Dequeue
One end used for both insertion and deletion Two ends: front
(delete) & rear (insert)
Example: Plates stack Example: Waiting line.