Which data structure is used for implementing recursion?
Explanation:
Recursion involves a function calling itself directly or indirectly.
Each time a function is called, a new activation record is created. This record contains information about the function's parameters, local variables, and return address.
To keep track of these activation records and ensure proper execution, a LIFO (Last In, First Out) data structure is needed.
Stack is the perfect LIFO data structure for this purpose.
When a function is called, its activation record is pushed onto the stack.
When the function returns, its activation record is popped off the stack.
This process allows the system to manage multiple function calls efficiently and correctly.