You are on page 1of 7

[SYCS 354] Programming with Recursion ashcar...

https://quizlet.com/8550860/sycs-354-programmi...

[SYCS 354] Programming with


Recursion

56 terms by philipjbrowning

Like this study set? Create a free account to save it.

Create a free account

1 of 7

What is a recursive call?

A function call in which the function


being called is the same as the one
making the call. (p412)

What is direct recursion?

When a function directly calls itself.


(p412)

What is indirect recursion?

When a chain of two or more function


calls returns to the function that
originated the chain. (p412)

What is a recursive definition?

A definition in which something is


defined in terms of a smaller version
of itself. (p413)

What is the base case?

The case for which the solution can be


stated nonrecursively. (p416)

What is the general case?

Also called recursive case. The case


for which the solution is expressed in
terms of a smaller version of itself.
(p416)

07/28/2015 07:13 PM

[SYCS 354] Programming with Recursion ashcar...

2 of 7

https://quizlet.com/8550860/sycs-354-programmi...

What is the recursive case?

Also called general case. The case for


which the solution is expressed in
terms of a smaller version of itself.
(p416)

What is a recursive algorithm?

A solution that is expressed in terms


of (1) smaller instances of itself and
(2) a base case. (p416)

What is an activation record?

Also called stack frame. A record used


at run time to store information about
a function call, including the
parameters, local variables, register
values, and return address. (p435)

What is a stack frame?

Also called activation record. A record


used at run time to store information
about a function call, including the
parameters, local variables, register
values, and return address. (p435)

What is a run-time stack?

A data structure that keeps track of


activation records during the
execution of a program. (p438)

What is tail recursion?

The case in which a function contains


only a single recursive invocation and
it is the last statement to be executed
in the function. (p446)

What does recursive mean?

Having the characteristic of coming


up again, or repeating. (p412)

What is a looping construct?

An construct using the for loop, while


loop or do while loop that controls
execution. (p418)

What is a branching structure?

A structure using operations like if


else or switch statements. (p418)

What is a recursive definition?

A definition in which something is


defined in terms of smaller versions
of itself. (p419)

07/28/2015 07:13 PM

[SYCS 354] Programming with Recursion ashcar...

3 of 7

https://quizlet.com/8550860/sycs-354-programmi...

What is the base case?

In a recursive algorithm, the one or


many cases for which the answer is
known. The solution is not stated in
terms of smaller versions of itself.
(p419)

What is the Three-Question Method?

A method used to verify recursive


functions. Includes (1) the base-case
question, (2) the smaller-caller
question, and (3) the general-case
question. (p419)

What is the base-case question?

Is there a nonrecursive way out of the


function, and does the routine work
correctly for this base case? (p419)

What is the smaller-caller question?

Does each recursive call to the


function involve a smalelr case of the
original problem, leading inescapably
to the base case? (p419)

What is the general-case question?

Assuming that the recursive call(s)


works correctly, does the entire
function work correctly?

What are inductive proofs?

Having made the assumption that the


function works for some base case
(n-1), we can now show that applying
the function to the next value, (n-1) +
1, or n, results in the correct formula.
(p420)

What is binding?

The association of a memory address


with a variable name. (p432)

What is binding time?

The point in the compile/execute


cycle when binding occurs. (p432)

When are the parameters of a


function bound to a particular
address in memory?

For static storage allocation, the


parameter is bound at compile time.
(p432) For dynamic storage
allocation, the parameter is bound at
run time. (p435)

07/28/2015 07:13 PM

[SYCS 354] Programming with Recursion ashcar...

4 of 7

https://quizlet.com/8550860/sycs-354-programmi...

How is recursion like a set of Russian


dols?

Inside the larger doll is a smaller doll,


inside of which is an even smaller
doll, inside of which is yet a smaller
doll, and so on. Recusion is the same.
It reproduces itself in the form of
smaller and smaller versions of itself
until a version is reached that can no
longer be subdivided - that is, until
the smallest doll is reached. (p412)

What is 3 factorial?

3 2 1 = 6. (p414)

What is the algorithm for writing


recursive solutions?

(1) Determine the size of the problem.


Size is the factor that is getting
smaller. Size is usually a parameter to
the problem. (2) Identify the base
case, for which you know the answer.
(3) Identify the general case(s), that
can be expressed as a smaller version
of the size. (Slide 11)

Why is recursion not very efficient?

A recursive solution usually requires


more "overhead" because of the
nested function calls, in terms of both
timie (the function prologues and
epologues must be run for each
recursive call) and space (an
activation record must be created).
(p448)

Why use recursion?

Algorithms could be more easily


solved using iteration, however, a
recursive solution is a natural
solution in certain cases, especially
when pointers are involved. (Slide 22)

What is static storage allocation?

Binding occurs during compilation.


(Slide 30)

What is dynamic storage allocation?

Binding occurs during run time.


(Slide 30)

07/28/2015 07:13 PM

[SYCS 354] Programming with Recursion ashcar...

5 of 7

https://quizlet.com/8550860/sycs-354-programmi...

Global variables are bound at compile


time. When are parameters bound to
an address?

At run-time.

What is transfer of control?

When a function is called, control is


passed to the first executable
statement in the function. (Slide 31)

How does control get passed back to


the calling code?

The activation record controls this


process.

What is the return address?

The address of the instruction in the


calling code that immediately follows
the function call. (Slide 31)

What is stacking?

Using a stack to keep track of each


local environment, i.e., simulate the
run-time stack. (Slide 41)

What three measures help decide


when to use recursion?

(1) Shallow depth


(2) Efficiency
(3) Clarity

When should you use recursion?

When (1) the depth of recursive calls


is relatively "shallow" compared to
the size of the problem, (2) the
recursive version does about the same
amount of work as the nonrecursive
versuion (same Big-O), and (3) the
recursive version is shorter and
simpler than the nonrecursive
solution. (Slide 42)

[Exercise 2a] TRUE or FALSE:


Recursive functions often have fewer
local variables than the equivalent
nonrecursive routines.

True

[Exercise 2b] TRUE or FALSE:


Recursive functions generally use
while or for statements as their main
control structure.

False. They use if-else statements.

07/28/2015 07:13 PM

[SYCS 354] Programming with Recursion ashcar...

6 of 7

https://quizlet.com/8550860/sycs-354-programmi...

[Exercise 2c] TRUE or FALSE:


Recursive functions are possible only
in languages with static storage
allocation.

False

[Exercise 2d] TRUE or FALSE:


Recursive functions should be used
whenever execution speed is critical.

False

[Exercise 2e] TRUE or FALSE:


Recursive functions are always
shorter and clearer than the
equivaleent nonrecursive routines.

False

[Exercise 2f] TRUE or FALSE:


Recursive functions must always
contain a path that does not contain a
recursive call.

True

[Exercise 2g] TRUE or FALSE:


Recursive functions are always ness
"efficient," in terms of Big-O
complexity.

False

[Exercise 4] Describe the ThreeQuestion Method of verifying


recursive routines in relation to an
inductive proof.

Answering yes to Question 1 provides


us with a base case that works
correctly. In answering Question 3,
we make an assumption that the
function works for some arbitrary
case. We can then show that applying
the function to the next value results
in the correct answer in the general
case.

[Exercise 19] What do we mean by


binding time, and what does it have to
do with recursion?

Binding time refers to the point in the


compile/execute cycle when variable
names are associated with addresses
in memory. For recursion to be
possible, parameters must be bound
to addresses at run time, not at
compile time.

07/28/2015 07:13 PM

[SYCS 354] Programming with Recursion ashcar...

7 of 7

https://quizlet.com/8550860/sycs-354-programmi...

[Exercise 22a] TRUE or FALSE: A


recursive solution should be used
when computing time is critical.

False. Recursive solutions are often


less efficient in terms of computing
time.

[Exercise 22b] TRUE or FALSE: A


recursive solution should be used
when the nonrecursive solution would
be longer and more difficult to write.

True

[Exercise 22c] TRUE or FALSE: A


recursive solution should be used
when computing space is critical.

False. Recursive solutions generally


require more space in the run-time
stack.

[Exercise 22d] TRUE or FALSE: A


recursive solution should be used
when your instructor says to use
recursion.

True

What is the function prologue?

A few lines of code at the beginning of


a function, which prepare the stack
and registers for use within the
function.

What is the function epilogue?

Appears at the end of the function,


and restores the stack and registers to
the state they were in before the
function was called.

Is it a coincidence that the depth of


recursion is the same as the
complexity of the iterative version?

No. Recursion represents another way


of doing repetition, so you would
expect that the depth of recursion
would be approximately the same as
the number of iterations for the
iterative version of the same problem.
(p441)

When do you need copy constructors?

1. When returning a complex object.


2. When passing in a complex object
to a function as a parameter.
3. When you initialize a complex
object as a copy of another complex
object.

07/28/2015 07:13 PM

You might also like