Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION 1 true false a palindrome not found exception the boolean value returne

ID: 3792429 • Letter: Q

Question

QUESTION 1

true

false

a palindrome not found exception

the boolean value returned from the isPal method

1 points   

QUESTION 2

10

8

4

21

1 points   

QUESTION 3

0

-10

-22

Nothing – a StackoverflowError exception will occur

1 points   

QUESTION 4

0, 4, and 8

4 and 8

4

8

1 points   

QUESTION 5

return s;

return 0;

return s.charAt(0);

return s.substring(1);

1 points   

QUESTION 6

In recursion, the non-recursive case is analogous to a loop ____.

call

iteration

termination

condition

1 points   

QUESTION 7

1

-1

120

840

1 points   

QUESTION 8

821

128

12

10

1 points   

QUESTION 9

1

2

6

24

1 points   

QUESTION 10

return (printSum(n - 1));

return (n + printSum(n + 1));

return (n + printSum(n - 1));

return (n - printSum(n - 1));

1 points   

QUESTION 11

1, 3, and 6

1, 3, 6, and 9

3, 6, and 9

3, 6, 9, and 12

1 points   

QUESTION 12

If recursion does not have a special terminating case, what error will occur?

Index out of range

Illegal argument

Stack overflow

Out of memory

1 points   

QUESTION 13

if (i == 0)

return j

return add(i - 1, j + 1)

there is no terminating condition

1 points   

QUESTION 14

if (n == -1)

if (n <= 0)

if (n >= 0)

The terminating case as shown will avoid infinite recursion.

1 points   

QUESTION 15

return reverseIt(s.substring(0)) + s.charAt(1);

return reverseIt(s.substring(0)) + s.charAt(0);

return reverseIt(s.substring(1)) + s.charAt(1);

return reverseIt(s.substring(1)) + s.charAt(0);

true

false

a palindrome not found exception

the boolean value returned from the isPal method

Explanation / Answer

For other question image didnot load hence was not able to answer.

Question 9

strangeCalc(2,3)
bottom = 2, top = 3
bottom is neither greater than 3 nor equal
so return bottom*strangeCalc(bottom+1, top)
= 2*strangeCalc(2+1,3)
= 2*strangeCalc(3,3)
= 2*1 (here strangeCalc(3,3) will return 1 as bottom and top are equal
=2

Question 10
public static int printSum(int n)
{
if(n==0)
{
return 0;
}
else
{
return (n + printSum(n-1))
}
}

Here we have to return sum of digits from 1 to n or we as we are passing n we can say n to 1 (both are same) hence we start with n + recursivly calling the same function with 1 digit less than previous hence n-1.

Question 11

Here we are passing n=3 to function recurse
first check n==0 false
go to else
total = 3+recurse(n-1)
total = 3+recurse(2)
then again call recurse
total = 3+3+recurse(1)
then again call recurse
total = 3+3+3+recurse(0)

values printed will be 3,6,9

Question 12
If recursion doesnot have a terminating case then it will end up in an infinite loop hence eating up memory which will result in Out Of Memory

Question 13
As here the assumption is i>=0 which means we are starting either from 0 or from some positive number hence once i becomes 0 the function terminates.

Question 14
The current terminating case will avoid infinte recursion
as when we are when n=1 , which is 1+myPrint(1-1)
which means we are calling recursive function with n=0
it will go to if condition and return 0 and no more further callling recursive function and termination.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote