Q. In which scenario would a queue be used in a web server?
-
A.
To manage user sessions
-
B.
To handle incoming requests
-
C.
To store user data
-
D.
To cache web pages
Solution
A queue is used to handle incoming requests in a web server, processing them in the order they arrive.
Correct Answer:
B
— To handle incoming requests
Learn More →
Q. In which scenario would a stack be preferred over a queue?
-
A.
When processing tasks in a last-in, first-out manner
-
B.
When tasks need to be processed in the order they arrive
-
C.
When implementing breadth-first search
-
D.
When managing a list of items to be displayed
Solution
A stack is preferred when tasks need to be processed in a last-in, first-out (LIFO) manner, such as in backtracking algorithms.
Correct Answer:
A
— When processing tasks in a last-in, first-out manner
Learn More →
Q. What data structure is used to implement a breadth-first search (BFS)?
-
A.
Stack
-
B.
Queue
-
C.
Array
-
D.
Linked List
Solution
A queue is used to implement breadth-first search (BFS) as it processes nodes in a first-in, first-out (FIFO) manner.
Correct Answer:
B
— Queue
Learn More →
Q. What is the primary advantage of using a stack for expression evaluation?
-
A.
Easy to implement
-
B.
Handles parentheses correctly
-
C.
Faster than queues
-
D.
Uses less memory
Solution
Stacks are advantageous for expression evaluation because they can handle parentheses and operator precedence correctly.
Correct Answer:
B
— Handles parentheses correctly
Learn More →
Q. Which application uses a stack to reverse a string?
-
A.
Queue
-
B.
Stack
-
C.
Graph
-
D.
Tree
Solution
A stack can be used to reverse a string by pushing each character onto the stack and then popping them off.
Correct Answer:
B
— Stack
Learn More →
Q. Which of the following is a typical use case for queues?
-
A.
Undo functionality in applications
-
B.
Task scheduling in operating systems
-
C.
Expression evaluation
-
D.
Backtracking algorithms
Solution
Queues are commonly used in task scheduling in operating systems to manage processes in a first-come, first-served manner.
Correct Answer:
B
— Task scheduling in operating systems
Learn More →
Q. Which of the following operations is typically O(1) for both stacks and queues?
-
A.
Accessing an element
-
B.
Inserting an element
-
C.
Removing an element
-
D.
All of the above
Solution
Removing an element (pop for stacks and dequeue for queues) is typically O(1) for both data structures.
Correct Answer:
C
— Removing an element
Learn More →
Showing 1 to 7 of 7 (1 Pages)