Recent questions tagged recursion

16 16 votes
1 1 answer
2.1k
2.1k views
Consider the following function:What is the cost in time in the worst case as a function of $n$ of mystery $(m, n)?$. Assume $m>0, n 0$.$\theta(\log n)$$\theta(n \log n)...
15 15 votes
2 2 answers
1.9k
1.9k views
What will be the output of following program?Assume that all necessary libraries are included.void myfunction(char *s, char *t) { int i = 0, n = 0; char p; n ...
11 11 votes
2 2 answers
1.5k
1.5k views
Consider a following recursive function $\textsf{f()}.$#include<stdio.h int f(int *a, int n) { if(n <= 0) return 0; if(*a % 2 == 0) return *a + f(a+1, n-1...
1 1 vote
1 answers 1 answer
1.4k
1.4k views
What will be the output of the following program ?answer is 8 but I am getting 5, please explain where I am wrong
0 0 votes
4 answers 4 answers
1.0k
1.0k views
A recursion program without a terminating condition will provide infinite output. True/False?
0 0 votes
0 0 answers
1.2k
1.2k views
What will be the return value of the below function, if it is called a sample(4)? int sample(int x){ if( x == 0 || x ==2) return 1; return (sample( x) * (x ));}
0 0 votes
0 0 answers
585
585 views
Please list out the best free available video playlist for Recursion from programming as an answer here (only one playlist per answer). We'll then select the best playlis...
1 1 vote
2 2 answers
1.6k
1.6k views
#include <stdio.h int fun(int num) { while(num>0) { num=num*fun(num-1); } return num; } int main() { int x=fun(8); printf("%d",x); ret...
1 1 vote
2 answers 2 answers
431
431 views
You can climb up a staircase of $n$ stairs by taking steps of one or two stairs at a time.Formulate a recurrence relation for counting $a_{n},$ the number of distinct way...
5 5 votes
3 3 answers
1.1k
1.1k views
Consider the following pair of mutually recursive functions.int f(int n){ if (n==0) return 1; return f(n-1)+g(n-1); } int g(int n){ if (n==0) return 1; return g(n-1) - f(...
3 3 votes
3 3 answers
1.0k
1.0k views
What will be the number of recursive calls for $\textsf{mystery(5)}$ including the first call?void mystery(int n) { if (n == 0 || n == 1) return 0; mystery(n-2); printf("...
4 4 votes
1 1 answer
1.0k
1.0k views
What will be the output of the following program?#include<stdio.h struct _go{ char b[20]; char *a; struct _go *c; }x = {"GATE", "2023", x+1, "GO", "Classes", x}, *p = x;...
0 0 votes
1 1 answer
1.3k
1.3k views
Consider the following recursive function which is used by dynamic programming. T(n) = { 0; if n<1 1; if n=1 T(n-1)+T(n-2)+1; if n>1}Assume ...
0 0 votes
1 1 answer
824
824 views
Which of the following methods can be used to solve the Knapsack problem?Brute force algorithm RecursionDynamic programmingBrute force, Recursion, and Dynamic Programming
0 0 votes
1 1 answer
646
646 views
Consider the following $\text{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 $\text{f}(1)$ is :$5$$...
0 0 votes
0 0 answers
547
547 views
Division in merge sort algorithm is based on which approach:ParallelRandomInteractiveRecursive
2 2 votes
3 answers 3 answers
1.9k
1.9k views
#include <stdio.h>int f(int n){ static int r = 0; if (n <= 0) return 1; r=n; return f(n-1) + r;}int main() { printf("output is %d", f(5)); return 0;}Ou...
4 4 votes
1 1 answer
1.3k
1.3k views
#include<stdio.h int test(int *a, int *b) { int c = *a-*b; if (c<0) return 0; else return (1 + test(&c, b)); } void main() { int x = 15; int y = 4; int a = test(&x,&y); p...