Graph Algorithms Interview Course
- 44Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
44 questions
- 1A graph is defined as a collection of_____and edges.
Hint
Think about what the circles represent in a graph diagram.
Answer
nodes
- 2Another term for a node in a graph is_____.
Hint
This word is often used interchangeably with 'node' in graph theory.
Answer
vertex
- 3In a graph, a_____is a connection between two nodes.
Hint
Think of it as a line or arrow connecting two circles.
Answer
edge
- 4A 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
- 5In an undirected graph, edges have no_____and allow movement in both directions.
Hint
Think of it as a two-way street.
Answer
directionality
- 6A 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
- 7The 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
- 8In 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
- 9A 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
- 10A 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
- 11In 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
- 12A 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
- 13In 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
- 14In 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
- 15In 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
- 16The 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
- 17In 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
- 18The 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
- 19For 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
- 20When 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
- 21To 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
- 22In 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
- 23The 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
- 24To 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
- 25In 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
- 26The connected components count function returns a_____representing the number of components.
Hint
This is the final output of the problem.
Answer
number
- 27In the largest component problem, you track the_____size of any component encountered.
Hint
Think about the opposite of minimum.
Answer
maximum
- 28In 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
- 29The 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
- 30In 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
- 31If 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
- 32In 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
- 33In 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
- 34The time complexity of an island count algorithm on an r×c grid is O(_____).
Hint
Consider the total number of cells that might be processed.
Answer
r×c
- 35In 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
- 36When 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
- 37In 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
- 38The 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
- 39A 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
- 40An acyclic graph is one that contains no_____.
Hint
This property prevents infinite traversals.
Answer
cycles
- 41When analyzing graph algorithm complexity with a single variable n (number of nodes), the worst-case number of edges is O(_____).
Hint
Consider the maximum number of distinct pairs of nodes.
Answer
n2
- 42In 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
- 43In 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
- 44In 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

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