Skip to main content
Filter by
Sorted by
Tagged with
2 votes
2 answers
112 views

I'm working on implementing the iterative (non-recursive) version of dfs. I'm confused when to mark a node as visited: at push or at pop. In bfs, we mark visited when pushing it to queue, so it seems ...
jeremy0519's user avatar
Advice
0 votes
2 replies
37 views

I'm in college learning about DFS and BFS. I knew about this before, although what's throwing me in a loop is DFSVisit. I just want to know what's the difference between DFS and DFSVisit. Is DFS just ...
Johanna's user avatar
0 votes
1 answer
36 views

I have a graph-based travel system where each city has two stations: a bus station and a train station. Each station is represented as a node (Node), and each connection/departure is represented as an ...
SP222's user avatar
  • 21
0 votes
0 answers
50 views

Suppose I have a complete, perfect binary tree stored in an array. If I store node data in breadth-first traversal order (Eytzinger order), then if an internal node's index is i, its left and right ...
Alec Jacobson's user avatar
7 votes
1 answer
105 views

I'm working on the following problem: Given an undirected graph G = (V, E), represented as an adjacency list, design an efficient algorithm to construct a subgraph H = (V, E') such that: E' is a ...
Johann Carl Friedrich Gauß's user avatar
3 votes
1 answer
156 views

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 ...
ThatsNotAbhinit's user avatar
0 votes
1 answer
82 views

I'm trying to detect cycles in a directed graph using a DFS-based approach in Java. I implemented a solution that uses a visited[] array and builds map from the input edge list. It seems to work ...
Игорь Райский's user avatar
1 vote
1 answer
135 views

I am trying to solve the CSES challenge Labyrinth: Labyrinth 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 ...
shubham kakade's user avatar
6 votes
4 answers
419 views

The problem I am trying to solve a competitive programming problem which goes like that: Given an m x n rectangular grid, what the maximum number of cars than can be parked (each car takes 1 cell) so ...
Andrey Surovtsev's user avatar
-2 votes
1 answer
142 views

I am having a hard time understanding the time complexity for the solution to the following LeetCode problem 329. Longest Increasing Path in a Matrix: Given an m x n integers matrix, return the ...
bourne's user avatar
  • 1,259
0 votes
1 answer
52 views

I am currently working on leetcode 994. Rotting Oranges. Where the description is given as follows: You are given an m x n grid where each cell can have one of three values; 0 represents an empty ...
WaterDrop's user avatar
  • 168
0 votes
1 answer
90 views

I have a DFS maze generation algorithm implementation in c++ that seems to consistently create multiple distinct areas. The maze is represented as a 2d vector of Node objects, which create a connected ...
isaa_ctaylor's user avatar
2 votes
2 answers
92 views

I use scipy version 1.14.1 to traverse the minimum spanning tree in depth-first order, but I do not understand some results, namely the predecessors returned by scipy are not correct. Here is an ...
user11634's user avatar
  • 306
0 votes
2 answers
119 views

In an m x n matrix consisting of 0s and 1s, we are tasked with counting the 4-directionally connected islands of 1s. A python implementation is as follows: def numIslands(grid): def sink(i,...
Brendan Langfield's user avatar
0 votes
1 answer
71 views

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: ...
Brendan Langfield's user avatar
2 votes
1 answer
104 views

I'm working on a depth first search of a weighted graph from an adjacency list. I know that technically weighted shouldn't make a difference here, but it does in how my vectors are setup and I'm not ...
Christian Tallet's user avatar
0 votes
1 answer
292 views

I was solving LeetCode problem 3290. Maximum Multiplication Score: You are given an integer array a of size 4 and another integer array b of size at least 4. You need to choose 4 indices i0, i1, i2, ...
souparno majumder's user avatar
0 votes
1 answer
107 views

Cormen, Leiserson, Rivest, and Stein (CLRS) give (section 22.3) a recursion-based implementation of DFS that not only adds parent data u.parent to each node u along the way but also timestamp fields u....
tarski's user avatar
  • 249
3 votes
1 answer
196 views

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 ...
Gigi Bayte 2's user avatar
  • 1,024
0 votes
1 answer
49 views

I am reading the paper Identifying Loops Using DJ Graphs by Sreedhar et al. In this paper, they present the following classification of edges in a depth first search ordering of a graph (specifically ...
Etten Moor's user avatar
0 votes
1 answer
152 views

I have a Shapely multiline string that has multiple branches that I want removed. I've attached an image where the red is the main line that I want to keep and the black are to be removed. I can't ...
nworbi's user avatar
  • 29
1 vote
2 answers
121 views

Consider the following polymorphic DFS function from here: -- | Depth-first search. -- -- Generates the list of unique visited states from a -- given starting state. States are unique up to the -- ...
Brendan Langfield's user avatar
0 votes
0 answers
45 views

I have written this code for the problem "Draughts" of codechef but only few testcases are getting passed. Can anyone tell what is the error in my logic? Furik and Rubik have come to the ...
Tapananshu Gandhi's user avatar
-1 votes
2 answers
109 views

I'm trying to find a non-recursive "powerful/versatile" tree walker algorithm, ultimately yielding not just the node but the depth of the node, its parent and its sibling index, and able to ...
mike rodent's user avatar
  • 16.1k
-1 votes
1 answer
107 views

I'm trying to run DFS on this 8 puzzle solver. the initial state is like this: 1 4 2 3 _ 5 6 7 8 where '_' represents a space. the goal state is this (formatted in my code as _12345678): _ 1 2 3 4 5 ...
j k's user avatar
  • 19
0 votes
2 answers
88 views

This may be a dumb question so I am sorry, but there is a Leetcode problem where you have to return all of the paths from the root node to leaf nodes in an array of strings connected with "->&...
Mike Carpinello's user avatar
2 votes
1 answer
83 views

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 ...
Palavi Rajgude's user avatar
0 votes
0 answers
51 views

In the following script, my current problem is with "CanDisableSkill()" That's called for the purpose to check if the node is inside a closed cycle of turned on nodes. Which in that case you ...
RiP Hunt's user avatar
1 vote
0 answers
183 views

I am working on a problem where I need to detect cycles in a directed graph. The graph is represented using an adjacency list, and it can have a large number of nodes and edges. I am looking for the ...
user25350358's user avatar
0 votes
1 answer
50 views

I'm working on a DFS algorithm to traverse an 8x8 matrix where I need to alternate between addition and subtraction while updating the maximum values for each cell. But it is not working as I want it ...
Muzaffer Eyvazov's user avatar
0 votes
0 answers
51 views

On a binary matrix M, a cyclic island is a region of 1s where the region encircles itself (horizontal, vertical and cross directions are allowed) Given a matrix M, Allowing neighbors to be in any of ...
Semzem's user avatar
  • 93
2 votes
1 answer
107 views

I am trying to solve LeetCode problem 1653. Minimum Deletions to Make String Balanced: You are given a string s consisting only of characters 'a' and 'b'​​​​. You can delete any number of characters ...
Vanillaice's user avatar
1 vote
0 answers
63 views

Are either of these more efficient or standard/readable? This is assuming that visited is not always empty/all False. The second option seems to do less checks: I wrote how many checks take place for ...
Sameem's user avatar
  • 11
1 vote
1 answer
55 views

The problem is from leetcode 2976. Minimum Cost to Convert String I The problem is that we have to convert source to target. We can use original[i] and replace it with changed[i]. Any pair of original[...
CDY's user avatar
  • 25
1 vote
1 answer
83 views

I have tried to code a depthfirstsearch algorithm to solve a maze. This is what I have so far. I have tried to add as much detail so the logic is understandable: //Upgraded dfs algorithm that creates ...
LonelyBoi404's user avatar
3 votes
1 answer
145 views

I think that I understand how Prolog uses unification and backtracking to find the first match. However I'm having a hard time trying to understand what does it do when it is asked to "redo" ...
Tim's user avatar
  • 7,614
0 votes
4 answers
246 views

I have a data set having parent and nested children in it. The purpose of this data is to traverse over parent. 1 / \ 2 3 / \ / \ 4 5 6 7 First traverse 1,2,4 Now 4 has no ...
vikas dhiman's user avatar
-12 votes
1 answer
205 views

The knights journey where we are given the start/end points and the size of board(n*n): Find the minimum steps to reach the end from the starting point. If no path is there return -1: I've tried ...
new's user avatar
  • 3
-1 votes
0 answers
80 views

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 ...
Nikhil Garg's user avatar
1 vote
1 answer
172 views

Context: I want to write an algorithm for finding the shortest(least cost) path from a fixed source to a fixed destination node in a weighted directed graph with non negative weights (can have cycles)....
Lupin's user avatar
  • 59
2 votes
1 answer
138 views

Currently solving Course Schedule II on LeetCode and this is the code that DOES NOT pass all test cases because of the following line: Collections.reverse(postOrder);. Removing this line solves all ...
Lola's user avatar
  • 21
1 vote
1 answer
117 views

I am trying to use DFS and BFS to find all simple paths that have lengths up to a given k, starting at a given vertex in a directed graph. No cycles are allowed. My code is as follows, and I have ...
ivygrowing's user avatar
1 vote
1 answer
165 views

I am trying to code an algorithm for the Word Hunt game on Iphone Game Pigeon. How word hunt works: There is a 4x4 grid of letters given to each player. Each player must form words that are three ...
Siddd's user avatar
  • 41
2 votes
0 answers
126 views

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: ...
pathikrit's user avatar
  • 33.7k
0 votes
1 answer
178 views

I am stumbled at this part of SCC. I know that 5,6,7 is a strongly connected component. Performing the tarjan Algorithm for SCC starting at no de 5, I get unsatisfied values of low-link at 7. Graph ...
Curious Lad's user avatar
1 vote
0 answers
93 views

Here's a famous problem: Given a Directed Acyclic Graph of N vertices from 0 to N-1 and a 2D Integer array(or vector) edges[ ][ ] of length M, where there is a directed edge from edge[i][0] to edge[i][...
ABGR's user avatar
  • 5,263
1 vote
1 answer
41 views

I'm doing https://leetcode.com/problems/longest-increasing-subsequence/ I know in theory that each index needs to be assigned a length but i'm having trouble coding it up using my iterative approach /*...
xqcccccccccc's user avatar
1 vote
0 answers
154 views

I tried to do this function DFS recursively in assembly and I keep recieving "Segmentation fault" and I don't know from where. neighbours_t expand(uint32_t node); void dfs(uint32_t node, ...
Alexandra Dinu's user avatar
1 vote
1 answer
107 views

I get a similar error with a different root cause compared to: Clone Graph LeetCode 133 Consider the below implementation. If I use a Node-type key for processed_node_map, the algorithm passes. If I ...
John Vandivier's user avatar
1 vote
0 answers
49 views

I'm working on a program to find an optimal travel route starting and ending at the same city. The goal is to find the best route with the best goodness rating of the visited cities. My data is read ...
NoOne's user avatar
  • 13

1
2 3 4 5
53