Depth First Search Algorithm

Go GATE IIT · 1.8M views · 2013 · 3:47

Open on YouTube

Algorithms & data structuresEducation & learningtutorial

Why Stack Overflow recommends it

Stack Overflow users link it as a quick visual explanation of how DFS works when answering or asking about graph traversal, maze solving and connected components.

Recommended by 3 people across 3 different months, 2016 to 2019.

What it is

A short 2013 whiteboard-style walkthrough of the depth first search graph traversal algorithm from the Go GATE IIT channel. It shows how DFS uses a stack, steps through a sample graph, and notes the O(V + E) time complexity with an adjacency list.

What people said

Recommends VRage · 2016-05 · Stack Overflow · on “Solving a maze using depth first search algorithm”

I dont want to post a new answer because yours is imo the correct one. @Henry in addition take a look at this video: [this video] and skipt to 3:00 see that stack on the right side, it is exactly the path he went throuh to get to Node F ... Just for visualisation

Recommends Vicky · 2017-04 · Stack Overflow · on “Depth-first search (DFS) code in python”

Hi Willem, if you checkout the link [LINK] there a sample code for the DFS is given but If I change the graph as given in youtube tutorial " [this video] " I am not getting the result as mentioned. So I thought of writing my own version based on the tutorial.

Recommends Patrick · 2019-01 · Stack Overflow · on “Efficient algorithm to find connected components”

Short version I think a Depth-First-Search algorithm might help you. In your case, each tile can be seen as a node of a graph and an edge exist between two nodes if they share a side or a corner. A nice video explaining how that algorithm works I found is here: Depth First Search on youtube [this video] The DFS algorithm is probably very similar to what you attempted with your recursive method, the key difference however is that you "color" the nodes/tiles you visit as you progress in the algorithm. Rather than keeping the explored nodes in a seperate data structure, I would suggest you to make it a property of each of your tiles. Then if you stumble on a tile which you already visited, you do no

Cites C. Tindall · 2018-04 · Stack Overflow · on “Initialize classes from POST JSON data”

Instead of having one master method to turn any arbitrary JSON into an arbitrary hierarchy of Python objects, the typical pattern would be to create a Django model for each type of thing you are trying to model. Relationships between them would then be modeled via relationship fields [LINK] (ForeignKey, ManyToMany, etc, as appropriate). For instance, you might create a class Employee that models an employee, and a class Paycheck . Paycheck could then have a ForeignKey field named issued_to that refers to an Employee . Note also that any scheme similar to the one you describe (where user-created JSON is translated directly into arbitrary Python objects) would have security implications, poten

Cites user2709168 · 2018-12 · Stack Overflow · on “Depth-first traversal of a directed graph”

I have an assignment where I have to write a method that performs a DFT of a directed graph. Here are the directed edges: Node 1-->Node 2, Node 3 Node 2 -->Node 4 Node 3 -->Node 5 Node 4-->Node 5 From my understanding, after watching this video [this video] , doing a DFT of the above graph starting from Node 1 would output 1, 2, 4, 5, 3. My reasoning for this is that when looking at 1's edges, 2 would naturally come before 3, and then progresses linearly until it arrives at 5. Since 5 doesn't have any other edges besides it's connection to 4, the traversal would "unwind" back to Node 1, after which it would output Node 3. However, the assignment is expecting the output 1, 3, 5, 4, 2. Where is the