Recall & Review
beginner
What does the 'peek' operation do in a queue?
It returns the front element of the queue without removing it, allowing you to see which element will be dequeued next.
Click to reveal answer
beginner
In a queue implemented with an array, which index usually holds the front element?
The front element is usually at the index pointed to by the 'front' variable, which tracks the start of the queue.
Click to reveal answer
beginner
What should the peek function return if the queue is empty?
It should indicate that the queue is empty, often by returning a special value like -1 or NULL, or by printing an error message.
Click to reveal answer
intermediate
Why is peek operation in a queue considered O(1) time complexity?
Because it only accesses the front element directly without traversing or modifying the queue, so it takes constant time.
Click to reveal answer
intermediate
Show the basic steps to peek the front element in a queue implemented with a linked list.
1. Check if the queue is empty (front pointer is NULL).<br>2. If not empty, return the data at the front node.<br>3. Do not remove the node.
Click to reveal answer
What does the peek operation in a queue do?
✗ Incorrect
Peek returns the front element without removing it, so you can see the next element to be dequeued.
If a queue is empty, what should peek return?
✗ Incorrect
Peek should indicate the queue is empty, often by returning -1 or NULL.
In an array-based queue, which variable usually points to the front element?
✗ Incorrect
The 'front' variable points to the index of the front element in the queue.
What is the time complexity of the peek operation in a queue?
✗ Incorrect
Peek accesses the front element directly, so it runs in constant time O(1).
Which of these is NOT a correct step in peeking the front element of a linked list queue?
✗ Incorrect
Peek should not remove the front node; it only returns its data.
Explain how to implement the peek operation in a queue using an array.
Think about the front index and empty condition.
You got /3 concepts.
Describe why peek operation is useful in queue data structures.
Consider when you want to see the next item without changing the queue.
You got /3 concepts.
