Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

depth first search

BFS-> uses queue
DFS-> uses stack or recursion (less code)
NOTE: same idea algo wise for both

IDEA:
1 declare the DS(if bfs-DS will be queue,if dfs-stack)
2 push the start node to DS
3 when you push you mark it as visited
4 until the DS is not empty run a loop
5 inside loop pop the DS(deque for queue or pop for stack) and save it in a new object actual
6 loop through the neighbors of actual
7 if the current neighbor n is not visited
8 then push n in DS
9 mark n as visited in the next line.
 
PREVIOUS NEXT
Tagged: #depth #search
ADD COMMENT
Topic
Name
8+7 =