Graph traversal (BFS vs DFS) Quiz

Test your understanding of key concepts in graph traversal, including the differences between Breadth-First Search (BFS) and Depth-First Search (DFS), level-order tree traversals, shortest paths in unweighted graphs, and the use of visited sets, queues, and stacks. This quiz is perfect for anyone wanting to refresh or assess their foundational knowledge of graph algorithms.

  1. Identifying BFS Strategy

    Which traversal method visits all nodes at the same depth in a tree before moving to the next level, for example, starting at the root and visiting all immediate children before any grandchildren?

    1. Depth-First Search (DFS)
    2. Dijkstra's Search
    3. Breadth-First Search (BFS)
    4. Prim's Algorithm
  2. Key Data Structure for BFS

    What data structure is typically used to keep track of the next node to visit in Breadth-First Search (BFS)?

    1. Set
    2. Queue
    3. Stack
    4. Priority queue
  3. DFS Exploration Order

    In Depth-First Search (DFS), which data structure's behavior most closely matches the traversal order, as in exploring as deep as possible before backtracking?

    1. Heap
    2. Queue
    3. Array
    4. Stack
  4. Level Order Traversal Identification

    Which graph traversal method gives you a level-order traversal of a tree, listing nodes level by level starting from the root?

    1. Breadth-First Search (BFS)
    2. Topological Sort
    3. Binary Search
    4. Depth-First Search (DFS)
  5. Finding Shortest Path in Unweighted Graphs

    What is the most efficient algorithm for finding the shortest path from one node to another in an unweighted graph?

    1. Greedy Search
    2. Insertion Sort
    3. Breadth-First Search (BFS)
    4. Depth-First Search (DFS)
  6. Purpose of a Visited Set

    In both BFS and DFS, why is it important to keep a visited set or array when traversing a graph?

    1. To count the total number of edges
    2. To avoid visiting the same node multiple times
    3. To ensure nodes are traversed in alphabetical order
    4. To speed up the sorting process
  7. Time Complexity for BFS and DFS

    What is the worst-case time complexity for both BFS and DFS when represented with adjacency lists in a graph with V vertices and E edges?

    1. O(V^2)
    2. O(V + E)
    3. O(V * E * logV)
    4. O(E^2)
  8. Space Usage in BFS vs DFS

    When traversing a tree with many leaves at the bottom level, which traversal method, BFS or DFS, tends to use more memory?

    1. Neither uses memory
    2. BFS uses more memory
    3. Both use the same memory
    4. DFS uses more memory
  9. DFS Behavior on Cyclical Graphs

    What might happen if you perform DFS on a graph with cycles and do not use a visited set?

    1. All nodes will still be visited exactly once
    2. The algorithm will run faster
    3. The algorithm may enter an infinite loop
    4. Nodes will be visited in sorted order by value
  10. Initial Step for Graph Traversals

    When beginning either BFS or DFS on a graph, which is the standard first step?

    1. Create a list of all possible paths
    2. Mark the starting node as visited and add it to the data structure
    3. Remove all edges from the graph
    4. Sort all nodes by value