flashcards.recursion

7
[SYCS 354] Programming with Recursion 56 terms by philipjbrowning Like this study set? Create a free account to save it. Create a free account Create a free account 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) [SYCS 354] Programming with Recursion flashcar... https://quizlet.com/8550860/sycs-354-programmi... 1 of 7 07/28/2015 07:13 PM

Upload: john-le-tourneux

Post on 15-Feb-2016

3 views

Category:

Documents


0 download

DESCRIPTION

recursion flashcards

TRANSCRIPT

Page 1: Flashcards.recursion

[SYCS 354] Programming with

Recursion 56 terms by philipjbrowning

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

Create a free accountCreate a free account

What is a recursive call? A function call in which the functionbeing called is the same as the onemaking 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 functioncalls returns to the function thatoriginated the chain. (p412)

What is a recursive definition? A definition in which something isdefined in terms of a smaller versionof itself. (p413)

What is the base case? The case for which the solution can bestated nonrecursively. (p416)

What is the general case? Also called recursive case. The casefor which the solution is expressed interms of a smaller version of itself.(p416)

[SYCS 354] Programming with Recursion flashcar... https://quizlet.com/8550860/sycs-354-programmi...

1 of 7 07/28/2015 07:13 PM

Page 2: Flashcards.recursion

What is the recursive case? Also called general case. The case forwhich the solution is expressed interms of a smaller version of itself.(p416)

What is a recursive algorithm? A solution that is expressed in termsof (1) smaller instances of itself and(2) a base case. (p416)

What is an activation record? Also called stack frame. A record usedat run time to store information abouta function call, including theparameters, local variables, registervalues, and return address. (p435)

What is a stack frame? Also called activation record. A recordused at run time to store informationabout a function call, including theparameters, local variables, registervalues, and return address. (p435)

What is a run-time stack? A data structure that keeps track ofactivation records during theexecution of a program. (p438)

What is tail recursion? The case in which a function containsonly a single recursive invocation andit is the last statement to be executedin the function. (p446)

What does recursive mean? Having the characteristic of comingup again, or repeating. (p412)

What is a looping construct? An construct using the for loop, whileloop or do while loop that controlsexecution. (p418)

What is a branching structure? A structure using operations like ifelse or switch statements. (p418)

What is a recursive definition? A definition in which something isdefined in terms of smaller versionsof itself. (p419)

[SYCS 354] Programming with Recursion flashcar... https://quizlet.com/8550860/sycs-354-programmi...

2 of 7 07/28/2015 07:13 PM

Page 3: Flashcards.recursion

What is the base case? In a recursive algorithm, the one ormany cases for which the answer isknown. The solution is not stated interms of smaller versions of itself.(p419)

What is the Three-Question Method? A method used to verify recursivefunctions. Includes (1) the base-casequestion, (2) the smaller-callerquestion, and (3) the general-casequestion. (p419)

What is the base-case question? Is there a nonrecursive way out of thefunction, and does the routine workcorrectly for this base case? (p419)

What is the smaller-caller question? Does each recursive call to thefunction involve a smalelr case of theoriginal problem, leading inescapablyto the base case? (p419)

What is the general-case question? Assuming that the recursive call(s)works correctly, does the entirefunction work correctly?

What are inductive proofs? Having made the assumption that thefunction works for some base case(n-1), we can now show that applyingthe function to the next value, (n-1) +1, or n, results in the correct formula.(p420)

What is binding? The association of a memory addresswith a variable name. (p432)

What is binding time? The point in the compile/executecycle when binding occurs. (p432)

When are the parameters of afunction bound to a particularaddress in memory?

For static storage allocation, theparameter is bound at compile time.(p432) For dynamic storageallocation, the parameter is bound atrun time. (p435)

[SYCS 354] Programming with Recursion flashcar... https://quizlet.com/8550860/sycs-354-programmi...

3 of 7 07/28/2015 07:13 PM

Page 4: Flashcards.recursion

How is recursion like a set of Russiandols?

Inside the larger doll is a smaller doll,inside of which is an even smallerdoll, inside of which is yet a smallerdoll, and so on. Recusion is the same.It reproduces itself in the form ofsmaller and smaller versions of itselfuntil a version is reached that can nolonger be subdivided - that is, untilthe smallest doll is reached. (p412)

What is 3 factorial? 3 2 1 = 6. (p414)

What is the algorithm for writingrecursive solutions?

(1) Determine the size of the problem.Size is the factor that is gettingsmaller. Size is usually a parameter tothe problem. (2) Identify the basecase, for which you know the answer.(3) Identify the general case(s), thatcan be expressed as a smaller versionof the size. (Slide 11)

Why is recursion not very efficient? A recursive solution usually requiresmore "overhead" because of thenested function calls, in terms of bothtimie (the function prologues andepologues must be run for eachrecursive call) and space (anactivation record must be created).(p448)

Why use recursion? Algorithms could be more easilysolved using iteration, however, arecursive solution is a naturalsolution in certain cases, especiallywhen 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)

[SYCS 354] Programming with Recursion flashcar... https://quizlet.com/8550860/sycs-354-programmi...

4 of 7 07/28/2015 07:13 PM

Page 5: Flashcards.recursion

Global variables are bound at compiletime. When are parameters bound toan address?

At run-time.

What is transfer of control? When a function is called, control ispassed to the first executablestatement in the function. (Slide 31)

How does control get passed back tothe calling code?

The activation record controls thisprocess.

What is the return address? The address of the instruction in thecalling code that immediately followsthe function call. (Slide 31)

What is stacking? Using a stack to keep track of eachlocal environment, i.e., simulate therun-time stack. (Slide 41)

What three measures help decidewhen to use recursion?

(1) Shallow depth(2) Efficiency(3) Clarity

When should you use recursion? When (1) the depth of recursive callsis relatively "shallow" compared tothe size of the problem, (2) therecursive version does about the sameamount of work as the nonrecursiveversuion (same Big-O), and (3) therecursive version is shorter andsimpler than the nonrecursivesolution. (Slide 42)

[Exercise 2a] TRUE or FALSE:Recursive functions often have fewerlocal variables than the equivalentnonrecursive routines.

True

[Exercise 2b] TRUE or FALSE:Recursive functions generally usewhile or for statements as their maincontrol structure.

False. They use if-else statements.

[SYCS 354] Programming with Recursion flashcar... https://quizlet.com/8550860/sycs-354-programmi...

5 of 7 07/28/2015 07:13 PM

Page 6: Flashcards.recursion

[Exercise 2c] TRUE or FALSE:Recursive functions are possible onlyin languages with static storageallocation.

False

[Exercise 2d] TRUE or FALSE:Recursive functions should be usedwhenever execution speed is critical.

False

[Exercise 2e] TRUE or FALSE:Recursive functions are alwaysshorter and clearer than theequivaleent nonrecursive routines.

False

[Exercise 2f] TRUE or FALSE:Recursive functions must alwayscontain a path that does not contain arecursive call.

True

[Exercise 2g] TRUE or FALSE:Recursive functions are always ness"efficient," in terms of Big-Ocomplexity.

False

[Exercise 4] Describe the Three-Question Method of verifyingrecursive routines in relation to aninductive proof.

Answering yes to Question 1 providesus with a base case that workscorrectly. In answering Question 3,we make an assumption that thefunction works for some arbitrarycase. We can then show that applyingthe function to the next value resultsin the correct answer in the generalcase.

[Exercise 19] What do we mean bybinding time, and what does it have todo with recursion?

Binding time refers to the point in thecompile/execute cycle when variablenames are associated with addressesin memory. For recursion to bepossible, parameters must be boundto addresses at run time, not atcompile time.

[SYCS 354] Programming with Recursion flashcar... https://quizlet.com/8550860/sycs-354-programmi...

6 of 7 07/28/2015 07:13 PM

Page 7: Flashcards.recursion

[Exercise 22a] TRUE or FALSE: Arecursive solution should be usedwhen computing time is critical.

False. Recursive solutions are oftenless efficient in terms of computingtime.

[Exercise 22b] TRUE or FALSE: Arecursive solution should be usedwhen the nonrecursive solution wouldbe longer and more difficult to write.

True

[Exercise 22c] TRUE or FALSE: Arecursive solution should be usedwhen computing space is critical.

False. Recursive solutions generallyrequire more space in the run-timestack.

[Exercise 22d] TRUE or FALSE: Arecursive solution should be usedwhen your instructor says to userecursion.

True

What is the function prologue? A few lines of code at the beginning ofa function, which prepare the stackand registers for use within thefunction.

What is the function epilogue? Appears at the end of the function,and restores the stack and registers tothe state they were in before thefunction was called.

Is it a coincidence that the depth ofrecursion is the same as thecomplexity of the iterative version?

No. Recursion represents another wayof doing repetition, so you wouldexpect that the depth of recursionwould be approximately the same asthe number of iterations for theiterative version of the same problem.(p441)

When do you need copy constructors? 1. When returning a complex object.2. When passing in a complex objectto a function as a parameter.3. When you initialize a complexobject as a copy of another complexobject.

[SYCS 354] Programming with Recursion flashcar... https://quizlet.com/8550860/sycs-354-programmi...

7 of 7 07/28/2015 07:13 PM