stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
Recursion Flashcards | StudBud
Explore
/
Recursion
Recursion
8 terms
·
StudBud Administration
·
82 plays
Questions about the Basic structure of recursion in AP Computer Science A
Flashcards
8 cards
F
Practice quiz
P
Host live
L
Questions
8
Answers
1
Which is
NOT
an advantage of using a recursive algorithm?
Less need for nested loops
Uses less memory
Can write efficiently without much code
Natural analog to recursive concepts like factorial
2
What is Recursion?
The derived classes share common methods with base class
Allows to create new classes that revise an existing class
Hiding the programming details from view
A programming technique in which a method will call itself
3
What will happen if the end case is never reached in a recursive method?
The code will run indefinitely until you manually stop it
You will get a "Bad Recursion" runtime error
The code will not compile
You will get a "Stack Overflow" runtime error
4
Which could be the
recursive case
of a factorial algorithm?
return (n - 1) * factorial(n);
return 1;
return n * factorial(n - 1);
return n * (n -1 ) * (n -2) * (n - 3);
5
Which could be a
recursive case
of a string reverse algorithm?
return reverse(str.substring(1)) + str.charAt(0);
return reverse(str.substring(0)) + str.charAt(1);
return reverse(str.charAt(0)) + str.substring(1);
return reverse(str.charAt(1)) + str.substring(0);
6
Which could be the
recursive case
of a
sum of digits
algorithm?
return n/10 + sumDigits(n-10);
return n%10 + sumDigits(n-10);
return n/10 + sumDigits(n%10);
return n%10 + sumDigits(n/10);
7
Which is the
recursive
case?
if (end > start) {
return end;
return end +sum (start, end - 1);
} else {
8
Which is the
base
case?
} else {
if (end > start) {
return end +sum (start, end - 1);
return end;