Skip to content

Breadth First Search and Depth First Search implementation in python.

License

Notifications You must be signed in to change notification settings

hassanzadehmahdi/BFS-and-DFS-Algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

BFS-and-DFS-Algorithms

Breadth First Search and Depth First Search implementation in python.

BFS Algorithm

The steps of the algorithm work as follow:

 1.Start by putting any one of the graph’s vertices at the back of the queue.
 2.Now take the front item of the queue and add it to the visited list.
 3.Create a list of that vertex's adjacent nodes. 
  Add those which are not within the visited list to the rear of the queue.
 4.Keep continuing steps two and three till the queue is empty.

DFS Algorithm

The DSF algorithm follows as:

1.We will start by putting any one of the graph's vertex on top of the stack.
2.After that take the top item of the stack and add it to the visited list of the vertex.
3.Next, create a list of that adjacent node of the vertex. 
  Add the ones which aren't in the visited list of vertexes to the top of the stack.
4.Lastly, keep repeating steps 2 and 3 until the stack is empty.

The graph that we used

10

The result

52

The description was from favtutor.com.

Releases

No releases published

Packages

No packages published

Languages