Q. How can stacks be used to check for balanced parentheses in an expression?
-
A.
By counting the number of parentheses
-
B.
By using a queue to store parentheses
-
C.
By pushing opening parentheses onto the stack and popping for closing ones
-
D.
By sorting the parentheses
Solution
Stacks can be used to check for balanced parentheses by pushing opening ones and popping when a closing one is encountered.
Correct Answer:
C
— By pushing opening parentheses onto the stack and popping for closing ones
Learn More →
Q. In which scenario would a queue be more appropriate than a stack?
-
A.
When you need to access the last element added
-
B.
When you need to process elements in the order they were added
-
C.
When you need to sort elements
-
D.
When you need to implement recursion
Solution
Queues follow First In First Out (FIFO) principle, making them suitable for processing elements in the order they were added.
Correct Answer:
B
— When you need to process elements in the order they were added
Learn More →
Q. What is the main advantage of using a queue in numerical applications?
-
A.
It allows random access to elements
-
B.
It processes elements in a specific order
-
C.
It uses less memory than a stack
-
D.
It can store elements of different types
Solution
Queues process elements in the order they were added, which is essential for many applications like scheduling.
Correct Answer:
B
— It processes elements in a specific order
Learn More →
Q. What is the primary use of a stack in numerical applications?
-
A.
To store data in a sorted manner
-
B.
To reverse a sequence of numbers
-
C.
To perform breadth-first search
-
D.
To implement a priority queue
Solution
Stacks are used to reverse sequences because they follow Last In First Out (LIFO) principle.
Correct Answer:
B
— To reverse a sequence of numbers
Learn More →
Q. What is the time complexity of dequeuing an element from a queue implemented using a linked list?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
Dequeuing from a queue implemented with a linked list is O(1) as it involves removing the head node.
Correct Answer:
A
— O(1)
Learn More →
Q. Which data structure would you use to implement a function that needs to backtrack?
-
A.
Array
-
B.
Stack
-
C.
Queue
-
D.
Linked List
Solution
A stack is ideal for backtracking as it allows you to return to the previous state easily.
Correct Answer:
B
— Stack
Learn More →
Q. Which of the following is a common application of stacks in numerical computations?
-
A.
Evaluating postfix expressions
-
B.
Finding the shortest path in a graph
-
C.
Sorting an array
-
D.
Searching for an element in a list
Solution
Stacks are commonly used to evaluate postfix expressions due to their LIFO nature.
Correct Answer:
A
— Evaluating postfix expressions
Learn More →
Showing 1 to 7 of 7 (1 Pages)