# AP Computer Science 3.1 Standard Algorithms

AP Computer Science 3.1 Standard Algorithms. What is the output of Recurse(3)?

AP | AP Computer Science |

AP Computer Science | Standard Algorithms |

Computer Science | AP Computer Science |

Language | English Language |

Standard Operations and Algorithms | Operations on data structures |

Test Prep | AP Computer Science |

### Transcript

mental answers on numbers Okay this question Assessing what we

know about rikers in which is essentially having a method

call itself This creates a type of loop that goes

round and round around until some condition typically called the

base case is satisfied like a dog chasing its tail

in telling finally catches it a simple implementation of riker

shin might look something like this All right well this

method would take an imager And if it's greater than

zero print hello plus the imager Then it will decrease

the imager by one and call itself again And if

it's still greater than zero it'll do it again can

again and again it'll rikers decreasing over and over and

saying hello annie in inger goes up there until it

reaches zero go at zero it will simply return the

zero and the method will no longer call itself it's

a bit like the recursive algorithm shown in this question

except this one is also doing some funky math to

the imager so we'll need to carefully plot out what's

happening step by step here's our sniffing and the question

is asking pre output of re curse free All right

well starting at the top we're getting our method ready

with the parameter into end which will let us accept

that three and play with it as variable end when

rikers three gets called if it is less than one

will return the number one doesn't apply to us at

the moment though else will return one plus the product

of three times re curse and minus one better known

as to wait a min We're trying to calculate what

happens in rikers right now How can we use something

that hasn't been calculated yet Has a factor in our

calculation Shouldn't they shatter the universe somehow Well we're just

gonna have to dive into the first method again and

see how deep the rabbit hole goes at this point

Imager and is currently three and we're being asked for

re curse and minus one so it's just like calling

re cursed too We did The fancy man if end

now to remember is less than one return One else

return one plus three times rikers and minus one So

we'll be calling recruits again this time as reversed one

so it ends less than one return One else returned

one plus three times were cursed and minus one and

calling rikers yet again this time as rikers Zero Ah

but here we go If and is less than one

which it is We return one The product of rikers

zero is one We've stopped the lute e Now we

just have to climb back out of this home were

in back to rikers one We now know that riker

zero equals one So occurs one equals one plus the

product of three times one well in california three times

One two three and add one to that for four

So recruits one equals four and climbing up a rung

refers to it three times for his twelve plus one

is thirteen to rikers to is thirteen And at rikers

three three times thirteen is thirty nine plus one which

is forty So the product of rikers three is forty

Who A lot of work Someone really should write a 00:03:26.9 --> [endTime] computer program to handle it for us next time