Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Stack is useful for implementinga)Recursionb)... Start Learning for Free
Stack is useful for implementing
  • a)
    Recursion
  • b)
    Breadth first search
  • c)
    Depth first search
  • d)
    Both (a) and (c)
Correct answer is option 'D'. Can you explain this answer?
Verified Answer
Stack is useful for implementinga)Recursionb)Breadth first searchc)Dep...
Stack is used for implementing recursion and depth first search.
For breadth first search, queue is used.
View all questions of this test
Most Upvoted Answer
Stack is useful for implementinga)Recursionb)Breadth first searchc)Dep...
Yes, the correct answer is option 'D' – Both (a) and (c).

Let's explain why a stack is useful for implementing recursion and depth-first search (DFS):

a) Recursion: Recursion is a programming technique where a function calls itself to solve a problem by breaking it down into smaller subproblems. When a function calls itself, the current state of the function is stored in memory, including the local variables, return address, and other necessary information. This information is stored in a data structure called the call stack.

Each time a function is called recursively, a new frame is added to the top of the call stack, containing the information for that specific invocation. When the function completes its execution, the frame is removed from the stack, and the control returns to the previous invocation.

The call stack follows a Last-In-First-Out (LIFO) order, meaning that the most recent function call is completed first before returning to the previous ones. This LIFO behavior matches the behavior of a stack data structure, making a stack an ideal choice for implementing recursion.

b) Depth First Search (DFS): DFS is a graph traversal algorithm that explores vertices as far as possible along each branch before backtracking. It can be implemented using a stack to keep track of the vertices being visited.

In the iterative implementation of DFS, a stack is used to store the vertices. The algorithm starts with an initial vertex, pushes it onto the stack, and marks it as visited. Then, it repeatedly pops a vertex from the stack, visits its adjacent unvisited vertices, and pushes them onto the stack. This process continues until the stack becomes empty.

By using a stack, the algorithm ensures that the most recently visited vertex is explored first, following the LIFO order.

Therefore, option 'D' – Both (a) and (c) – is the correct answer, as a stack is useful for implementing recursion and depth-first search (DFS) algorithms.
Explore Courses for Computer Science Engineering (CSE) exam
Question Description
Stack is useful for implementinga)Recursionb)Breadth first searchc)Depth first searchd)Both (a) and (c)Correct answer is option 'D'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Stack is useful for implementinga)Recursionb)Breadth first searchc)Depth first searchd)Both (a) and (c)Correct answer is option 'D'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Stack is useful for implementinga)Recursionb)Breadth first searchc)Depth first searchd)Both (a) and (c)Correct answer is option 'D'. Can you explain this answer?.
Solutions for Stack is useful for implementinga)Recursionb)Breadth first searchc)Depth first searchd)Both (a) and (c)Correct answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Stack is useful for implementinga)Recursionb)Breadth first searchc)Depth first searchd)Both (a) and (c)Correct answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Stack is useful for implementinga)Recursionb)Breadth first searchc)Depth first searchd)Both (a) and (c)Correct answer is option 'D'. Can you explain this answer?, a detailed solution for Stack is useful for implementinga)Recursionb)Breadth first searchc)Depth first searchd)Both (a) and (c)Correct answer is option 'D'. Can you explain this answer? has been provided alongside types of Stack is useful for implementinga)Recursionb)Breadth first searchc)Depth first searchd)Both (a) and (c)Correct answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Stack is useful for implementinga)Recursionb)Breadth first searchc)Depth first searchd)Both (a) and (c)Correct answer is option 'D'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev