#(daxz_) can someone explain DFS in denizen terms

27 messages · Page 1 of 1 (latest)

mild halo
#

trying to understand this for c++, might be easier to understand in denizen

onyx wadiBOT
#

(daxz_) can someone explain DFS in denizen terms

onyx wadiBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
You can block this bot if you don't want to see these messages, I won't mind.
<@&525394568410038282>

compact moss
#

nah,but I can draw a picture, hold on

#

nvm, here's one I found

#

DFS -> go down as far as you can, then back up to the last split, then down far as you can again
BFS -> Go "layer by layer"

mild halo
#

denizen code

compact moss
#

dang, not from my phone. but what part are you struggling on?

#

pretty much in both cases, you'd recursion though. it's just an ordering thing. whether you check each item in a layer first, or if you look at the children's children's children's... first

#

I can. write some pseudo code though

#
function depthfirst(search, node)
  if node == search then return node end
  foreach node.children() as child do
    result = depthfirst(search, node.child)
    if result then return result end
  end
end```
rich bane
#

imagine you have a map of maps of maps

#

Depthfirst is like

- foreach (map):
  - foreach <[value]>:
    - foreach <[value]>:
      - if thing == result:
        - stop
```?
#

this uhh

#

doesn't work really great as a denizen example because Denizen doesn't really operate under the the same data structures lol

rugged mango
#

@pure zinc explain depth first search and provide a working code example

pure zincBOT
# rugged mango <@1109134469836841091> explain depth first search and provide a working code exa...

Depth First Search (DFS) is a graph traversal algorithm used to traverse through graphs where edges may connect nodes in arbitrary directions. It starts at a given node and explores its neighboring nodes by visiting them before backtracking to explore other paths. Here’s how DFS works:

def dfs(graph):
    visited = set() # Set to keep track of already visited nodes
    
    # Start at root node
    current_node = graph[0]
    print(current_node)
    
    while len(visited) \< len(graph):
        # Mark the current node as visited
        visited.add(current_node)
        
        # Explore all neighbors of the current node
        for neighbor in graph[current_node]:
            if neighbor not in visited:
                # Visit the unexplored neighbor
                print(neighbor)
                
                # Recursively call DFS on the new node
                dfs(graph[neighbor])
            
        # Move to next unexplored node
        current_node = neighbor

In this example, we start at the root node and recursively call DFS on all its neighbors until no more unexplored nodes remain. We use a set called visited to keep track of which nodes have been explored.

compact moss
#

What the hek is \<? Is that supposed to be not equals?

rugged mango
compact moss
#

Ahh gotcha

haughty wagon
#

most intriguing