Deep
Dive — DFS Search
“Scan every ping — the shark can’t hide forever.”
Challenge:
The shark is hiding somewhere in a tree of sonar pings. Use
Depth-First Search
to scan the tree and find the shark fast.
Sonar Station • Tree Traversal
Task:
Implement
dfs_search(root)
to perform a
preorder
depth-first traversal.
Return a list of node
values
in the order visited.
Click
Run Unit Tests
. If all tests pass, you'll get the flag.
def dfs_search(root): # Your code here visited = [] return visited # Test runner do not edit below run_selected_test()
Run Unit Tests
Output or flag will appear here...