Questions tagged [graph-traversal]

Questions about graph traversal algorithms such as BFS and DFS.

Filter by
Sorted by
Tagged with
1
vote
1answer
32 views

Bridges and Edge Disjoint Paths

So , Basically assume there is a graph $G$ which has no bridges. Is it always true that there exists two edge disjoint paths between any two vertices in the Graph ? $\text{My Attempt at the Proof}$:- ...
1
vote
0answers
16 views

Why does this BFS solution work for this question about euclidean distance and what's its complexity?

Given a matrix of 1s and 0s where 0 represents houses and 1 represents stores, find the square of minimum Euclidean distance of every house to nearest store. Return it as a vector of vector. ...
0
votes
0answers
20 views

Please explain the algorithm for finding bridges in graph?

let, low[] and disc[] be two 1D arrays disc[i] stores the discovery time of node[I] low[i] stores the lowest value between disc[i] and discovery time of children of node[i] I'm curious that what is ...
1
vote
1answer
14 views

Matching vertex values with sum of edge weights on bipartite graph

Earlier this week I asked this question (please review): Imagine StackOverflow started offering a subscription where companies could buy X number of impressions per month for a set of tags. ...
-1
votes
0answers
15 views

Logspace reduction from PATH to 2SAT

It is known that PATH (given a directed graph G and two vertices s,t is there a path in G from s to t), and 2SAT are NL-complete problems. Find a logspace reduction from PATH to 2SAT.
3
votes
1answer
50 views

Efficiently finding “unfounded edges” in a strongly connected graph

While implementing a debugger I've encountered a problem I need to solve concerning dependency graphs. I've simplified it as follows: Consider a strongly connected graph G = (V,E). We define a ...
3
votes
2answers
39 views

Finding a hamiltonianISH path in a graph

Problem statement Given a graph of all the blue squares in the following image where each blue square is connected to other blue squares in all 4 cardinal directions. Given any starting node. What ...
1
vote
2answers
80 views

Iterative Depth First Search for cycle detection on directed graphs

I found this pseudocode on Wikipedia, and looks very elegant and intuitive: ...
1
vote
0answers
32 views

small world networks properties

Small-world networks have two properties: clustering coefficient and average node-to-node distance my questions are: 1- Can a disconnected graph ( which may include multiple connected graphs) hold a ...
2
votes
1answer
61 views

In a DAG, finding the path with the highest score

Given a directed, acyclic graph in which each node has an assigned integer score, what is a fast way of finding the path from a start and end vertex with the highest cumulative score? I thought of a ...
2
votes
1answer
34 views

Number of `m` length walks from a vertice with steps in [1, s]

The problem is stated as the following: We are given a grid graph $G$ of $N \times N$, represented by a series of strings that describe vertices s.t. $L$ is the vertice we're interested in $P$ are ...
1
vote
1answer
63 views

Some paths in directed graph

Given directed graph $G = \langle V, E \rangle$, such that some vertices are red, and some vertices are black, and some edges are blue or green, decide for all vertices $v \in V$ if there is path from ...
0
votes
0answers
49 views

Graphs which favour BFS over DFS and vice versa

I am trying to figure out what kinds of graphs are better suited to BFS and which are better suited to DFS. However i'm struggling to visualise what kind of graphs favour which search. Could someone ...
1
vote
0answers
20 views

Restoring the minimum vertex cover on bipartite graph from the maximum matching

I had to solve a problem on finding the minimum vertex cover on a bipartite graph, and I used the Kőnig's theorem and reduced it to maximum matching problem on bipartite graph, which is easily ...
3
votes
1answer
68 views

Existence of walk in undirected connected graph where nodes must end with assigned value

We have a graph with $N$ nodes and $N-1$ undirected edges, where it's possible to reach one node from any other node. Each node will get assigned a value randomly from [1,...,10]. We want the value of ...
0
votes
0answers
69 views

Shortest tour visiting given set of nodes in knight tour graph

Problem: Given knight tour graph $G$ ($8 \times 8$ nodes) and a set of nodes $\{ v_{1}, v_{2}, \dots, v_{n} \} = V \subset V(G)$, find a minimal length tour in $G$ that visits all nodes from $V$ (...
0
votes
0answers
17 views

algorithm that finds minimal vertex cover of a given vertex

i am looking for a simple algorithm that gets as an input an undirected graph and a vertex in the graph and outputs the minimal vertex cover that v belongs to. not sure on how to do it correctly, ...
1
vote
0answers
58 views

About shortest cycles in undirected graphs

In an undirected (and unweighted) graph, to find the shortest cycle containing a specific vertex $s$, it is usually said to run a BFS from $s$ and the first time to find a re-visit, then that is the ...
0
votes
0answers
14 views

Is it possible to implement iterative pre/in/post-order traversal with only one stack?

All iterative algorithms I've seen for pre-order, in-order, and post-order traversals of trees have used two stacks. Is it possible to do it with one? I've been thinking about it for ever, I haven't ...
1
vote
1answer
71 views

Determine whether there exists a path in a directed acyclic graph that reaches all nodes without revisiting a node

For this I came up with a DFS recursion. Do DFS from any node and keep doing it until all nodes are Exhausted. I.E. pick the next unvisited node once you cannot keep recursing. The element with ...
0
votes
0answers
32 views

Making graph acyclic by removing back edges in depth first and breadth traversal

I came across following points: Removing all back edges produced by DFS makes the graph acyclic. For a directed graph, the absence of back edges with respect to a BFS tree implies that the ...
0
votes
0answers
15 views

Comparing shortest path distance and relation between two modes present in FIFO queue at the same time during breadth first traversal

I came across following problem: Consider two vertices $a$ and $b$ that are simultaneously on the FIFO queue at same point during the execution of breadth first search from $s$ in an undirected ...
0
votes
1answer
64 views

Dijkstra's algorithm - Finding additional paths with same weight but different edges

given a network with n stations. assuming the shortest between s,t was found using dijkstra's algorithm. let that path be denoted as $(a_1,a_2,...,a_k)$ assume that between the nodes s and t, there's ...
3
votes
1answer
40 views

Algorithm for finding “mean center” of unweighted graph

I have a large sparse unweighted undirected graph (20M vertices, 60M edges) and would like to find what I'm calling the "mean center" (the vertex w/ shortest mean distance to all other vertices. Does ...
1
vote
2answers
118 views

Dijkstra and A* Algorithms: Why is A* faster?

I am learning about Dijkstra's Algorithm and the A* Algorithm and I have manually worked through the graph attached here, which is supposed (I think) to demonstrate that the A* Algorithm is faster ...
0
votes
0answers
23 views

Finding the minimal path from S to T that visit all vertices

So I have a complete and directed graph with weights. I wish to find the shortest path from S to T that visits all other vertices in the graph at least once. Another important piece of information I ...
1
vote
0answers
17 views

How do programs like Apache Airflow/ Luigi determine shortest path and how does that relate to graph theory?

I am looking for a simple layman's term explanation on how do programs like Apache Airflow or Luigi (or any Task/ETL schedulers) determine the shortest path to complete a certain task and make it ...
0
votes
1answer
134 views

Why is my algorithm version so slow with this input?

Here I'm trying to do a comparison of two simple as possible algorithms, solving the symmetric travelling salesman problem, finding the optimal solution without the support of heuristics. I'm showing (...
1
vote
1answer
50 views

Breadth First Traversal for graph with multiple connected components

I read BFS and DFS from CLRS and realized that the BFS algorithm does not consider graph with multiple connected components but only with single connected component, whereas DFS algorithm considers ...
2
votes
1answer
276 views

O(V+E) algorithm for computing chromatic number X(g) of a graph instead of brute-force?

I came up with this O(V+E) algorithm for calculating the chromatic number X(g) of a graph g represented by an adjacency list: Initialize an array of integers "colors" with V elements being 1 Using ...
4
votes
2answers
392 views

Find all nodes on simple paths between two nodes in cyclic directed graph

Given two nodes U and V in a cyclic directed graph, how can I find the set of nodes that are part of a simple path from ...
1
vote
0answers
27 views

Finding all non-comparable nodes in DAG

I have a DAG and I want to list all pairs of vertices that are not comparable (there is no path from the first to the second or the second to the first). In this image (taken from this StackOverflow ...
1
vote
0answers
37 views

Find all Eulerian cycles in a directed graph

I am trying to create an algorithm that can find all Eulerian cycles in a directed graph. I was able to make an algorithm that can find one cycle in the graph, but I don't know how to find all the ...
0
votes
2answers
95 views

Graph theory: BFS (Breadth First Search) - why is current processed first?

I am referencing some code I found on GeeksForGeeks.com: Why is the current node printed (and processed) first before its children are processed? Wouldn't "breadth first" mean "Process children first, ...
0
votes
0answers
21 views

Is there a Weisfeiler-lehman kernel for directed, labelled and with cycles graphs?

I have a set of labelled, directed and cyclic graphs and a I need to perform a supervised learning algorithm in this data. I have found a single paper A Persistent Weisfeiler-Lehman Procedure for ...
5
votes
0answers
81 views

Find the 'best' longest common subsequence

I am writing a program that computes and displays diffs. I implemented Meyers algorithm that computes the LCS between 2 subsequences (seq1 and ...
-1
votes
1answer
65 views

Is there an example of when DFS will not return the min. spanning tree?

If we have a connected, weighted, undirected graph. Can anyone provide an example where DFS will not return the MST? No matter what vertex we start from ?
4
votes
1answer
60 views

Computing a pre-topological sort using a BFS/a queue

Computing a topological sort in a DAG using a queue simply amounts to putting the nodes with indegree 0 in a queue, and going through the queue removing these nodes from the graph and adding the nodes ...
0
votes
0answers
48 views

BFS vs DFS, and Timing of Marking Vertex as Visited

The Wikipedia article on Depth-Frist Search states that: The non-recursive implementation is similar to breadth-first search but differs from it in two ways: it uses a stack instead of a ...
2
votes
1answer
44 views

An algorithm for topological sorting based on depth-first search: why do we need two tags?

Wiki gives an alternative algorithm for topological sorting is based on depth-first search, as follows: ...
2
votes
1answer
51 views

Arranging Colors in a Grid; Two Dimensional TSP?

I am working on an interesting problem, which I believe can be solved algorithmically. I have a 6x8 on which I am attempting to arrange 48 color swatches, such that the transition from each swatch to ...
2
votes
1answer
57 views

Efficiently compute the sum of edge weights product of all possible path in a DAG

I thought of using Depth First Search (DFS) to find all possible paths in O(|V|+|E|). However, computing the product of all the edge weights for a path is O(2^N). Is there any way to compute this more ...
-1
votes
1answer
86 views

binomial tree number of nodes

Does anybody knows that how we can assign number to nodes for binomial tree . I mean how we can represent the number of nodes by array? please give me hint I am really confused .
2
votes
1answer
88 views

How to deal with parallel edges between two vertices in cycle detection using BFS in an undirected graph?

I am new to Programming and learning Algorithms and was studying BFS when I read that BFS could be used for cycle detection. I tried to implement the same on an undirected graph G with Adjacency List ...
1
vote
2answers
48 views

Find the minimal tank capacity to be able to travel from any city to any other

There are $n$ cities in the country. The car can go from any city $u$ to city $v$, On this road it spends $w_{u,v} > 0$ fuel. At the same $w_{u,v}$ can differ from $w_{v, u}$. The task is to find ...
0
votes
0answers
19 views

Detecting whether a node belong to a cutset with the least memory consumption as possible

I'm working on a problem about connected components implemented by cutsets. Given a cutset, I want to determine whether some node lies within the connected component created by such cutset. The most ...
4
votes
2answers
271 views

How to evaluate all possible groups of adjacent tiles in 2D array?

I'm working on a tile based game idea in Javascript. It's a math puzzle game where players move around tiles with numbers on them, and the goal is to connect groups of tiles that have a sum of certain ...
1
vote
1answer
86 views

Directed graph reachability

Given a directed graph G(V,E) and a node s, how do we determine what nodes are reachable from s? Do I need simple traversal algorithms or do I need to look at Tarjan's algorithm?
0
votes
1answer
35 views

Strongly connected graph proof

Here I have a proof related to strongly connected graph from Algorithms book. However, when I run DFS on the following 2 strongrly connected graph, I get different result than the proof. According ...
0
votes
0answers
29 views

Why is BFS “vertex based” and DFS “edge based”?

I am trying to understand the various differences between Breadth-first and Depth-first search on graphs. Two sources state that BFS is "vertex based" and DFS is "edge based" even though in ...

1
2 3 4 5
7