breadth-first-search

Is is still considered a BFS algorithm if I modify it A little bit?

Is is still considered a BFS algorithm if I modify it A little bit? Question: So I’m trying to create a program that finds the shortest path from nodeA to nodeB, however, I want to block certain nodes so that it would find another path. I’m not really aiming for an optimal code here I’m …

Total answers: 1

Python code to do breadth-first discovery of a non-binary tree

Python code to do breadth-first discovery of a non-binary tree Question: My problem: I have a known root node that I’m starting with and a specific other target node that I’m trying to find the shortest path to. I’m trying to write Python code to implement the Iterative Deepening Breadth-First Search algo, up to some …

Total answers: 2

python – collect full path till leaf on organization tree

python – collect full path till leaf on organization tree Question: I got organizations tree stored as json { "name": "amos", "direct_reports": [ { "name": "bart", "direct_reports": [ { "name": "colin", "direct_reports": [] }, { "name": "clara", "direct_reports": [] } ] }, { "name": "bravo", "direct_reports": [ { "name": "cupid", "direct_reports": [] }, { "name": …

Total answers: 1

Python: Number of nodes per level in dictionary with breadth-first search

Python: Number of nodes per level in dictionary with breadth-first search Question: Assuming the input d = {‘title’: ‘Root’, ‘children’: [ {‘title’: ‘Child 1′,’children’: [ {‘title’: ‘Grandchild 11’, ‘children’: [ {‘title’: ‘Great Grandchild 111’, ‘children’: []} ]} ]}, {‘title’: ‘Child 2’, ‘children’: [ {‘title’: ‘Grandchild 21’, ‘children’: []} ]}, {‘title’: ‘Child 3’, ‘children’: [ {‘title’: …

Total answers: 1

Find shortest path on graph with 1 character difference

Find shortest path on graph with 1 character difference Question: I have a somewhat complicated question. I am provided a list of words (each word has the same length). I am given two words into my function (StartNode and EndNode) and my task is to find the shortest path between the two (A follow-up would …

Total answers: 1

How do I return the length of the path found by Breadth First Search?

How do I return the length of the path found by Breadth First Search? Question: I’m trying to augment the typical BFS algorithm to also return the length of the path it found. Here’s what I’ve written so far: from collections import deque length = 1 visited = set() q = deque() visited.add("Start") while q: …

Total answers: 1

Shortest path in a grid using BFS

Shortest path in a grid using BFS Question: The grid consists of following items as python list of lists g = [ [‘1’, ‘1’, ‘1’, ‘1’, ‘1’], [‘S’, ‘1’, ‘X’, ‘1’, ‘1’], [‘1’, ‘1’, ‘1’, ‘1’, ‘1’], [‘X’, ‘1’, ‘1’, ‘E’, ‘1’], [‘1’, ‘1’, ‘1’, ‘1’, ‘X’] ] S indicates the start, E indicates the …

Total answers: 2

printing all the edges of a graph in an adjacency matrix in python

printing all the edges of a graph in an adjacency matrix in python Question: How do you print the all the edges of a graph with a given adjacency matrix in python? for example, if 0 is adjacent to 3 and 8, it should print: 0 3 0 8 without repetition I’ve been using Bfs …

Total answers: 4

How to trace the path in a Breadth-First Search?

How to trace the path in a Breadth-First Search? Question: How do you trace the path of a Breadth-First Search, such that in the following example: If searching for key 11, return the shortest list connecting 1 to 11. [1, 4, 7, 11] Asked By: Christopher Markieta || Source Answers: You should have look at …

Total answers: 7