Queue
Class 12 · Computer Science
4 ideas in Class 12 Computer Science, explained in plain words, with games and quizzes to practise.
Queue and the FIFO Rule
Part of: Queue basics and operations
A queue is an ordered line where new items join at the rear end and leave from the front end. It follows the first-in-first-out rule: the item that joined first leaves first, like pupils in an assembly line or vehicles at a toll booth.
Why it matters. Queues keep service fair, from ticket counters to printers to web servers handling results. A learner who sees the pattern knows why requests are served in arrival order and when jumping the line is allowed.
Key words
- Queue
- : An ordered line where items join at one end and leave at the other.
- Front
- : The end from which items leave the queue.
- Rear
- : The end at which new items join the queue.
- FIFO Rule
- : The rule that the first item in is the first item out.
Try it in two minutes
- Line up four books as vehicles at a toll booth. Ask which leaves first.
- Send three print jobs in order. Ask which prints first.
- Ask your child to name who the front and the rear are.
Try at home. Ask your child to find three queues at home or outside and explain the rule each one follows.
Enqueue Dequeue and Helpers
Part of: Queue basics and operations
Enqueue adds an item at the rear and dequeue removes the front item. Adding to a full queue causes overflow and removing from an empty one causes underflow. Helper steps check emptiness, peek at the front item without removing it, and count the items. In Python, newcomers are appended at the end and the front item is removed from position zero.
Why it matters. Real queues must never lose a request or crash on an empty line. Learners who check before removing and peek before serving write reliable counters, printers and servers.
Key words
- Enqueue
- : Adding a new item at the rear of the queue.
- Dequeue
- : Removing the front item from the queue.
- Peek
- : Viewing the front item without removing it.
- Underflow
- : The error of removing from an empty queue.
- Overflow
- : The error of adding to a completely full queue.
Try it in two minutes
- Enqueue three tokens and peek. Ask what the front shows.
- Dequeue twice and count what remains.
- Dequeue until empty, then try once more and name the result.
Try at home. Ask your child to run a token counter with slips of paper and record every peek and dequeue.
Deque and Its Operations
Part of: Deque in Python
A deque is a double-ended queue where items can join or leave at either end. Its four moves are joining at the front, joining at the rear, leaving from the front and leaving from the rear. Using only one end turns it into a stack, while joining at the rear and leaving from the front turns it into an ordinary queue.
Why it matters. Some jobs need flexible ends, like a returning visitor rejoining at the front or history lists dropping old entries. Learners who master the four moves can shape one structure into stacks or queues as needed.
Key words
- Deque
- : A double-ended queue open for moves at both ends.
- Insert Front
- : Joining a new item at the front end.
- Insert Rear
- : Joining a new item at the rear end.
- Deletion Front
- : Removing an item from the front end.
- Deletion Rear
- : Removing an item from the rear end.
Try it in two minutes
- Build a deque by joining tokens at the rear only.
- Remove one token from each end and name what is left.
- Use a single end for all moves and ask which structure it mimics.
Try at home. Ask your child to act out a ticket line where a returning visitor rejoins at the front.
Deque in Action: Palindrome Check
Part of: Deque in Python
A palindrome reads the same from both ends, like LEVEL or MADAM. To test one, load its letters from left to right at the rear, then repeatedly take one letter from each end and compare the pair. Matching all the way down to empty, or to a single middle letter, proves the word is a palindrome.
Why it matters. Two-ended comparison is a neat pattern for checking symmetry in words, numbers and sequences. Learners who trace it understand how one structure can drive a full decision procedure.
Key words
- Palindrome
- : A word that reads the same from both ends.
- Pair Matching
- : Comparing one letter from each end of the deque.
- Middle Letter
- : The single letter left over in odd-length palindromes.
- Mismatch Stop
- : Ending the test early when a compared pair differs.
Try it in two minutes
- Write LEVEL on slips and load them in order at the rear.
- Compare and drop one slip from each end, twice.
- Ask what the single middle slip proves.
Try at home. Ask your child to test three words from a storybook and report the pair counts.
What your child will practise
- Deque and Its Operations: Candy Quick Fire (Quick Fire)
- Deque in Action: Palindrome Check: Desert Quick Fire (Quick Fire)
- Deque in Action: Palindrome Check: Ocean Puzzle (Clue Puzzle)
- Enqueue Dequeue and Helpers: Space Quick Fire (Quick Fire)
- Queue and the FIFO Rule: Candy Puzzle (Clue Puzzle)
- Quiz: Deque and Its Operations (8 questions)
- Quiz: Deque in Action: Palindrome Check (8 questions)
- Quiz: Enqueue Dequeue and Helpers (8 questions)
- Quiz: Queue and the FIFO Rule (8 questions)