Q. In a stack, what will be the output of popping an element from an empty stack?
-
A.
Null
-
B.
Error
-
C.
0
-
D.
Undefined
Solution
Popping an element from an empty stack typically results in an error, as there are no elements to remove.
Correct Answer:
B
— Error
Learn More →
Q. What happens when you try to enqueue an element into a full queue?
-
A.
The element is added
-
B.
The queue overflows
-
C.
An error is raised
-
D.
The queue is resized
Solution
When trying to enqueue an element into a full queue, an error is typically raised, indicating that the queue cannot accept more elements.
Correct Answer:
C
— An error is raised
Learn More →
Q. What is the main advantage of using a deque over a regular queue?
-
A.
Faster access time
-
B.
Ability to add/remove from both ends
-
C.
Less memory usage
-
D.
Easier implementation
Solution
A deque (double-ended queue) allows for adding and removing elements from both ends, providing more flexibility than a regular queue.
Correct Answer:
B
— Ability to add/remove from both ends
Learn More →
Q. What is the primary use of a stack in algorithm design?
-
A.
To store data in a sorted manner
-
B.
To manage function calls
-
C.
To implement breadth-first search
-
D.
To maintain a queue of tasks
Solution
Stacks are primarily used to manage function calls in programming, allowing for backtracking and maintaining the order of execution.
Correct Answer:
B
— To manage function calls
Learn More →
Q. What is the time complexity of accessing an element in a queue?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Accessing an element in a queue typically requires O(n) time because you may need to traverse the queue to find the element.
Correct Answer:
B
— O(n)
Learn More →
Q. Which data structure would you use to implement a call stack?
-
A.
Queue
-
B.
Array
-
C.
Linked List
-
D.
Stack
Solution
A call stack is implemented using a stack data structure, which allows for the last function called to be the first one to return (LIFO).
Correct Answer:
D
— Stack
Learn More →
Q. Which of the following is a characteristic of a circular queue?
-
A.
It can grow dynamically
-
B.
It uses a fixed size array
-
C.
It allows for efficient memory usage
-
D.
Both B and C
Solution
A circular queue uses a fixed size array and allows for efficient memory usage by reusing empty spaces created by dequeued elements.
Correct Answer:
D
— Both B and C
Learn More →
Showing 1 to 7 of 7 (1 Pages)