MATH 140 Recursive

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/11

flashcard set

Earn XP

Description and Tags

Week 6 Topics for MATH 140

Last updated 7:04 AM on 4/14/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

12 Terms

1
New cards

Any problem that can be solved recursively can also be solved iteravely, with a loop
True or False

True

2
New cards

Without a base case, a recursive method will call itself only once and stop
True or False

False

3
New cards

A recursive method can only have one base case
True or False

False

4
New cards

Recursion is never absolutely required to solve a problem
True or False

True

5
New cards

A method that calls itself is a _________ method

recursive
redundant
binary
derived

recursive

6
New cards

The _________ is at least one case in which a problem can be solved without recursion

recursive case
base case
termination point
point of absolution

base case

7
New cards

In the following cose that uses recursion to find the factorial of a number, what is the base case?

private static int factorial (int n)
{
	if (n == 0)
	     return 1;
	else
	     return n * factorial (n - 1);
}
factorial (int n)
if (n == 0)
    return 1;
else
     return n * factorial (n - 1);

Cannot tell from this code

if (n == 0)
    return 1;

8
New cards

In the following code that uses recursion to find the greatest common divisor of a number, what is the base case?

public static int gcd (int x, int y)
{
	if (x % y == 0)
		return y;
	else
		return gcd(y, x % y);
}
gcd(int x, int y)
if (x % y == 0)
		return y;
else
		return gcd(y, x % y);

Cannot tell from this code

if (x % y == 0)
		return y;

9
New cards

Criticize the following recursive function:

public static String exR2(int n)

{

	String s = exR2(n-3) + n + exR2(n-2) + n;

	if (n <= 0) 
		return "";

	return s;

}

This code doesn't have any problems.
In line String s = exR2(n-3) + n + exR2(n-2) + n; we can't call the same method twice.
return ""; is error
Base case should be the first statement.

Base case should be the first statement.

10
New cards

Find the error in the following program:

public class FindTheError
{
   public static void main(String[] args)
   {
      myMethod(0);
   }
   public static void myMethod(int num)
   {
      System.out.print(num + " ");
      myMethod(num + 1);
   }
}


There is no error in this code.
There is no base case for myMethod.
myMethod can't be a static method.
myMethod should return an integer.

There is no base case for myMethod.

11
New cards

Consider the following code;
What is the value of mystery(2,14)?

public static int mystery(int a, int b)
    {
        if (b == 0)  return 0;
        if (b%2 == 0) return mystery(a+a,b/2);
        return mystery(a+a,b/2)+a;
    }

7
16
12
28

28

12
New cards

What operation does the following code implement?

public static int mystery(int a, int b)
{
        if (b == 0)  return 0;
        if (b%2 == 0) return mystery(a+a,b/2);
        return mystery(a+a,b/2)+a;
}

Addition
Subtraction
Multiplication
Division

Multiplication