recategorized by
1,076 views
7 7 votes

Consider the recursive function $\mathsf{mc91}$.

int mc91(int n)
{
    print n
    if (n > 100) {
            return n-10;
    }
    else {
        return mc91(mc91(n+11));
    }
}

Let 

$\mathsf{Out}=\{n : \text{ there is an } x \in \{0, 1, \dots , 100 \} \text{ such that } n \text{ is one of the integers printed by } \mathsf{mc91}(x)\}$

Then which of the following is $\mathsf{Out}$?

  1. $\{ n:  - \infty < n \leq 100 \}$
  2. $\{ n:  0 \leq n \leq 101 \}$
  3. $\{ n:  0 \leq n \leq 110 \}$
  4. $\{ n:  0 \leq n \leq 111 \}$
  5. $\{ n:  0 \leq n < + \infty \}$

1 Answer

Best answer
3 3 votes

For using the values of $x\in \left \{ 0,1,2,3,4,..........,100 \right \}$, the $n$ ranges $\left \{ n:0\leq n\leq 111 \right \}$.

  • Taking $x= 0$ 
#include <stdio.h>
int mc91(int );
int main(void)
{
	int i = mc91(0); 
	printf("%d",i);
	return 0;
}

int mc91(int n)
{
    printf("%d\n",n);
    if (n > 100) 
    {
        return (n-10);
    }
    else 
    {
        return (mc91(mc91(n+11)));
    }
}

Output :

0        // Minimum Value printed for the given range of $x$
11
22
33
44
55
66
77
88
99
110
100
111     // Maximum Value printed for the given range of $x$
101
91
102
92
103
93
104
94
105
95
106
96
107
97
108
98
109
99
110
100
111
101      // Maximum value returned for the given range of $x$
............................................................

........................................................

.......................................................


  • Taking $x= 100$ 
#include <stdio.h>
int mc91(int );

int main(void)
{
	int i = mc91(100);
	printf("%d",i);
	return 0;
}

int mc91(int n)
{
    printf("%d\n",n);
    if (n > 100) 
    {
        return (n-10);
    }
    else 
    {
        return (mc91(mc91(n+11)));
    }
}

Output : 

100
111       // Maximum Value printed for the given range of $x$
101       // Maximum value returned for the given range of $x$
91

selected by
Answer:
Position:
Show:

Related questions

3 3 votes
1 1 answer
1.3k
1.3k views
go_editor asked Dec 29, 2016
1,280 views
Let $G$ be an undirected graph. For a pair $(x, y)$ of distinct vertices of $G$, let $\mathsf{mincut}(x, y)$ be the least number of edges that should be delted from $G$ s...
7 7 votes
1 1 answer
1.9k
1.9k views
go_editor asked Dec 29, 2016
1,914 views
Consider a family $\mathcal{F}$ of subsets of $\{1, 2, \dots , n\}$ such that for any two distinct sets $A$ and $B$ in $\mathcal{F}$ we have: $A \subset B$ or $ B \subset...
3 3 votes
4 4 answers
2.4k
2.4k views
go_editor asked Dec 29, 2016
2,353 views
An undirected graph $G = (V, E)$ is said to be $k$-colourable if there exists a mapping $c: V \rightarrow \{1, 2, \dots k \}$ such that for every edge $\{u, v\} \in E$ we...
6 6 votes
1 1 answer
1.4k
1.4k views
go_editor asked Dec 29, 2016
1,388 views
A computer program computes a function $\: f \: \{0, 1\}^* \times \{0, 1\}^* \rightarrow \{0, 1\}^*$. Suppose $f(a, b)$ ahs length $\mid b \mid ^2$, where $\mid a \mid$ a...