10 Lecture
CS301
Midterm & Final Term Short Notes
Queues
A queue is a data structure that stores and manages a collection of elements in a first-in, first-out (FIFO) manner. Elements are added to the back of the queue and removed from the front, ensuring that the oldest element is always the first to
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- What is a queue data structure? a) A data structure where the last element added is the first one to be removed. b) A data structure where the first element added is the first one to be removed. c) A data structure where the middle element is always removed first. d) None of the above.
Answer: b) A data structure where the first element added is the first one to be removed.
- Which operation adds an element to the queue? a) Dequeue b) Enqueue c) Peek d) None of the above.
Answer: b) Enqueue
- Which operation removes an element from the queue? a) Dequeue b) Enqueue c) Peek d) None of the above.
Answer: a) Dequeue
- Which operation returns the element at the front of the queue without removing it? a) Dequeue b) Enqueue c) Peek d) None of the above.
Answer: c) Peek
- Which data structure is commonly used to implement a queue? a) Array b) Linked list c) Both a and b d) None of the above.
Answer: c) Both a and b
- Which of the following is not a real-world application of queues? a) Waiting lines at banks b) Amusement parks c) Airports d) None of the above.
Answer: d) None of the above.
- What is the time complexity of the enqueue operation in a queue implemented using an array? a) O(1) b) O(n) c) O(log n) d) None of the above.
Answer: a) O(1)
- What is the time complexity of the dequeue operation in a queue implemented using a linked list? a) O(1) b) O(n) c) O(log n) d) None of the above.
Answer: a) O(1)
- Which of the following is a disadvantage of using an array to implement a queue? a) Insertion and deletion are faster than in a linked list. b) The size of the array must be fixed. c) It is more efficient in terms of memory usage. d) None of the above.
Answer: b) The size of the array must be fixed.
- Which of the following is a disadvantage of using a linked list to implement a queue? a) Insertion and deletion are slower than in an array. b) The size of the linked list must be fixed. c) It is less efficient in terms of memory usage. d) None of the above.
Answer: a) Insertion and deletion are slower than in an array.
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is the difference between a queue and a stack? Answer: A queue is a data structure where the first element added is the first one to be removed (FIFO), while a stack is a data structure where the last element added is the first one to be removed (LIFO).
How is a queue implemented using a linked list? Answer: A queue can be implemented using a linked list by adding elements to the tail of the linked list and removing elements from the head of the linked list.
What is a circular queue, and what are its advantages? Answer: A circular queue is a queue where the last element points to the first element, forming a circle. The advantages of a circular queue are that it can utilize space better than a regular queue and allows efficient use of memory when implementing a buffer.
What is a priority queue, and how is it different from a regular queue? Answer: A priority queue is a data structure where each element has a priority assigned to it, and elements with higher priority are dequeued first. A regular queue, on the other hand, follows the first-in, first-out (FIFO) principle.
How can a queue be used to implement a breadth-first search (BFS) algorithm? Answer: A queue can be used to implement BFS by adding the starting node to the queue and then removing it and adding its adjacent nodes to the queue, repeating this process until the desired node is found.
What is a blocking queue, and how does it work? Answer: A blocking queue is a queue that blocks when attempting to dequeue from an empty queue or enqueue to a full queue. The blocking queue will wait until an element is available or space becomes available to perform the desired operation.
What is a double-ended queue (deque), and what are its advantages? Answer: A double-ended queue, also known as a deque, is a data structure that allows insertion and deletion at both ends. The advantages of a deque are that it can be used as both a stack and a queue and provides more flexibility in implementing certain algorithms.
How can a queue be used to implement a producer-consumer problem? Answer: In a producer-consumer problem, a queue can be used as a buffer between the producer and consumer, where the producer adds items to the queue, and the consumer removes them. The queue ensures that the producer and consumer can work independently and at their own pace.
What is a concurrent queue, and how does it work? Answer: A concurrent queue is a queue that can be accessed by multiple threads simultaneously. It works by using thread-safe operations for enqueueing and dequeueing elements to ensure that the queue remains consistent and free from race conditions.
How can a queue be used to implement a call center waiting system? Answer: In a call center waiting system, a queue can be used to hold calls that are waiting to be answered by the next available representative. As representatives become available, calls are dequeued from the queue and assigned to them. The queue ensures that callers are served in the order they called.