1. Home
  2. Explore
  3. Computer Science
  4. Key Computer Science Algorithms

Study methods

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

Key Computer Science Algorithms

  • 43Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Recursion Concepts
In recursion, a function calls
within its own body.

43 questions

  1. 1
    In recursion, a function calls
    _____
    within its own body.
    Hint

    Think about the defining characteristic of recursive functions.

    Answer

    itself

  2. 2
    A recursive algorithm must have at least one
    _____
    case and one recursive case.
    Hint

    What is the term for the condition that stops the recursion?

    Answer

    base

  3. 3
    The strategy of breaking a problem into smaller subproblems and combining their solutions is known as
    _____
    .
    Hint

    Think about how you split a problem into manageable pieces.

    Answer

    divide and conquer

  4. 4
    The Fibonacci sequence has two base cases: F(1)=1F(1) = 1F(1)=1 and $F(2) =
    _____
    .$
    Hint

    Consider the first two terms of the Fibonacci sequence.

    Answer

    1

  5. 5
    The recursive case for the Fibonacci sequence is $F(n) = F(n-1) +
    _____
    .$
    Hint

    What two terms sum to the current term?

    Answer

    F(n−2)F(n-2)F(n−2)

  6. 6
    The time complexity of the naive recursive Fibonacci algorithm is $O(
    _____
    ).$
    Hint

    It grows exponentially with n.

    Answer

    2n2^n2n

  7. 7
    Memoization reduces the time complexity of Fibonacci from O(2n)O(2^n)O(2n) to $O(
    _____
    ).$
    Hint

    It becomes linear after caching results.

    Answer

    nnn

  8. 8
    The iterative Fibonacci algorithm uses $O(
    _____
    )$ space.
    Hint

    It only needs a constant number of variables.

    Answer

    111

  9. 9
    In a binary tree, inorder traversal visits the left subtree, then the
    _____
    , then the right subtree.
    Hint

    What is the order of processing the current node?

    Answer

    node

  10. 10
    Preorder traversal visits the
    _____
    before the left and right subtrees.
    Hint

    Which part is visited first in preorder?

    Answer

    node

  11. 11
    Postorder traversal visits the left subtree, then the right subtree, then the
    _____
    .
    Hint

    The current node is visited last.

    Answer

    node

  12. 12
    When reversing a string recursively, the base case is when the string length equals
    _____
    .
    Hint

    What length indicates no characters left to reverse?

    Answer

    0

  13. 13
    Linear search has a time complexity of $O(
    _____
    )$.
    Hint

    It grows linearly with the number of elements.

    Answer

    nnn

  14. 14
    Binary search requires the array to be
    _____
    .
    Hint

    What property must the array have for binary search to work?

    Answer

    sorted

  15. 15
    Binary search has a time complexity of $O(
    _____
    )$.
    Hint

    It halves the search space each iteration.

    Answer

    log⁡n\log nlogn

  16. 16
    In binary search, the base case for not finding the element is when the start index is greater than the
    _____
    index.
    Hint

    What index condition indicates no more elements to search?

    Answer

    end

  17. 17
    Depth-first search uses a
    _____
    data structure to keep track of nodes to visit.
    Hint

    LIFO structure.

    Answer

    stack

  18. 18
    Breadth-first search uses a
    _____
    data structure to traverse nodes level by level.
    Hint

    FIFO structure.

    Answer

    queue

  19. 19
    The time complexity of DFS on a grid of width WWW and height HHH is $O(
    _____
    ).$
    Hint

    It visits each cell at most once.

    Answer

    W×HW \times HW×H

  20. 20
    A stable sorting algorithm maintains the relative order of elements with
    _____
    keys.
    Hint

    What kind of keys are considered when checking stability?

    Answer

    equal

  21. 21
    An in-place sorting algorithm modifies the
    _____
    array without using extra space proportional to input size.
    Hint

    It does not create a new array.

    Answer

    original

  22. 22
    Selection sort selects the smallest element from the unsorted portion and swaps it with the
    _____
    element.
    Hint

    Which position in the unsorted part does it swap with?

    Answer

    first

  23. 23
    Selection sort has a time complexity of $O(
    _____
    ).$
    Hint

    It's one of the inefficient sorts.

    Answer

    n2n^2n2

  24. 24
    Insertion sort builds the sorted array one element at a time by
    _____
    each new element into the correct position.
    Hint

    What action is performed to place the element?

    Answer

    inserting

  25. 25
    Insertion sort is efficient for
    _____
    sorted data.
    Hint

    When the data is almost in order.

    Answer

    partially

  26. 26
    Bubble sort repeatedly swaps
    _____
    elements if they are in the wrong order.
    Hint

    Which elements are compared and swapped?

    Answer

    adjacent

  27. 27
    The largest element in bubble sort
    _____
    to the end of the array after each pass.
    Hint

    Think about the name of the algorithm.

    Answer

    bubbles

  28. 28
    Merge sort divides the array into two halves, sorts them recursively, and then
    _____
    them.
    Hint

    What operation combines the sorted halves?

    Answer

    merges

  29. 29
    Merge sort has a time complexity of $O(
    _____
    ).$
    Hint

    It is one of the efficient sorts.

    Answer

    nlog⁡nn \log nnlogn

  30. 30
    Heap sort uses a
    _____
    data structure to sort elements.
    Hint

    What data structure is referenced in the name?

    Answer

    heap

  31. 31
    Quicksort selects a
    _____
    element and partitions the array around it.
    Hint

    What is the chosen element called?

    Answer

    pivot

  32. 32
    Dijkstra's algorithm finds the shortest
    _____
    from a start vertex to all other vertices.
    Hint

    What does the algorithm compute?

    Answer

    distance

  33. 33
    In Dijkstra's algorithm, the table stores the current shortest distance and the
    _____
    node for each vertex.
    Hint

    Which node leads to the current vertex on the shortest path?

    Answer

    previous

  34. 34
    Dijkstra's algorithm uses a
    _____
    set to avoid revisiting vertices.
    Hint

    What is the set that marks completed nodes?

    Answer

    visited

  35. 35
    The time complexity of Dijkstra's algorithm with a min-heap is $O((V + E) \log
    _____
    )$.
    Hint

    The logarithm is base 2 of what?

    Answer

    VVV

  36. 36
    The A* algorithm extends Dijkstra's algorithm by using a
    _____
    to estimate the distance to the goal.
    Hint

    What function provides an educated guess?

    Answer

    heuristic

  37. 37
    A spanning tree of a graph connects all vertices with no
    _____
    .
    Hint

    What is forbidden in a tree structure?

    Answer

    cycles

  38. 38
    Kruskal's algorithm sorts all edges by
    _____
    and adds the smallest edge that does not form a cycle.
    Hint

    What property of edges is used for sorting?

    Answer

    weight

  39. 39
    In Kruskal's algorithm, the stopping condition is when the number of edges selected equals
    _____
    .
    Hint

    How many edges are in a spanning tree?

    Answer

    V−1V-1V−1

  40. 40
    The time complexity of Kruskal's algorithm is $O(
    _____
    )$.
    Hint

    Sorting edges dominates the complexity.

    Answer

    Elog⁡EE \log EElogE

  41. 41
    Dynamic programming stores results of
    _____
    to avoid redundant calculations.
    Hint

    What smaller parts of the problem are saved?

    Answer

    subproblems

  42. 42
    The minimum sum subarray problem can be solved in O(n)O(n)O(n) time using
    _____
    programming.
    Hint

    What technique avoids recomputation?

    Answer

    dynamic

  43. 43
    In the DP solution for minimum sum subarray, at each element we decide to either start a new subarray or include the
    _____
    sum ending at the previous element.
    Hint

    What value from the previous element is considered?

    Answer

    minimum

1 of 43
Question 1 of 43

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent