Depth First Search (DFS) in Python [Python Maze World- pyamaze]
Vložit
- čas přidán 4. 07. 2024
- Python Maze World
In this series we will learn about different Maze Search Algorithm in Python e.g., Depth First Search (DFS), Breadth First Search (BFS), A-Star Search, Dijkstra's Algorithm and many other possible search and navigation algorithms like Wall Following Robot, Reinforcement Learning, Genetic Algorithm etc.
This video is about Depth First Search (DFS).
(00:00) Intro
(00:32) Graph, Maze and Tree
(02:48) DFS and BFS
(06:23) What is Stack
(07:36) Pseudocode of DFS
(12:07) DFS Implementation in Python
⭐⭐Breadth First Search (BFS) Implementation:
• Breadth First Search (...
⭐⭐A-star (A*) Search Implementation:
• A-Star A* Search in Py...
⭐⭐Comparison of DFS, AFS and A*
• DFS BFS and A* Search ...
⭐⭐Dijkstra's Algorithm:
• Dijkstra Shortest Path...
You can download the package as:
pip install pyamaze
Or you can copy the module code from here:
github.com/MAN1986/pyamaze/bl...
The used demo file is here :
github.com/MAN1986/pyamaze/tr...
How to use pyamaze module:
• Maze Generation and Se...
What is __name__=='__main__':
• [Python Programming Ba...
Here is the Playlist:
• AI Search Algorithms u...
#Python #pyamaze #Python
This was explained perfectly. The graphics and animations were really useful!
Glad it was helpful!
An excellent video my friend. I learned so much! Thank you for such a high quality lesson.
Thank you 🙂
Thank you this is really convenient and brain friendly explanation
You're welcome!
man this is the most usfull video explaining the algorithm thank you❤❤
You're welcome!
This was very helpful. Thank you
Glad it was helpful! 🙂
Amazing Job, Thank you so much
Thank you too!
Great explanation! Appreciate it
Thank you 🙂
thanks a lot, I understood DFS by your video. Esselamu aleykum.
Walaikum Assalam.
@@LearningOrbis how can I transform DFS to maze labrynt robot witn ardunio..ı need algorıthm scheme like your wall follower video.
I would like your implementation to show the generated nodes and visited nodes and also the depth when live, could you tell me how to do it?
this was really well explained in an organized manner, thank you
You're very welcome!
@@LearningOrbis can you tell me how to get the final path (for DFS or BFS)in a matrix form, thanks in advance
By default, without using any algorithm, the pyamaze module gives the path as a dictionary. Moreover the algorithms I coded also calculate the path as sickbay. And you want that as a list.
This is not done in pyamaze module but can be done easily as explained below:
👉 m.path gives the path as Dictionary (m is maze).
👉 Create an empty list (e.g. pathList) for the path as a list. And then add the start cell in that list which is (m.rows,m.cols) by default.
👉 Search for the key (m.rows,m.cols) inside the dictionary m.path and append its value (let's say cell V) in pathList.
👉 Search for the key V inside the dictionary m.path and append its value in pathList.
👉 Repeat the last two steps until the goal cell (1,1) is appended in the list.
Let me know if you have any question.
@@LearningOrbis but I want the path of the BFS and DFS as the maze has multiple paths not a single one
The BFS and DFS functions return the path as dictionary. And then you can apply the above described logic on that dictionary to convert that to list. Does that what you are looking for?
how do i deal with looping in the maze, like a corner where it always turns left ?
thanks for explaining , i have a doubt :
is the order of direction while looping is necessary in case of bfs as well??
Thank you so much for this nice work!!!!
You're very welcome!
@@LearningOrbis I am watching the other two tutorials on BFS and dijkstra search now. Thanks again for your detailed and patient demonstration:)
Thanks for the compliment :)
this is very ell explained! How would i implement an iterative deepening depth first search? From my understanding I would need a depth counter. I'm new to python and would really appreciate some help!
Thanks.
DFS uses a stack and BFS uses a queue. IDDFS uses primarily the DFS approach but it puts a limit on maximum depth and after that, it searches in Breadth.
I will try to develop its logic but after a couple of weeks. You can try it and share the result with me.
@@LearningOrbis Have you had the chance to do it?
good
Thanks 🙂
How do we get the csv file, is it like hardcoded?
Code can generate a random maze and we can Export that maze as CSV file. Later we can load that CSV file if we want to work on the same maze.
Please watch the first video in playlist:
czcams.com/video/McMU-WuJwG0/video.html
the code for dfs is not working , its showing that it cannot find the key value
Have you tried this code:
github.com/MAN1986/pyamaze/tree/main/Demos/DFS
can we implement this code to java?ı mean ı want to create a random maze with java but ı cant find any resource to learn that
Of course we can but there is no direct way. I have provided the GitHub link to code and you need to understand that and implement the same in Java
Very informative. Thanks for sharing. Please, I have a question relating to this topic and would like to contact you. How do I reach you? Thanks
Thanks.
You can contact me at mahsan.naeem@gmail.com
What if middle of the map is the starting node?
This should work.
You can set the starting point as any cell. Please watch this video for detail: czcams.com/video/McMU-WuJwG0/video.html
bro code is not working help me out.
Which code you tried?
very well eplained but can you make this same playlist but without using the "maze" for the explanation... im having hard time merging these two together because in my academics only graphs are mentioned.... please..................................make one without mazes....
I have explained the relation between Maze and Graph. It will be very hard to design new GUI and graphics for Graph.
@@LearningOrbis 🥲 Noo no like that.. i wan you to explain it using python dictionary like A node has b & c like that... No need of new gui