Q. If a stack is used to evaluate an expression in postfix notation, what is the time complexity of the evaluation?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
The time complexity of evaluating an expression in postfix notation using a stack is O(n), where n is the number of tokens in the expression.
Correct Answer:
B
— O(n)
Learn More →
Q. In a circular queue, what condition indicates that the queue is full?
A.
front == rear
B.
rear == (front + 1) % size
C.
front == (rear + 1) % size
D.
rear == front
Show solution
Solution
In a circular queue, the condition rear == (front + 1) % size indicates that the queue is full, as it means there is no space left for new elements.
Correct Answer:
B
— rear == (front + 1) % size
Learn More →
Q. In a queue implemented using two stacks, what is the worst-case time complexity for the dequeue operation?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
In the worst case, the dequeue operation may require transferring all elements from one stack to another, resulting in a time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. When implementing a queue using two stacks, what is the average time complexity for enqueue operations?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
The average time complexity for enqueue operations in a queue implemented using two stacks is O(1), as most operations do not require transferring elements.
Correct Answer:
A
— O(1)
Learn More →
Q. Which data structure would you use to implement a function that checks for balanced parentheses in an expression?
A.
Array
B.
Stack
C.
Queue
D.
Linked List
Show solution
Solution
A stack is the ideal data structure for checking balanced parentheses, as it allows for the last opened parenthesis to be matched with the next closing parenthesis.
Correct Answer:
B
— Stack
Learn More →
Q. Which of the following applications can be efficiently solved using a stack?
A.
Undo functionality in text editors
B.
Breadth-first search in graphs
C.
Finding the shortest path in a weighted graph
D.
Sorting an array
Show solution
Solution
Stacks are commonly used for implementing undo functionality in text editors, as they allow for easy backtracking of actions.
Correct Answer:
A
— Undo functionality in text editors
Learn More →
Q. Which of the following scenarios is best suited for using a stack?
A.
Processing tasks in the order they arrive
B.
Reversing a string
C.
Searching for an element in a list
D.
Maintaining a sorted list
Show solution
Solution
A stack is best suited for reversing a string, as it allows characters to be pushed and popped in reverse order.
Correct Answer:
B
— Reversing a string
Learn More →
Showing 1 to 7 of 7 (1 Pages)