Recursion
Visit: tshahab.blogspot.com
Recursion
 Basic problem solving technique is to divide a
problem into smaller subproblems
 These subproblems may also be divided into
smaller subproblems
 When the subproblems are small enough to
solve directly the process stops
 A recursive algorithm is a problem solution that
has been expressed in terms of two or more
easier to solve subproblems
What is recursion?
 A procedure that is defined in terms of
itself
 In a computer language a function that
calls itself
Recursion
Recursion
A recursive definition is one which is defined in terms of itself.
Examples:
• A phrase is a "palindrome" if the 1st and last letters are the same,
and what's inside is itself a palindrome (or empty or a single letter)
• Rotor
• Rotator
• 12344321
N =
1 is a natural number
if n is a natural number, then n+1 is a natural number
• The definition of the natural numbers:
Recursion
Recursion
1. Recursive data structure: A data structure that is partially
composed of smaller or simpler instances of the same data
structure. For instance, a tree is composed of smaller trees
(subtrees) and leaf nodes, and a list may have other lists as
elements.
a data structure may contain a pointer to a variable of the same
type:
struct Node {
int data;
Node *next;
};
2. Recursive procedure: a procedure that invokes itself
3. Recursive definitions: if A and B are postfix expressions, then A
B + is a postfix expression.
Recursion in Computer Science
Recursion in Computer Science
Recursive Data Structures
Recursive Data Structures
Linked lists and trees are recursive data structures:
struct Node {
int data;
Node *next;
};
struct TreeNode {
int data;
TreeNode *left;
TreeNode * right;
};
Recursive data structures suggest recursive algorithms.

Lec-32 What is recursion? A mathematical look

  • 1.
  • 2.
    Recursion  Basic problemsolving technique is to divide a problem into smaller subproblems  These subproblems may also be divided into smaller subproblems  When the subproblems are small enough to solve directly the process stops  A recursive algorithm is a problem solution that has been expressed in terms of two or more easier to solve subproblems
  • 3.
    What is recursion? A procedure that is defined in terms of itself  In a computer language a function that calls itself
  • 4.
    Recursion Recursion A recursive definitionis one which is defined in terms of itself. Examples: • A phrase is a "palindrome" if the 1st and last letters are the same, and what's inside is itself a palindrome (or empty or a single letter) • Rotor • Rotator • 12344321
  • 5.
    N = 1 isa natural number if n is a natural number, then n+1 is a natural number • The definition of the natural numbers: Recursion Recursion
  • 6.
    1. Recursive datastructure: A data structure that is partially composed of smaller or simpler instances of the same data structure. For instance, a tree is composed of smaller trees (subtrees) and leaf nodes, and a list may have other lists as elements. a data structure may contain a pointer to a variable of the same type: struct Node { int data; Node *next; }; 2. Recursive procedure: a procedure that invokes itself 3. Recursive definitions: if A and B are postfix expressions, then A B + is a postfix expression. Recursion in Computer Science Recursion in Computer Science
  • 7.
    Recursive Data Structures RecursiveData Structures Linked lists and trees are recursive data structures: struct Node { int data; Node *next; }; struct TreeNode { int data; TreeNode *left; TreeNode * right; }; Recursive data structures suggest recursive algorithms.

Editor's Notes

  • #1 Visit: tshahab.blogspot.com
  • #4 Visit: tshahab.blogspot.com