Recursion

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the Droste effect?

A recursive image; a picture within a picture

What is a common strategy in linear recursion?

Divide by half until the problem is solved, similar to binary search, worst case is O(logn)

What is a recursive function?

Function that calls itself somewhere in the body; supported in most programming languages

What is the super lame joke on the first slide?

'If you google recursion, it asks if you meant recursion' HAHAHAHAHA

What are recurrence relations?

Arise when analyzing the running time of recursive algorithms, especially divide and conquer algorithms

What two parts exist in a recursive definition?

Base case: stopping condition; recursive step: expression of the computation or definition in terms of itself

What are examples of recurrence relations?

Binary search: T(n) = 1 if n = 1, T(n) = T(n/2) + O(1) if n > 1; and mergesort: T(n) = 1 if n = 1, T(n) = 2T(n/2) + O(n) if n > 1

What is merge sort?

Divide and conquer algorithm; divide into two parts, sort each part using merge sort (divide again), combine instances; O(n)

What are the components of divide and conquer?

Divide the problem into two+ instances of the same problem & same size; Conquer the sub-problems by solving them recursively (if small enough, solve straightforwardly); combine solutions to create solution to original

What is a recursive algorithm?

Form of decomposition where a problem is solved by decomposing it into one or more simpler problems that have the same form as the original

What is the substitution method?

Guess the form of the solution, then use mathematical induction to show correctness; substitute guessed answer for function; works well when the solution is easy to guess

How do we guess a solution?

Making a guess is difficult; use recursion trees to devise good guesses

How do you solve a recurrence relation?

Put T(n) on left-hand side, but not the right. Two methods: Substitution (induction proofs :( ) and Master Theorem "cookbook" formula

Compare/contrast recursion and iteration.

Recursive code is simpler than iterative (easier to write, read, debug); BUT recursive functions execute slower than iterative: recursion incurs overhead for function calls, deep recursive can cause overflowing run-time stack, SE benefit of recursion outweighs reduction in efficiency

What is tree recursion? How is it different from linear?

Recursive function calls itself two or more times before returning a value; linear calls itself once before returning a value

What is linear recursion?

Recursive function makes at most one recursive call each time it is invoked

What is a recursion tree?

Show successive expansions of recurrences; keep track of time spent on subproblems or a divide/conquer alg; organize the algebraic bookkeeping necessary to solve a recurrence

What is divide and conquer?

Strategy for algorithm design that is usually implemented using tree recursion

What is recursion?

Technique for defining data structures or algorithms in terms of themselves

What is tail recursion?

Uses linear recursion and makes a recursive call as it's LAST operation


Kaugnay na mga set ng pag-aaral

Med Surg I Prep U Chapter 36: Management of Patients With Immune Deficiency Disorders

View Set

Chapter 14 Competing in Marketing & Supply Chain Management

View Set

Cognitive Psychology Exam 2 (chapters 5-8)

View Set

History of Rock and Roll: Final Review

View Set