You are on page 1of 5

ASSIGNMENT/ASSESSMENT COVER SHEET

Student Name: Imran Hakeem

FIRST NAME FAMILY / LAST NAME

Registration Number: BSCS-023R13-191

Course Code Course Title

Theory of Autamata

Department (Computer Science / Information Technology)

Computer Science

Class & Semester BSCS 7th

02 06-05-
20
Assessment Item Title: Due Date/Time:

Tutorial Group (If applicable): Word Count (If applicable):


Lecturer/Tutor Name: Zia Ur Rehman

Extension Granted: Yes No Granted By:

I declare that this assessment item is my own work unless otherwise acknowledged and is
in accordance with the University’s academic integrity policy.
I certify that this assessment item has not been submitted previously for academic credit in
this or any other course. I certify that I have not given a copy or have shown a copy of this
assessment item to another student enrolled in the course.
I acknowledge that the assessor of this assignment may, for the purpose of assessing this
assignment:
 Reproduce this assessment item and provide a copy to another member of the Faculty; and/or
 Communicate a copy of this assessment item to a plagiarism checking service (which may then
retain a copy of the item on its database for the purpose of future plagiarism checking).
 Submit the assessment item to other forms of plagiarism checking.

I certify that any electronic version of this assessment item that I have submitted or will
submit is identical to this paper version.

Signature: Imran Hakeem Date: 19-08-20

Using ten examples explain recursive definition?


In computer programming evaluating a function or executing a procedure is often accomplished
by using a recursion. A recursive process is one in which one or more initial stages of the process
are specified, and the nth stage of the process is defined in terms of previous stages, using some
fixed procedure. In a computer program this is usually accomplished by using a subroutine, such
as a “For” loop, in which the same procedure is repeated a specified number of times; that is, the
procedure calls itself.

A recursive function is a function that calls itself during its execution. This enables the function
to repeat itself several times, outputting the result and the end of each iteration. Below is an
example of a recursive function.
function Count (integer N)
    if (N <= 0) return "Must be a Positive Integer";
    if (N > 9) return "Counting Completed";
    else return Count (N+1);
end function

The function Count() above uses recursion to count from any number between 1 and 9, to the
number 10. For example, Count(1) would return 2,3,4,5,6,7,8,9,10. Count(7) would return
8,9,10. The result could be used as a roundabout way to subtract the number from 10.

EXAMPLE The function f (n) = 2n , where n is a natural number, can be defined recursively as
follows:

Initial Condition: f (0) = 1,

Recursion: f (n + 1) = 2 · f (n), for n ≥ 0.

For any particular n, this procedure could be programmed by first initializing F = 1, and then
executing a loop “For i = 1 to n, 2 ∗ F = F.”

Here is how the definition gives us the first few powers of 2: 21 = 20+1 = 20 · 2 = 2

22 = 21+1 = 21 · 2 = 2 · 2 = 4

23 = 22+1 = 22 · 2 = 4 · 2 = 8

EXAMPLE The factorial function f (n) = n! is defined recursively as follows:

Initial Condition: f (0) = 1

Recursion: f (n + 1) = (n + 1)f (n)

Discussion
Starting with the initial condition, f (0) = 1, the recurrence relation, f (n + 1) = (n + 1)f (n),
tells us how to build new values of f from old values. For example,

1! = f (1) = 1 · f (0) = 1,

2! = f (2) = 2 · f (1) = 2,

3! = f (3) = 3 · f (2) = 6, etc.

When a function f (n), such as the ones in the previous examples, is defined recursively, the
equation giving f (n + 1) in terms of previous values off is called a recurrence relation.

EXAMPLE: Suppose the set S is defined recursively as follows:

1. 1 ∈ S,

2. If x ∈ S, then 2 · x ∈ S.

Prove that S = {2n|n ≥ 0}.

EXAMPLE: Suppose the set S is defined recursively as follows:

1. 0, 1 ∈ S,

2. If x, y ∈ S, then x · y ∈ S.

What are the elements of S? Prove that your answer is correct.

EXAMPLE: Suppose f : N → R is define recursively as follows:

1. f (0) = 0,

2. f (n + 1) = f (n) + (2n + 1), for n ≥ 0.

Prove that f (n) = n2 for all n ≥ 0.

EXAMPLE Prove that if f is injective, then f n is injective for n ≥ 1.

Proof. Assume f is injective.

1. Basis Step: f 1 = f is injective by our assumption.


2. Inductive Step: Let n ≥ 1 and assume f n is injective. Prove fn+1 is injective. Recall that to
prove f n+1 is injective we must show ∀a, b ∈ A[(fn+1(a) =
n+1
f (b)) → (a = b)]

Assume a, b ∈ A and f n+1 (a) = f n+1 (b).

fn+1(a) = f n+1 (b) (recurrence relation)


(f ◦ fn)(a) = (f ◦ f n )(b) (recurrence relation)

f (fn(a)) = f (f n (b)) (by the definition of composition)


fn(a) = f n (b) (since f is injective)
a =b (by the induction hypothesis, f n is injective)

Therefore, by the first principle of mathematical induction fn is injective for all positive
integers.

EXAMPLE Given a real number a = 0, define an for all natural numbers, n, inductively by
ƒ

1. Initial Condition: a0 = 1
2. Recursion: a(n+1) = an

You might also like