In the context of recursion, what is the purpose of the "stack" data structure?

2025

In the context of recursion, what is the purpose of the "stack" data structure?

  1. A.

    To store variables and function calls for backtracking

  2. B.

    To store only variables

  3. C.

    To store only function calls

  4. D.

    To store loop counters

Attempted by 472 students.

Show answer & explanation

Correct answer: A

In recursion, the "stack" data structure is essential for managing the execution context of function calls. When a function calls itself, the system creates a new "stack frame" that stores the function's local variables, parameters, and the return address. This allows the program to pause the current function, execute the nested call, and then resume exactly where it left off once the nested call completes. This mechanism is known as backtracking.

हिन्दी उत्तर: रिकर्शन में, "स्टैक" डेटा संरचना फंक्शन कॉल के निष्पादन संदर्भ को प्रबंधित करने के लिए आवश्यक है। जब कोई फंक्शन स्वयं को कॉल करता है, तो सिस्टम एक नया "स्टैक फ्रेम" बनाता है जो फंक्शन के स्थानीय चरों, पैरामीटरों और रिटर्न पते को स्टोर करता है। यह प्रोग्राम को वर्तमान फंक्शन को रोकने, नेस्टेड कॉल को निष्पादित करने और नेस्टेड कॉल पूरा होने के बाद बिल्कुल वहां से फिर से शुरू करने की अनुमति देता है। इस तंत्र को बैकट्रैकिंग कहा जाता है।

Explore the full course: Bpsc