You are on page 1of 13

ASSIGNMENT NO : 04

Submitted to :
Ma’am Shaista Rashid
Submitted by :
AZKA REHMAN 2657-FBAS/BSSE/F14
MARIUM KALSOOM 3400-FBAS/BSSE/F17
ANEESA NOSHEEN 3536-FBAS-BSCS-F17
SAMRA SEERAT 2753-FBAS-BSSE-F15
Submitted on :
29th april, 2021
Question#01:

1. Recursion is the phenomenon of a function calling itself.

2. Name and describe the two parts of a recursive definition of a


function.

The two parts of a recursive definition are:


● Anchor or Base case
● Inductive or Recursive case

I. Anchor or Base case:


The case for which the solution can be stated non-recursively. Here, a
solid solution is formed in which the problem is simple enough
to solve directly.
For example:
0! =1
II. Inductive or Recursive case:
The case for which the solution is expressed in terms of a smaller
version of itself. In other words, the problem space is made
smaller and smaller. The smaller problem is then sent to the
calling function.
For example:
n! = (n-1)! * n ( if n>0 )

3. A non-recursive function for computing some value may execute


more rapidly than a recursive function that computes the same
value ( true / false ) ?
Yes, it’s true.
A non-recursive function for computing some value may execute more rapidly
than a recursive function that computes the same value

4. For the given recursive function find f(5).

SOLUTION:

MEMORY DIAGRAM:
5. For the function in question 4 find f(0).

SOLUTION:

MEMORY DIAGRAM:
6. For the function in question 4, suppose + is changed to * in the inductive
case. Find f(5).

SOLUTION:

MEMORY DIAGRAM:
7. For the function in question 4, what happens with the function
call f(-1)?

SOLUTION:

Question#02:
Assume ASCII representation of characters and the following function f().
Tell what output will be produced by the function call.

1) F(‘C’)

SOLUTION:

MEMORY DIAGRAM:
2) F(‘G’)

SOLUTION:

MEMORY DIAGRAM:
3) F(‘3’)

SOLUTION:

MEMORY DIAGRAM:
4) F(‘C’) if ch-1 is replaced by ch+1

SOLUTION:

MEMORY DIAGRAM:
5) F(‘C’) if the output and recursive call to f() are interchanged.

SOLUTION:

MEMORY DIAGRAM:
6) F(‘C’) if a copy of the output statement is inserted before
recursive call to f().

SOLUTION:
MEMORY DIAGRAM:

You might also like