1. Home
  2. Explore
  3. Computer Science
  4. Top 7 Coding Interview Algorithms

Study methods

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

Top 7 Coding Interview Algorithms

  • 24Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Search Algorithms
Binary search can only be used on a
list.

24 questions

  1. 1
    Binary search can only be used on a
    _____
    list.
    Hint

    The list must be ordered in some way for this algorithm to work.

    Answer

    sorted

  2. 2
    The worst-case time complexity of binary search is
    _____
    .
    Hint

    Think about how the number of elements to search halves each step.

    Answer

    O(log⁔n)O(\log n)O(logn)

  3. 3
    Linear search has a worst-case time complexity of
    _____
    .
    Hint

    In the worst case, you might have to check every single element.

    Answer

    O(n)O(n)O(n)

  4. 4
    In depth-first search, the process of returning to an unvisited branch after reaching the end of a path is called
    _____
    .
    Hint

    Think about what you do when you hit a dead end in a maze.

    Answer

    backtracking

  5. 5
    Depth-first search uses a
    _____
    array to keep track of visited nodes.
    Hint

    We need to avoid revisiting the same node.

    Answer

    visited

  6. 6
    One real-life application of depth-first search is solving a
    _____
    .
    Hint

    Think about exploring paths until you find the exit.

    Answer

    maze

  7. 7
    The time complexity of depth-first search is expressed as
    _____
    .
    Hint

    It depends on the number of vertices (nodes) and edges (connections).

    Answer

    O(V+E)O(V + E)O(V+E)

  8. 8
    In breadth-first search, nodes are visited level by level using a
    _____
    .
    Hint

    First-in-first-out data structure.

    Answer

    queue

  9. 9
    Breadth-first search is used in chess algorithms to explore all possible moves at each
    _____
    .
    Hint

    The algorithm looks at moves for the current player, then all responses, etc.

    Answer

    turn

  10. 10
    The time complexity of breadth-first search is also
    _____
    .
    Hint

    Same as DFS for the same reason.

    Answer

    O(V+E)O(V + E)O(V+E)

  11. 11
    Insertion sort works by comparing adjacent elements and
    _____
    them if they are out of order.
    Hint

    It moves elements into the correct position one by one.

    Answer

    swapping

  12. 12
    The best-case time complexity of insertion sort is
    _____
    .
    Hint

    When the list is already sorted, no swaps are needed.

    Answer

    O(n)O(n)O(n)

  13. 13
    The worst-case time complexity of insertion sort is
    _____
    .
    Hint

    When the list is in reverse order, many swaps are required.

    Answer

    O(n2)O(n^2)O(n2)

  14. 14
    Insertion sort is best used for lists that are
    _____
    .
    Hint

    It performs well when little movement is needed.

    Answer

    small or nearly sorted

  15. 15
    Merge sort is a
    _____
    algorithm, breaking the problem into smaller subproblems.
    Hint

    It splits the list into halves, sorts them, then combines.

    Answer

    divide-and-conquer

  16. 16
    Merge sort has a time complexity of
    _____
    in both best and worst cases.
    Hint

    The list is always split in half and then linearly merged.

    Answer

    O(nlog⁔n)O(n \log n)O(nlogn)

  17. 17
    Quick sort picks a pivot and then
    _____
    the list into two sublists based on that pivot.
    Hint

    Elements are rearranged so that all less than pivot come before it.

    Answer

    partitions

  18. 18
    The worst-case time complexity of quick sort is
    _____
    .
    Hint

    Occurs when the pivot is always the smallest or largest element.

    Answer

    O(n2)O(n^2)O(n2)

  19. 19
    Quick sort has a space complexity of
    _____
    while merge sort has a space complexity of O(n)O(n)O(n).
    Hint

    Quick sort can be implemented in-place, but recursion adds stack space.

    Answer

    O(log⁔n)O(\log n)O(logn)

  20. 20
    On average, quick sort is
    _____
    times faster than merge sort when implemented correctly.
    Hint

    The inner loop of quick sort can be highly optimized.

    Answer

    2-3

  21. 21
    Greedy algorithms make the best
    _____
    decision at each step without considering future consequences.
    Hint

    They focus on immediate gain rather than global optimization.

    Answer

    local

  22. 22
    Greedy algorithms are used when finding the
    _____
    solution is computationally infeasible.
    Hint

    They provide a good enough answer when exact optimization is too slow.

    Answer

    optimal

  23. 23
    In the traveling salesman problem, a greedy approach might always choose the
    _____
    unvisited city.
    Hint

    At each step, select the option that minimizes immediate distance.

    Answer

    nearest

  24. 24
    The number of possible routes in the traveling salesman problem with nnn cities is
    _____
    .
    Hint

    Consider permutations of cities, accounting for starting point and direction.

    Answer

    (nāˆ’1)!2\frac{(n-1)!}{2}2(nāˆ’1)!​

1 of 24
Question 1 of 24

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent