Which data structure is mainly used for implementing the recursive algorithm?
2023
Which data structure is mainly used for implementing the recursive algorithm?
- A.
Queue
- B.
Stack
- C.
Binary tree
- D.
More than one of the above
- E.
None of the above
Attempted by 929 students.
Show answer & explanation
Correct answer: B
Recursive algorithms rely on the call stack to manage function calls. Each time a function calls itself, the current state (like variables and return address) is pushed onto the stack. When the recursion ends, the state is popped off in reverse order. This LIFO (Last In, First Out) behavior is exactly what a stack provides. Therefore, the stack is the primary data structure used to implement recursion.
हिन्दी उत्तर: पुनरावर्ती एल्गोरिथ्म फ़ंक्शन कॉल को प्रबंधित करने के लिए स्टैक का उपयोग करता है। प्रत्येक बार जब एक फ़ंक्शन खुद को कॉल करता है, तो वर्तमान अवस्था (जैसे चर और रिटर्न एड्रेस) स्टैक पर डाली जाती है। जब रिकर्शन समाप्त होता है, तो अवस्था विपरीत क्रम में पॉप की जाती है। यह LIFO (लास्ट इन, फर्स्ट आउट) व्यवहार ठीक वही है जो स्टैक प्रदान करता है। इसलिए, स्टैक रिकर्शन को लागू करने के लिए प्राथमिक डेटा संरचना है।