DEV Community 👩‍💻👨‍💻

Justin Bermudez
Justin Bermudez

Posted on

Depth-First Search (DFS) with Python

Given a Node class that has a name and array of optional children nodes. When put together, these nodes form a tree-like structure.

class Node:
    def __init__(self, name):
        self.children = [] = name
    def addChild(self, name):
        return self
    def depthFirstSearch(self, array):
        for child in self.children:
        return array

Top comments (0)

Let's Get Hacking

Join the DEV x Linode Hackathon 2022 and use your ingenuity and creativity to build using Linode.

Join the Hackathon <-