Skip to content
Advertisement

Tag: depth-first-search

Python DFS nested dictionary

I’ve written a function which should be able to search a nested dictionary, using DFS, to find a specific value. The recursive element seems to be working fine, however, when the base case should return True, it simply doesn’t. And the results. As you can see, the standard output “i==i” shows that this element was evaluated correctly but the return

Is it possible to do a depth first search iteratively without copying visited nodes?

Background I am searching a 2D grid for a word. We can search left/right and up/down. For example, in this grid, searching for “abef” starting at (0,0) will return True Example (grid1): Where I’m at The recursive version gives expected results (see dfs_rec() below). The iterative version also gives expected results (see dfs_iter() below). However, in this version I am

Python3 running the same function with the same input many times but producing different outputs every time

I am currently trying to solve a simple version of checkers with python. Specifically, I am trying to solve the problem “checkers” from USACO 2008 December Bronze contest. (Problem Link) My idea is to run a recursive dfs function on the location of each of the kings. However, I have encountered some issues with my dfs function. When I run

Advertisement