- What might you say about this loop test? while(x != 10 || x < 20)
- What might you say about this loop?
for(int i = 1; i != 10 && i != 20; ++i)
What if we change the initial value to 15? How about 20?
- What does this function compute?
int f(int a)
{
if(a == 0) return 0;
else if(a % 2 == 1) return 1 + f(a-1);
else return f(a/2);
}
- Does the following recursion terminate? For what parameter value(s)?
int g(int a)
{
if(a > 0) return g(a/2 - 3*a/2);
else if(a < 0) return g(a+1);
else return 0;
}
- Does the following recursion terminate? For what parameter value(s)?
int foo(int a)
{
if(a == 1024) return 1;
else if(a % 2 == 0) return foo(a + 1);
else return foo(a - 2);
}