0
0
DSA Typescriptprogramming~5 mins

DFS Depth First Search on Graph in DSA Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main idea behind Depth First Search (DFS) on a graph?
DFS explores as far as possible along each branch before backtracking, visiting nodes deeply before moving to neighbors.
Click to reveal answer
beginner
In DFS, what data structure is commonly used to keep track of nodes to visit next?
A stack is used, either explicitly or via recursion call stack, to remember nodes to visit next in DFS.
Click to reveal answer
beginner
What is the purpose of a 'visited' set or array in DFS?
It prevents revisiting nodes, avoiding infinite loops and repeated work in graphs with cycles.
Click to reveal answer
intermediate
How does DFS differ from Breadth First Search (BFS)?
DFS goes deep into a branch before backtracking, while BFS explores neighbors level by level.
Click to reveal answer
intermediate
What is the time complexity of DFS on a graph with V vertices and E edges?
The time complexity is O(V + E) because each vertex and edge is visited once.
Click to reveal answer
Which data structure is naturally used by DFS to remember nodes to visit?
AHash Map
BQueue
CStack
DPriority Queue
What does DFS use to avoid visiting the same node multiple times?
AVisited set or array
BPriority queue
CSorting nodes
DRandom selection
What is the order of node visiting in DFS?
ALevel by level
BDeep first, then backtrack
CRandom order
DBy node value
What is the time complexity of DFS on a graph with V vertices and E edges?
AO(V + E)
BO(V^2)
CO(E^2)
DO(log V)
Which traversal method explores neighbors level by level, unlike DFS?
ADijkstra's Algorithm
BDepth First Search (DFS)
CBinary Search
DBreadth First Search (BFS)
Explain how DFS works on a graph and why a visited set is important.
Think about how you explore a maze by going deep and marking visited paths.
You got /4 concepts.
    Describe the difference between DFS and BFS in graph traversal.
    Imagine exploring a tree by going down one branch fully vs exploring all neighbors first.
    You got /5 concepts.