What will be the output of the following C program?
void count (int n) {
static int d=1;
printf ("%d",n);
printf ("%d",d);
d++;
if (n>1) count (n-1);
printf ("%d",d);
}
void main(){
count (3);
}
A language with string manipulation facilities uses the following operations
head(s): first character of a string
tail(s): all but exclude the first character of a string
concat(s1, s2): s1s2
For the string "acbc" what will be the output of
concat(head(s), head(tail(tail(s))))
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Consider the following C function:
int f(int n)
{
static int i = 1;
if(n >= 5) return n;
n = n+i;
i++;
return f(n);
}
The value returned by f(1) is
double foo(int n)
{
int i;
double sum;
if(n == 0)
{
return 1.0;
}
else
{
sum = 0.0;
for(i = 0; i < n; i++)
{
sum += foo(i);
}
return sum;
}
}
The space complexity of the above code is?
double foo(int n)
{
int i;
double sum;
if(n == 0)
{return 1.0;
}
else
{
sum = 0.0;
for(i = 0; i < n; i++)
{
sum += foo(i);
}
return sum;
}
}
Suppose we modify the above function foo() and stores the value of foo(i) 0 <= i < n, as and when they are computed. With this modification the time complexity for function foo() is significantly reduced. The space complexity of the modified function would be:
int f(int n)
{
static int r = 0;
if (n <= 0) return1;
if (n > 3)
{ r = n;
return f(n-2) + 2;
}
return f(n-1) + r;
}
What is the value of f(5)?
The function f is defined as follows:
int f (int n) {
if (n <= 1) return 1;
else if (n % 2 == 0) return f(n/2);
else return f(3n - 1);
}
Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
i. The function f terminates for finitely many different values of n ≥ 1.
ii. The function f terminates for infinitely many different values of n ≥ 1.
iii. The function f does not terminate for finitely many different values of n ≥ 1.
iv. The function f does not terminate for infinitely many different values of n ≥ 1.
Which one of the following options is true of the above?
A. i and iii
B. i and iv
C. ii and iii
D. ii and iv
Consider the following two functions.
void fun1(int n) {
if(n == 0) return;
printf("%d", n);
fun2(n - 2);
printf("%d", n);
}
void fun2(int n) {
if(n == 0) return;
printf("%d", n);
fun1(++n);
printf("%d", n);
}
The output printed when fun1 (5) is called is
Consider the following computation rules. Parallel-outermost rule: Replace all the outermost occurrences of F (i.e., all occurrences of F which do not occur as arguments of other F's) simultaneously. Parallel - innermost rule: Replace all the innermost occurrences of F (i.e.,all occurrences of F with all arguments free of F's) simultaneously. Now consider the evaluations of the recursive program over the integers.
F(x, y) <== if x = 0 then 0 else
[ F(x + 1, F(x, y)) * F(x - 1, F(x, y))]
where the multiplication functions * is extended as follows:
0 * w & w * 0 are 0
a * w & w * a are w (for any non-zero integer a)
w * w is w
We say that F(x, y) = w when the evaluation of F(x, y) does not terminate. Computing F(1, 0) using the parallel - innermost and parallel - outermost rule yields
Consider the class of recursive and iterative programs. Which of the following is false?