1. Home
  2. Explore
  3. Computer Science
  4. Graph Algorithms Interview Course

Study methods

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

Graph Algorithms Interview Course

  • 44Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Graph Basics
A graph is defined as a collection of
and edges.

44 questions

  1. 1
    A graph is defined as a collection of
    _____
    and edges.
    Hint

    Think about what the circles represent in a graph diagram.

    Answer

    nodes

  2. 2
    Another term for a node in a graph is
    _____
    .
    Hint

    This word is often used interchangeably with 'node' in graph theory.

    Answer

    vertex

  3. 3
    In a graph, a
    _____
    is a connection between two nodes.
    Hint

    Think of it as a line or arrow connecting two circles.

    Answer

    edge

  4. 4
    A graph with arrowheads on its edges is called a
    _____
    graph.
    Hint

    The arrowheads indicate that movement is only allowed in one direction along the edge.

    Answer

    directed

  5. 5
    In an undirected graph, edges have no
    _____
    and allow movement in both directions.
    Hint

    Think of it as a two-way street.

    Answer

    directionality

  6. 6
    A node that is directly reachable from another node via an edge is called a
    _____
    node.
    Hint

    In a graph, nodes that are connected by an edge are often called this.

    Answer

    neighbor

  7. 7
    The most common way to represent a graph in code is using an
    _____
    list.
    Hint

    This data structure maps each node to a list of its neighbors.

    Answer

    adjacency

  8. 8
    In an adjacency list, even if a node has no neighbors, it should still appear as a
    _____
    .
    Hint

    Think about what is needed to ensure all nodes are included in the representation.

    Answer

    key

  9. 9
    A depth-first traversal uses a
    _____
    data structure to determine the order of visiting nodes.
    Hint

    This data structure follows a LIFO (last in, first out) principle.

    Answer

    stack

  10. 10
    A breadth-first traversal uses a
    _____
    data structure to explore nodes level by level.
    Hint

    This data structure follows a FIFO (first in, first out) principle.

    Answer

    queue

  11. 11
    In a depth-first traversal, you explore one direction as far as possible before
    _____
    directions.
    Hint

    Think about the behavior of going deep first then laterally.

    Answer

    switching

  12. 12
    A breadth-first traversal explores all nodes
    _____
    away from the starting node before moving to nodes two edges away.
    Hint

    Think about the level-by-level exploration pattern.

    Answer

    one edge

  13. 13
    In a recursive depth-first traversal, the
    _____
    stack is used implicitly.
    Hint

    This stack is automatically maintained by the programming language when functions call themselves.

    Answer

    call

  14. 14
    In an iterative depth-first traversal, you use
    _____
    and pop operations on a stack.
    Hint

    These two operations are used to add and remove items from the stack.

    Answer

    push

  15. 15
    In an iterative breadth-first traversal, you use shift to remove from the front and
    _____
    to add to the back of the queue.
    Hint

    Think about the array methods that mimic queue behavior.

    Answer

    push

  16. 16
    The hasPath problem on a directed acyclic graph can be solved using either depth-first or
    _____
    traversal.
    Hint

    Both traversal orders can be used to search for a path, but one might be preferred for shortest path.

    Answer

    breadth-first

  17. 17
    In the hasPath recursive solution, the base case returns
    _____
    if the current node equals the destination.
    Hint

    Think about when you have successfully found the target.

    Answer

    true

  18. 18
    The time complexity of the hasPath algorithm is O(
    _____
    ) where E is the number of edges.
    Hint

    Consider how many edges you might need to traverse in the worst case.

    Answer

    E

  19. 19
    For an undirected path problem, you must first convert the edge list into an
    _____
    list.
    Hint

    This conversion makes it easier to perform traversals.

    Answer

    adjacency

  20. 20
    When building an adjacency list for an undirected graph, for each edge you must add the connection in
    _____
    directions.
    Hint

    Think about the symmetric nature of undirected edges.

    Answer

    both

  21. 21
    To avoid infinite loops in an undirected graph traversal, you need to track
    _____
    nodes.
    Hint

    This set prevents reprocessing nodes that have already been explored.

    Answer

    visited

  22. 22
    In the undirected path solution, if a node has already been visited, the recursive call returns
    _____
    .
    Hint

    Think about what value indicates that no new path is found from this node.

    Answer

    false

  23. 23
    The space complexity of the undirected path solution is O(
    _____
    ) where N is the number of nodes.
    Hint

    Consider the storage needed for the visited set and the recursion stack.

    Answer

    N

  24. 24
    To count connected components, you iterate through each node and start a traversal only if the node is
    _____
    .
    Hint

    This ensures you only explore new components, not ones already counted.

    Answer

    unvisited

  25. 25
    In the connected components count algorithm, after completing a traversal of a new component, you increment the
    _____
    by one.
    Hint

    This variable tracks the total number of components found.

    Answer

    count

  26. 26
    The connected components count function returns a
    _____
    representing the number of components.
    Hint

    This is the final output of the problem.

    Answer

    number

  27. 27
    In the largest component problem, you track the
    _____
    size of any component encountered.
    Hint

    Think about the opposite of minimum.

    Answer

    maximum

  28. 28
    In the recursive solution for largest component, you initialize size to
    _____
    to count the current node.
    Hint

    Think about how to include the current node in the count.

    Answer

    1

  29. 29
    The shortest path problem in an unweighted graph is best solved using
    _____
    -first search.
    Hint

    This algorithm explores nodes in order of increasing distance from the start.

    Answer

    breadth

  30. 30
    In the shortest path BFS, you store each node in the queue along with its
    _____
    from the start.
    Hint

    This number increases as you go further from the source.

    Answer

    distance

  31. 31
    If the queue becomes empty in the shortest path BFS and the destination was never reached, you should return
    _____
    .
    Hint

    This is a common sentinel value indicating no path exists.

    Answer

    -1

  32. 32
    In a grid graph, a node's neighbors are the positions
    _____
    down, left, and right from it.
    Hint

    Think about the four cardinal directions.

    Answer

    up

  33. 33
    In island count, you only start a traversal if the current cell is land and has not been
    _____
    .
    Hint

    This prevents counting the same island multiple times.

    Answer

    visited

  34. 34
    The time complexity of an island count algorithm on an r×cr \times cr×c grid is O(
    _____
    ).
    Hint

    Consider the total number of cells that might be processed.

    Answer

    r×cr \times cr×c

  35. 35
    In the minimum island problem, you compare each island's size to a
    _____
    variable and update if smaller.
    Hint

    Think about tracking the smallest value.

    Answer

    minimum

  36. 36
    When building an adjacency list for an undirected graph from an edge list, you must ensure the adjacency is
    _____
    (both directions).
    Hint

    This property means if A is connected to B, then B is also connected to A.

    Answer

    symmetric

  37. 37
    In the hasPath problem, if no neighbor returns true after checking all, the function returns
    _____
    .
    Hint

    This indicates that no path exists from the current node to the destination.

    Answer

    false

  38. 38
    The iterative breadth-first traversal code is almost identical to depth-first except you use shift instead of
    _____
    .
    Hint

    These two array methods differ in which end they remove from.

    Answer

    pop

  39. 39
    A cycle in a graph is a path that starts and ends at the same
    _____
    .
    Hint

    Think about a loop that returns to the origin.

    Answer

    node

  40. 40
    An acyclic graph is one that contains no
    _____
    .
    Hint

    This property prevents infinite traversals.

    Answer

    cycles

  41. 41
    When analyzing graph algorithm complexity with a single variable nnn (number of nodes), the worst-case number of edges is O(O(O(
    _____
    ))).
    Hint

    Consider the maximum number of distinct pairs of nodes.

    Answer

    n2n^2n2

  42. 42
    In the connected components count code, you use a
    _____
    to mark nodes as visited.
    Hint

    This data structure provides O(1) lookup and addition.

    Answer

    set

  43. 43
    In JavaScript, when storing positions in a visited set for a grid, you should use a
    _____
    representation like "r,c" to avoid reference equality issues.
    Hint

    This primitive type works with Set has() correctly, unlike arrays.

    Answer

    string

  44. 44
    In the breadth-first shortest path algorithm, you mark a node as visited when it is
    _____
    to the queue.
    Hint

    This prevents multiple enqueues of the same node.

    Answer

    added

1 of 44
Question 1 of 44

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent