Question
What is the primary advantage of using a stack in
recursive algorithms?Solution
Stacks are crucial in recursive algorithms because they support backtracking by maintaining a history of function calls. Every recursive call is pushed onto the stack, and when a base condition is met, the stack unwinds (pops) the calls in reverse order. This property is integral for problems like solving mazes, tree traversal (DFS), or evaluating expressions. The Last-In-First-Out (LIFO) nature of stacks ensures that the most recent state is resumed first, making them perfect for backtracking scenarios. Why Other Options Are Incorrect · Option 1 (Efficient sorting): Stacks are not inherently used for sorting. Algorithms like Quick Sort and Merge Sort do not directly depend on stacks for sorting efficiency. · Option 2 (Memory allocation for variables): This is managed by the program's runtime stack, not the data structure itself. · Option 4 (Managing concurrent processes): This is more relevant to queues or process schedulers. · Option 5 (Sorting data): Stacks are used in algorithms like stack-based parsing but are not designed for general sorting.
What is the Probability of getting a sum of ‘9’ on rolling a dice twice?
22 rotten bananas are accidentally mixed with 136 good ones. It is not possible to just look at a banana and tell whether or not it is rotten. One banan...
A box contains ‘x + 1’ green balls, ‘x + 4’ blue balls and ‘x – 2’ yellow balls. If the probability of drawing a yellow ball is 1/30 less ...
- There are three people A, B and C who are competing in a 100-meter race. If A is 50% more likely to win as B and B is twice as likely to win as C then what...
Two dice are rolled. What is probability that sum is at least 10?
- ‘A’ and ‘B’ play a game where a coin is tossed 2 times. ‘A’ wins if both tosses give the same result. Find the probability that ‘A’ wins.
A box contains 13 black and 13 white balls. The probability of drawing two balls of the same colour is?
- 5 boys and 3 girls are to be seated on chairs arranged in a row. If the arrangement is made at random, find the probability that no two girls will be seate...
A box contains 12 black, 8 red and 10 green marbles. Two marbles are randomly selected from the box, what is the probability that a black and a green ma...
The probability of selecting a rotten apple randomly from a heap of 250 apples is 0.20. What is the number of rotten apples in the heap?
...