2,257 questions
3
votes
1
answer
139
views
How can I efficiently parallelize and optimize a large-scale graph traversal algorithm in Python to handle millions of nodes?
I'm working on Python project that involves processing a very large graph - it has millions of nodes and edges. The goal is to perform a breadth-first search (BFS) or depth-first search (DFS) from a ...
1
vote
1
answer
81
views
Implementing Breadth First Search from CLRS
At my wits end here. I'm following this psuedocode from CLRS and I don't know why my final for loop doesn't keep going to give me the distance from the given source node to all other vertices. I'm so ...
0
votes
1
answer
122
views
Stack Overflow with BFS LISP
I have created a search function following the BFS algorithm but found a problem, it works fine on other problem domains but on this problem domain I am only getting stack overflows.
This specific ...
1
vote
1
answer
75
views
go - LeetCode Time limit exceeded on Graph question 2493
Here's a link to the actual question.
Here's a link to the full code on Go Playground, with some test cases that return the correct result
My code is correct, just slow it seems? I'm not a programmer ...
0
votes
1
answer
68
views
DFS-compatible coordinate-free neighbors in Haskell
I've recently found myself solving a lot of 2D matrix search problems. A typical approach looks like the skeleton below, which searches for a word along 4-directionally connected paths in a 2D array:
...
3
votes
1
answer
189
views
String representation of a tree (nodes) data structure with paths from left to right
Given a tree-like data structure of nodes with each node having a property children that contains the children nodes from left to right, I wish to create a string representation of this data structure ...
1
vote
1
answer
113
views
Is BFS and a Tree Data Structure Sufficient for Comparing if two Trees are Structurally Equal?
I’m working on a problem where I need to compare multiple lineages (family trees) to check if they are structurally identical. Each lineage starts from a single root (ancestor) and extends downwards. ...
0
votes
0
answers
82
views
Find all spanning trees using BFS
While trying to find all spanning trees using the queue, I came to the conclusion that it would be logical to search edges. If there is no new edge in the tree, I add the edge to the tree and put the ...
0
votes
1
answer
96
views
Splitting dag dependencies in python
Splitting dag dependencies in Python
I tried implementing a script for splitting dag dependencies, my goal is to split the node dependencies so that for each node that has more then one dependency, I ...
2
votes
0
answers
73
views
How do i iteratively traverse directory and parse it into struct in rust?
with some help, i was able to traverse directory and parse it into Collection struct recursively like this
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Collection {
pub relative_path:...
2
votes
1
answer
80
views
Depth First Search Time Complexity
Below is Python code for a depth search algorithm.
def add_edge(adj, s, t):
# Add edge from vertex s to t
adj[s].append(t)
# Due to undirected Graph
adj[t].append(s)
print('adj add ...
3
votes
2
answers
160
views
Space Complexity of Dijkstra
I was working on some Leetcode questions for Dijkstra's algorithm and I do not quite understand the space complexity of it. I looked online but I found various answers and some were rather complicated ...
0
votes
2
answers
90
views
Why do I get this error when trying to solve problem 133 on LeetCode?
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> neighbors;
Node() {
val = 0;
neighbors = vector<Node*>();
}
Node(int _val) {
...
0
votes
0
answers
73
views
Why use two arrays of insertion_time and lowest_insert_time in Tarjans algorithm for Bridges in Graph? [duplicate]
I've been working on the LeetCode problem 1192. Critical Connections in a Network. From various sources, I have the following code:
class Solution {
int timer = 1;
void dfs(int node, int ...
2
votes
0
answers
126
views
Are BFS and DFS the same and just the Monad is different?
I wrote a tail-recursive BFS in Scala:
import scala.collection.mutable
/** Do BFS from start and return the smallest distance to end (None if not connected) */
def bfs[A](start: A, end: A, neighbors: ...
2
votes
2
answers
103
views
Leetcode 417 BFS Time Limit Exceeded
I am working on Leetcode 417 Pacific Atlantic Water Flow:
There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and ...
1
vote
0
answers
41
views
Depth Search between CFGs in BFS algorithm using python with LLVM IR
Context: I am trying to find out the depth between two CFGs using BFS but the code is not properly working as it's only showing the results up to depth 0 and 1 but it's not showing the other depths ...
1
vote
1
answer
79
views
Nearest exit from an entrance in a maze
I am trying to solve the following question
https://leetcode.com/problems/nearest-exit-from-entrance-in-maze/?envType=study-plan-v2&envId=leetcode-75
This is my approach
def insidemaze(r,c,nrow,...
2
votes
2
answers
409
views
BFS implementation takes too much time for CSES labyrinth problem
I am trying to solve the CSES Labyrinth problem:
You are given a map of a labyrinth, and your task is to find a path from start to end. You can walk left, right, up and down.
Input
The first input ...
1
vote
2
answers
109
views
BFS implementation for leetcode problem fails one test case
I am trying to solve a LeetCode problem (1219. Path with Maximum Gold) with BFS approach
Statement:
In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of ...
0
votes
1
answer
29
views
Level Order Insertion on an Orderless tree
I am attempting to use breadth first search to add to a node to an orderless tree
Tree: Unordered
Node: Each node groups together 3 datapoints, which are usernames
Children: 3 nodes
My current code is ...
0
votes
3
answers
171
views
How to reconstruct the shortest path with BFS (Javascript) for Knight chess piece?
I'm currently working for a project with TOP and I'm asked to find the shortest path between 2 squares with a Knight on a 8x8 chessboard. Imagine I want to go from 0,0 to 7,7, my algo need to return ...
0
votes
1
answer
171
views
DFS (Depth-first search) vs BFS (Breadth-first search) Space Optimizations
Problem
I am currently digging deep into some optimizations on the classical iterative approaches to both DFS and BFS algorithms. The material I'm currently using at my University presents both ...
-1
votes
1
answer
75
views
Why DFS and not BFS for finding cycle in graph [duplicate]
Give the reasons for the above my query
I find the above questions of the traverse of graph. Bfs and DFS both are the traverse to detect the cycle in a graph but most is the dfs why this is the best ...
-2
votes
1
answer
88
views
Undirected Graph, get list of all nodes that can be visited
I am new into graph theory I have this, problem I have a graph that will be diferent each time, I want to know if there is an algorithm to know from a random node which nodes I can visit, this ...