1. Home
  2. Explore
  3. Computer Science
  4. Understanding Recursion

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Understanding Recursion

  • 94Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Recursion Basics
Recursion is a method or function that
.

94 questions

  1. 1
    Recursion is a method or function that
    _____
    .
    Hint

    Think about what makes a recursive method different from one that only calls other methods.

    Answer

    calls itself

  2. 2
    A recursive call should change or progress a parameter so that each invocation moves closer to the
    _____
    .
    Hint

    This is the condition that stops further recursive calls.

    Answer

    base case

  3. 3
    The condition that tells a recursive function when to stop making further recursive calls is the
    _____
    .
    Hint

    It is also called the stopping condition.

    Answer

    base case

  4. 4
    The small unit of work performed during a recursive invocation helps move the solution closer to the
    _____
    .
    Hint

    It is the problem's desired outcome.

    Answer

    goal

  5. 5
    In the line analogy, each person can find their position by asking the person ahead of them and adding
    _____
    for themselves.
    Hint

    Each person counts as one person in the line.

    Answer

    one

  6. 6
    In the line-position example, the recursion stops when a person has no next person ahead; this is represented by
    _____
    .
    Hint

    It indicates that there is no next person.

    Answer

    null

  7. 7
    In essay revision, each invocation revises the essay and calls itself again until the essay is
    _____
    .
    Hint

    The professor stops requesting revisions at this point.

    Answer

    complete

  8. 8
    The smallest input for reversing a string can be the
    _____
    because reversing it produces the same value.
    Hint

    It contains no characters to rearrange.

    Answer

    empty string

  9. 9
    A single character is also a valid palindrome base case because reading it forward or backward gives the
    _____
    .
    Hint

    There is only one character to compare.

    Answer

    same character

  10. 10
    A recursive algorithm can solve a large problem by breaking it into smaller
    _____
    .
    Hint

    These are reduced versions of the original problem.

    Answer

    subproblems

  11. 11
    In the line-position example, each person passes the question along to the person in
    _____
    of them.
    Hint

    This person is closer to the ATM.

    Answer

    front

  12. 12
    A recursive process needs a condition that prevents the number of active recursive calls from growing
    _____
    .
    Hint

    Without a stopping condition, calls continue indefinitely until resources are exhausted.

    Answer

    without end

  13. 13
    A benefit of recursion is that it can make algorithms for inherently recursive data structures more
    _____
    .
    Hint

    It can reduce complicated loops and variables to a concise solution.

    Answer

    elegant

  14. 14
    Recursive calls can incur CPU overhead compared with iterating through a
    _____
    .
    Hint

    This is the iterative alternative mentioned in the content.

    Answer

    loop

  15. 15
    Recursion can reduce the need for complex loops and auxiliary data structures by using an implicit
    _____
    .
    Hint

    Method invocations are stored on this structure.

    Answer

    stack

  16. 16
    Too many active recursive calls can exhaust the program's available call-stack memory and cause a
    _____
    .
    Hint

    This exception occurs when the call stack exceeds its allocated memory.

    Answer

    Stack Overflow

  17. 17
    Storing results from expensive recursive calls so they can be reused is called
    _____
    .
    Hint

    It avoids repeating work that has already been done.

    Answer

    memoization

  18. 18
    Using recursion without a suitable way to divide the task into meaningful subproblems can lead to unnecessarily
    _____
    code.
    Hint

    The code becomes harder to understand rather than simpler.

    Answer

    complex

  19. 19
    Recursion is especially suitable for data structures that are themselves recursively defined, such as trees and
    _____
    .
    Hint

    This other structure is often traversed with depth-first search.

    Answer

    graphs

  20. 20
    The tradeoff between recursive calls and iteration can involve both time and
    _____
    .
    Hint

    Recursive calls use memory for their stack frames.

    Answer

    space

  21. 21
    The amount of memory used by recursive calls can grow as additional method invocations are added to the
    _____
    .
    Hint

    Each active invocation has a frame stored here.

    Answer

    call stack

  22. 22
    To decide whether recursion is a good fit, ask whether the problem can be broken into meaningful
    _____
    .
    Hint

    Each should move the solution toward the original goal.

    Answer

    subproblems

  23. 23
    When method A needs the result of method B, A cannot finish its dependent work until B
    _____
    .
    Hint

    The needed value must be available before the caller can continue.

    Answer

    returns

  24. 24
    The operating system uses the call stack to store method invocations as
    _____
    .
    Hint

    Each active method call has one of these.

    Answer

    stack frames

  25. 25
    A stack frame can store information about local variables and the method's
    _____
    .
    Hint

    These are the values passed into a method.

    Answer

    parameters

  26. 26
    A method's stack frame must wait for its dependent calls to complete before it can
    _____
    from the stack.
    Hint

    This is the operation that removes a completed frame.

    Answer

    pop

  27. 27
    After a called method returns, its result is passed back to the method invocation that was
    _____
    it.
    Hint

    That earlier method could not finish until the result arrived.

    Answer

    waiting for

  28. 28
    An infinite recursive function with no base case keeps adding invocations until a
    _____
    occurs.
    Hint

    The call stack eventually exceeds its allocated memory.

    Answer

    Stack Overflow

  29. 29
    After the base case returns, recursive stack frames are evaluated in the reverse order of how they were
    _____
    .
    Hint

    The most recent unfinished call returns before earlier calls.

    Answer

    called

  30. 30
    The call stack helps determine the memory address to which a method should
    _____
    its data.
    Hint

    A caller needs the result of its dependent method.

    Answer

    return

  31. 31
    In recursive string reversal, each call can shrink the input by removing its first
    _____
    .
    Hint

    This is the smallest unit of a string used in the example.

    Answer

    character

  32. 32
    To reverse a string recursively, the removed first character is concatenated
    _____
    the result of the recursive call.
    Hint

    This placement causes characters to appear in reverse order as calls return.

    Answer

    after

  33. 33
    For the input "Hello," recursive reversal first processes the remaining substring after removing
    _____
    .
    Hint

    It is the first character of the example input.

    Answer

    H

  34. 34
    In recursive string reversal, saved characters are returned and concatenated as the calls
    _____
    .
    Hint

    The calls do this after the base case has returned.

    Answer

    unwind

  35. 35
    A palindrome reads the same
    _____
    and backward.
    Hint

    The word's order is unchanged when read in either direction.

    Answer

    forward

  36. 36
    A recursive palindrome check compares characters at opposite
    _____
    of the string.
    Hint

    One is near the beginning and the other near the end.

    Answer

    indices

  37. 37
    If opposite-end characters in a palindrome check do not match, the function can immediately return
    _____
    .
    Hint

    The mismatch violates the palindrome property.

    Answer

    false

  38. 38
    An empty string and a one-character string are palindrome base cases that return
    _____
    .
    Hint

    Neither input contains a mismatched pair of characters.

    Answer

    true

  39. 39
    In the palindrome example "race car," matching outer characters allows the function to recurse on a
    _____
    substring.
    Hint

    The matching characters are no longer needed for the next comparison.

    Answer

    smaller

  40. 40
    In decimal-to-binary conversion, repeatedly dividing by two produces a quotient and a
    _____
    .
    Hint

    This value records whether the current number is even or odd.

    Answer

    remainder

  41. 41
    When converting a decimal number to binary recursively, the remainder from division by two contributes one
    _____
    .
    Hint

    It is either zero or one.

    Answer

    binary digit

  42. 42
    For the recursive binary conversion described, reaching zero means there is no need to
    _____
    again.
    Hint

    Zero is the stopping condition for the process.

    Answer

    divide

  43. 43
    In the binary conversion example, the quotient is obtained by dividing by two and applying the
    _____
    operator.
    Hint

    It keeps the result as an integer rather than a floating-point value.

    Answer

    floor

  44. 44
    The sum of natural numbers from one to ten is
    _____
    .
    Hint

    Add each integer from one through ten.

    Answer

    55

  45. 45
    For recursive summation, an input of one is a base case because the sum from one to one is
    _____
    .
    Hint

    There is only a single value to add.

    Answer

    one

  46. 46
    To recursively sum values up to a larger number, add the current number to the sum for the number
    _____
    .
    Hint

    This makes the recursive input progress toward one.

    Answer

    one less

  47. 47
    The Fibonacci sequence is defined so that each value after the base cases is the sum of the
    _____
    values.
    Hint

    For example, 55 comes from 34 and 21.

    Answer

    two preceding

  48. 48
    In the Fibonacci example, the values at indices zero and one are the base cases
    _____
    and one.
    Hint

    It is the first value in the sequence shown.

    Answer

    zero

  49. 49
    In the non-optimized recursive Fibonacci function, the call for one side of the sum must finish before the call for the
    _____
    side begins.
    Hint

    The first call is evaluated before the other operand of the addition.

    Answer

    right

  50. 50
    Recomputing the same Fibonacci values in multiple branches is
    _____
    work.
    Hint

    These calculations have already been performed elsewhere in the recursion tree.

    Answer

    redundant

  51. 51
    A divide-and-conquer algorithm splits a large problem into smaller subproblems, solves them, and then
    _____
    their results.
    Hint

    The results are brought together to solve the overall problem.

    Answer

    merges

  52. 52
    Binary search requires its input list to be
    _____
    .
    Hint

    The ordering lets the algorithm discard half of the search space.

    Answer

    sorted

  53. 53
    Binary search compares the target with a value at the
    _____
    of the current search range.
    Hint

    This value separates the current range into two halves.

    Answer

    midpoint

  54. 54
    If the target is less than the midpoint value in binary search, the algorithm can discard the
    _____
    half.
    Hint

    The sorted order places smaller values on the other side.

    Answer

    right

  55. 55
    If the target is greater than the midpoint value in binary search, the algorithm searches from the midpoint
    _____
    .
    Hint

    The midpoint and everything before it can be excluded.

    Answer

    plus one

  56. 56
    Binary search can stop successfully when the midpoint value equals the
    _____
    .
    Hint

    This means the sought value has been found.

    Answer

    target

  57. 57
    Merge Sort continues dividing an array until each subarray contains just
    _____
    value.
    Hint

    A subarray of this size is already sorted.

    Answer

    one

  58. 58
    During the merge phase of Merge Sort, two sorted subarrays are combined by repeatedly selecting the
    _____
    front value.
    Hint

    This keeps the combined output in ascending order.

    Answer

    smaller

  59. 59
    A temporary array in Merge Sort holds merged values so the original array is not modified prematurely; the values are then copied back into the
    _____
    .
    Hint

    This is the input structure being sorted in place.

    Answer

    original array

  60. 60
    In Merge Sort, the left recursive half is completed before the algorithm starts processing the
    _____
    half.
    Hint

    Recursive calls are evaluated in order, not simultaneously.

    Answer

    right

  61. 61
    A linked list stores its elements through node connections rather than requiring them to be
    _____
    in memory.
    Hint

    The nodes may be located in different memory locations.

    Answer

    contiguous

  62. 62
    For recursive linked-list reversal, a null head or a head with no next node is a
    _____
    .
    Hint

    No further reversal work is needed for either input.

    Answer

    base case

  63. 63
    In recursive linked-list reversal, the call advances through the list by passing
    _____
    as its next input.
    Hint

    This is the pointer to the next node.

    Answer

    head.next

  64. 64
    After the recursive reversal reaches the last node, that node is returned as the new
    _____
    .
    Hint

    It becomes the first node of the reversed list.

    Answer

    head

  65. 65
    When unwinding recursive linked-list reversal, the current node's next node is made to point
    _____
    .
    Hint

    This reverses the direction of the link.

    Answer

    back to the current node

  66. 66
    After reversing a pair of linked-list nodes, the current node's old next pointer is set to
    _____
    to prevent a cycle.
    Hint

    The old forward connection must be removed.

    Answer

    null

  67. 67
    When recursively merging two sorted linked lists, if one head is null, the function can return the
    _____
    list.
    Hint

    There are no nodes from the empty list to merge.

    Answer

    other

  68. 68
    To merge two sorted linked lists recursively, compare their current values and attach the
    _____
    node first.
    Hint

    Choosing it preserves ascending order.

    Answer

    smaller

  69. 69
    In recursive linked-list merging, each selected node's next pointer is assigned the result of the
    _____
    merge call.
    Hint

    That call processes the remaining nodes.

    Answer

    recursive

  70. 70
    For a binary search tree, each node can have at most
    _____
    children.
    Hint

    They are referred to as the left and right children.

    Answer

    two

  71. 71
    In a binary search tree, values in a node's left subtree are
    _____
    than that node's value.
    Hint

    This ordering determines the direction taken when searching or inserting.

    Answer

    less

  72. 72
    In a binary search tree, values in a node's right subtree are
    _____
    than that node's value.
    Hint

    This is the opposite ordering from the left subtree.

    Answer

    greater

  73. 73
    When inserting into a binary search tree, comparisons continue until the insertion position is a
    _____
    .
    Hint

    A new node is inserted at an available child position.

    Answer

    null

  74. 74
    If a value to insert is greater than the current binary search tree node, recursion proceeds to the
    _____
    subtree.
    Hint

    Greater values are placed on this side.

    Answer

    right

  75. 75
    If a value to insert is less than the current binary search tree node, recursion proceeds to the
    _____
    subtree.
    Hint

    Smaller values are placed on this side.

    Answer

    left

  76. 76
    After recursively inserting a node into a binary search tree, the function returns the original
    _____
    .
    Hint

    Returning it preserves access to the tree that was passed in.

    Answer

    root node

  77. 77
    A leaf node is a tree node with no
    _____
    .
    Hint

    It has neither a left nor a right child.

    Answer

    children

  78. 78
    A depth-first traversal explores one subtree fully before exploring the other; in the described tree traversal, it explores the
    _____
    subtree first.
    Hint

    The traversal then proceeds to the right subtree.

    Answer

    left

  79. 79
    To avoid revisiting nodes in a graph that may contain cycles, depth-first search keeps a set of
    _____
    nodes.
    Hint

    The set records nodes already encountered.

    Answer

    visited

  80. 80
    In graph depth-first search, a null input node cannot contain an integer goal, so the search returns
    _____
    .
    Hint

    There is no node to match against the goal.

    Answer

    false

  81. 81
    In graph depth-first search, when the current node matches the goal, the search returns
    _____
    .
    Hint

    The target has been found.

    Answer

    true

  82. 82
    If depth-first search has visited every reachable neighbor without finding the goal, it returns
    _____
    .
    Hint

    The goal was not found in the explored graph.

    Answer

    false

  83. 83
    Memoization stores results of previously computed subproblems so later calls can
    _____
    them.
    Hint

    This avoids repeating expensive calculations.

    Answer

    reuse

  84. 84
    In the described memoized Fibonacci implementation, a hash map provides average constant-time access, described as big O of
    _____
    .
    Hint

    The result is written as big O of one.

    Answer

    one

  85. 85
    A memoized recursive function checks whether the cache contains a result before doing the
    _____
    calls.
    Hint

    If the result is already present, those calls can be skipped.

    Answer

    recursive

  86. 86
    After a recursive subproblem is computed in a memoized function, its result is added to the
    _____
    .
    Hint

    Later calls consult this storage.

    Answer

    cache

  87. 87
    Memoization is especially useful when different recursive branches call the same
    _____
    .
    Hint

    The result of this repeated calculation can be reused.

    Answer

    subproblem

  88. 88
    A recursive function is tail recursive when its final return value is just the
    _____
    .
    Hint

    No further operation is performed on its result before returning.

    Answer

    recursive call

  89. 89
    A factorial function that multiplies a value by the result of a recursive call is not tail recursive because work remains after the
    _____
    .
    Hint

    The multiplication must still be performed.

    Answer

    recursive call

  90. 90
    Tail-call optimization can reduce the number of stack frames used by recursive
    _____
    .
    Hint

    It can help avoid stack growth in supported languages.

    Answer

    calls

  91. 91
    To make a recursive call tail-call optimizable, the recursive call should be the
    _____
    instruction.
    Hint

    Nothing should need to be added to its result afterward.

    Answer

    last

  92. 92
    Tail-call optimization is supported mostly by
    _____
    programming languages.
    Hint

    These languages commonly emphasize recursive function definitions.

    Answer

    functional

  93. 93
    Tail-call optimization is not inherent in languages such as Python, Java, and
    _____
    .
    Hint

    The content also notes that support can vary by browser and execution environment.

    Answer

    JavaScript

  94. 94
    Before relying on tail-call optimization, developers should check whether their language, compiler, and execution environment
    _____
    it.
    Hint

    Support is not consistent across languages and platforms.

    Answer

    support

1 of 94
Question 1 of 94

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent