Understanding Recursive Algorithms: Numbers, Integers, Strings, and Ackerman's Function, Slides of Data Structures and Algorithms

The concept of recursive algorithms using examples of natural numbers, even integers, strings, and ackerman's function. It also covers the six commandments for writing recursive algorithms and the divide and conquer meta-technique. The document also includes a warning about the size of the results produced by ackerman's function.

Typology: Slides

2012/2013

Uploaded on 04/30/2013

patel
patel 🇮🇳

3.8

(15)

80 documents

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Recursive and merge sort
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download Understanding Recursive Algorithms: Numbers, Integers, Strings, and Ackerman's Function and more Slides Data Structures and Algorithms in PDF only on Docsity!

Recursive and merge sort

Example 1. The Set of Natural Numbers

Basis Clause: 0 εN

Inductive Clause: For any element x in N , x + 1 is in N. Extremal Clause: Nothing is in unless it is obtained from the Basis and Inductive Clauses. The basis for this set N is { 0 }. The x + 1 in the Inductive Clause is the parent of x , and x is the child of x + 1. Following this definition, the set of natural numbers N can be obtained as follows: First by (1), 0 is put into N. Then by (2), since 0 is in N , 0 + 1 (= 1) is in N. 0 is the parent of 1 , and 1 is the child of 0. Then by (2) again, 1 + 1 (= 2) is in N. 1 is the parent of 2 , and 2 is the child of 1. Proceeding in this manner all the natural numbers are put into N. Note that if we don't have (3), 0.5, 1.5, 2.5, ... can be included in N , which is not what we want as the set of natural numbers.

Example 3. The Set of Strings over the alphabet {a,b} excepting empty string This is the set of strings consisting of a 's and b 's such as abbab , bbabaa , etc.

Basis Clause: aεS , and baεS. Inductive Clause: For any element x in S , ax , and bx εS. Here ax means the concatenation of a with x. Extremal Clause: Nothing is in S unless it is obtained from the Basis and Inductive Clauses

Six Commandments for Writing Recursive Algorithms

**1. You must be able to define the problem.

  1. You must understand the types of data objects involved in the solution of the problem.
  2. You must understand the trivial condition necessary for terminating recursion.
  3. You must understand non-trivial condition for reducing a problem towards the trivial case.**

Try it out on some inputs. Warning: Try very small inputs first, because the result gets very big very fast.

This function isn't very useful, except as a function that grows faster than probably any one you've seen before. (In technical jargon, the function is not primitive recursive.)

Here's the definition of a strange numerical function on natural numbers, called Ackerman's Function:

A(m,n) = 0, if n=

= 2n, if n>0 and m= = 2, if n=1 and m> = A(m-1,A(m,n-1)), if n>1 and m>

Inventor of merge sort

  • John von Neuman is

generally considered

to be the inventor of

the "stored program"

machines - the class to

which most of today's

computers belong.

  • 2013/4/