Q. What is the primary difference between a stack and a queue?
-
A.
Stack is LIFO, Queue is FIFO
-
B.
Stack is FIFO, Queue is LIFO
-
C.
Both are LIFO
-
D.
Both are FIFO
Solution
A stack follows Last In First Out (LIFO) order, while a queue follows First In First Out (FIFO) order.
Correct Answer:
A
— Stack is LIFO, Queue is FIFO
Learn More →
Q. What is the worst-case time complexity for enqueue and dequeue operations in a queue implemented using a linked list?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Both enqueue and dequeue operations can be performed in constant time, O(1), when using a linked list.
Correct Answer:
A
— O(1)
Learn More →
Q. Which data structure would you use to implement a function that checks for balanced parentheses?
-
A.
Array
-
B.
Stack
-
C.
Queue
-
D.
Linked List
Solution
A stack is ideal for checking balanced parentheses because it allows you to match opening and closing symbols in the correct order.
Correct Answer:
B
— Stack
Learn More →
Q. Which of the following is a common application of queues?
-
A.
Function call management
-
B.
Backtracking algorithms
-
C.
Breadth-first search in graphs
-
D.
Sorting algorithms
Solution
Queues are commonly used in breadth-first search (BFS) algorithms for traversing graphs.
Correct Answer:
C
— Breadth-first search in graphs
Learn More →
Q. Which of the following is a valid application of a stack?
-
A.
Undo functionality in text editors
-
B.
Managing tasks in a queue
-
C.
Storing data in a database
-
D.
Sorting elements in an array
Solution
Stacks are used for undo functionality in text editors because they allow the last action to be reversed easily.
Correct Answer:
A
— Undo functionality in text editors
Learn More →
Showing 1 to 5 of 5 (1 Pages)