DATA STRUCTURE - RECURSION BASICS Some computer programming languages allows a module or function to call itself This technique is known as recursion
We will take only a superficial look at recursion in this course since it provides a very neat way to represent certain useful numerical functions and data
A function is said to be recursive if it calls itself again and again within its body whereas iterative functions are loop based imperative functions 2
Ming Zhang“ Data Structures and Algorithms “ Commonly used to deal with data which has recursive Non recursive implementation of recursive algorithm
11 3 Example: recursive implementation of the sum between two integers the stack of ARs is used as a temporary “data structure” in which to store the
28 mar 2013 · 4 2 4 Implementing Recursion C++ is used here strictly as a tool to illustrate data structures concepts In particu-
Which data structure is used by the compiler to implement recursion? (a) hash table (b) priority queue (c) queue (d) search tree (e) stack
Recursion is another, typically more favored, solution, which is actually implemented by a stack Memory Management Any modern computer environment uses a
The elegant recursive definitions of data structures such as lists and trees suggest that recur- sion can be used to develop software involving these structures
trative examples of the use of recursion, providing a Java implementation for each • The factorial function (commonly denoted as n) is a classic mathematical
ties, and suggests an efficient implementation method It shows how a re- cursive data structure may be used to represent another data type, for example, a set
Function Calls and Recursive Implementation • Anatomy of a Recursive 2 Data Structures and Algorithms in C++, Fourth Edition The use of activation records on the runtime stack allows recursion to be implemented and handled correctly
A data structure is a way of storing data in a computer so that it can be used efficiently and it will (Abstract Data Type) which is independent of implementation Recursion uses more memory than iteration as its concept is based on stacks