Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [graph-traversal]

Questions about graph traversal algorithms such as BFS and DFS.

1
vote
0answers
17 views

Enumerate all re-convergent paths in a digraph (with cycles)

I'm looking for an algorithm to count and enumerate (separately, if differing complexity) all the reconvergent pathsets in a simple, directed, non-weighted graph, which may contain cycles. That is, ...
1
vote
1answer
26 views

DFS & BFS Spanning Trees

I want to construct a DFS and a BFS spanning trees for the graph below. The root is node a. At each step the next edge to be traversed should be the cheapest one. DFS: My understanding that to the ...
0
votes
2answers
20 views

How to traverse a graph in reverse with dfs

So I'm watching Stanford's algorithm lectures and I'm on Kosaraju's algorithm. In the lecture, the algorthm was given in 3 steps: calculate the graph with all arcs reversed, run dfs on reversed graph, ...
2
votes
2answers
58 views

Proof for BFS and DFS equivalence

I'm trying to prove (by induction) that BFS in equivalent to DFS, in the sense that they return the same set of visited nodes, but I'm stuck in the middle of some of the cases. Let $G$ be a directed ...
1
vote
1answer
34 views

proof that BFS remains total after adding edge to graph

I'm trying to prove that if $G$ is a connected graph, then $BFS(u\in G)$ is total (i.e. it visits all the vertices of $G$). The inductive proof consists in 2 cases: (i) Prove that $\rm{BFS}$$(u \in \...
1
vote
1answer
42 views

Post numbers in DFS tree of an undirected graph

How could you prove: An edge (u,v) is part of an undirected graph G. If post(u) $<$ post(v) (i.e. the post number of u is smaller than that of v) then it implies that v is an ancestor of u in the ...
1
vote
2answers
167 views

Is there a name for this graph search strategy?

The standard implementation of breadth-first search looks like ...
0
votes
2answers
27 views

Calculation of Inorder Traversal Complexity

I want to analyze complexity of traversing a BST. I directly thought that its complexity as $O(2^n)$ because there are two recursive cases. I mean $T(n) = constants + 2T(n-1)$. However, AFAI research ...
2
votes
1answer
68 views

Understanding the “ordering of the four types of edges” in DFS

The following is Exercise 22.3-6 from CLRS (Introduction to Algorithms, the 3rd edition; Page 611). Show that in an undirected graph, classifying an edge $(u,v)$ as a tree edge or a back edge ...
0
votes
0answers
7 views

Alternative technologies/theories for a “Git for Structured Graph Databases”

Along the lines of detect differences between tree structures, I'm wondering if there are any general techniques or tools (e.g. the techniques behind the tools) that can essentially do what Git does ...
2
votes
1answer
22 views

Graph Traversal Solutions for “Find all unique paths” Problem

I was studying the grid problem where a robot is at the top left position and wants to go to the bottom right position and you need to return the number of unique paths it can take to get there with ...
0
votes
0answers
71 views

A longest path can be found using DFS

The following is a Yes/No question. In an undirected unweighted graph $G$, a longest path between two given vertices $s$ and $t$ can be found using Depth-first search? If it is possible to use DFS ...
0
votes
1answer
54 views

DFS on reversed graph

I was watching a lecture on determining the strongly connected components of a graph using Kosaraju's algorithm and the lecturer claimed one can easily walk the edges in reverse fashion. While I see ...
2
votes
2answers
250 views

Proving Postorder Traversal's Time Complexity

I am looking at the following algorithm for performing a Postorder Traversal of a binary tree ...
3
votes
1answer
191 views

Tarjan's SCC : example showing necessity of lowlink definition and calculation rule?

Several questions (1, 2) have been asked about this topic already but I am trying to be more specific. In Tarjan's SCC algorithm, the calculation of lowlink when encountering a vertex which is ...
2
votes
2answers
101 views

What is the name of a rooted tree whose nodes may have edges to their descendants?

A tree is a special kind a graph. However, I came across a data structure which is a like a rooted tree, but where nodes are authorized to have direct links to any of their descendants. Shortcuts if ...
1
vote
1answer
39 views

Finding a minimum weight path with certain restrictions

I have a directed weighted multigraph whose vertices are sets of URLs. We add to this multigraph all edges of the form $i\to j$ where $i\subset j$ (such edges are of zero weight), where $i$, $j$ are ...
0
votes
1answer
48 views

Conditions for a node to be a leaf node on DFS tree

Question: Consider the DFS tree generated by a DFS on a connected graph. Write below the necessary and sufficient condition for a node v to be a leaf node on the DFS tree. The condition must be in ...
4
votes
1answer
24 views

How to identify named points by coordinates?

The problem: This is a reduced version of a problem I currently have. I have a list of edges as input. This list contains the names of 2 nodes (the edge connects these 2 nodes) and 2 x 2D coordinates (...
1
vote
1answer
64 views

Split graph in two parts, such that most nodes have even number of edges

We have given graph of at most $200$ nodes, we want to split the given graph in two parts, such that the number of nodes with even number of edges is maximized, note that the edges that are between ...
1
vote
1answer
29 views

Breadth First Search actually require specifically Queue instead of any other type of Collection?

As far as I know, Breadth-First-Search [BFS] theory traditionally requires a Queue to process a given level of a graph (i.e: wiki seems to assume so). But does BFS really actually require a Queue, ...
2
votes
2answers
51 views

How to graph search a LTL-generated Buchi automaton to generate valid execution paths

I have a set of tasks, and a LTL specification that describes which orders of the tasks are legal. I want to find a way to enumerate all permutations of the tasks that meet the specification. For ...
0
votes
0answers
32 views

How many roots are there in an undirected root

Given an undirected tree with 7 nodes how many roots would this tree have. My intuition tells me that because the tree is undirected it would either be 7 or 0. How would I solve this?
1
vote
1answer
46 views

Ordering the incident edges of each vertex to have a specified pre-order traversal

Input: You are given a graph $G(V, E)$ undirected, loop-less, no parallel edges, etc. and a label function $L: V \to \mathbb{N}$. Also, a sequence of $|V|$ natural numbers is given. Output: Is it ...
2
votes
2answers
85 views

Find out an algorithm that finds out if an undirected graph contains even length cycle or not using BFS?

I know how to find odd length cycles(a bipartite graph cannot have odd cycles) but I cannot manage to make an algorithm when considering even length cycles.
1
vote
1answer
60 views

When to terminate search for path in an infinite grid

I'm learning shortest path algorithms like Dijkstra's, BFS, etc. I understand on a 2D finite grid there are boundary conditions (i.e. size of the grid) that help terminate the algorithm and keep it in ...
1
vote
1answer
133 views

Different topologically sorted order based on DFS vertex ordering

The algorithm for topological sort, in CLRS goes as follows : call DFS(G) to compute finishing times v.f for each vertex v as each vertex is finished, insert it onto the front of a linked list return ...
0
votes
0answers
22 views

How to Compute Lowpt(v) in a DFS Tree, where Lowpt(v)={w| there exist a back_edge xw, such that x is a descendant of v}?

In computing Triconnected components of a graph using HopCropt and Tarjan algorithm, i.e https://sci-hub.tw/https://epubs.siam.org/doi/pdf/10.1137/0202012, they compute two additional values Lowpt1 ...
0
votes
0answers
41 views

Single source shortest Path Algorithm in dynamic graph

In case of dynamic graphs where edges are added only (all edges have positive weight). Goal: to keep track of the shortest path from the source to the goal node. Are their any specific conditions ...
2
votes
1answer
27 views

Is it possible to detect a simple negative-weight cycle of weight $N$ in polynomial time?

Given a directed graph and an integer $N$, is it possible to detect a simple negative-weight cycle whose edges sum to $N$ in polynomial time? I thought about modifying the Floyd-Warshall algorithm to ...
1
vote
1answer
11 views

How to get initial flow for TSP with missing edges

I need to solve a version of the traveling salesman problem with missing edges. I've decided to use simulated annealing. How do I generate a valid initial path effectively? I would use a greedy ...
0
votes
0answers
52 views

v.lowlink = min(v.lowlink, w.index) line in Tarjan Algorithm

Following the pseudo-code notation used in wikipedia. I understand the basics of the algorithm but I don't really understand this line. When exactly is it relevant? I only found one example, and it ...
0
votes
0answers
13 views

Finding a path between 2 points passing through N points

Given a graph/plane with N points each at a given coordinate how could I find a path between 2 points via N other points where each point is weighted on how likely it is to be passed through. ...
1
vote
1answer
79 views

Understanding time complexity of a while loop that will look over all vertices and edges

I need a little clarification on differing time complexities. My analysis for the below algorithm was $O(n +nm)$, but the correct analysis would be $O(n+m)$. I know that ...
0
votes
1answer
152 views

Removing vertices that belong to a given set from a graph

If I'm given a graph $G$ with the set of vertices $V$ and a set $B \subseteq V$, can I remove all the vertices $\in B$ from $G$, as well as all edges that connect any other vertex to a vertex $\in B$ ...
2
votes
0answers
223 views

How to traverse a graph in reverse dfs order

For kosaraju's algorithm to traverse the graph in reverse order the naive solution is to reconstruct the original input graph in reverse order and dfs on it. Is there any way I can avoid creating ...
0
votes
0answers
109 views

Longest-Path Layering algorithm

NOTES: there are a myriad of graph data structures, I use a spin-off of a directed adjacency hash. the code provide in this post is python3 on the premise that it ...
0
votes
0answers
36 views

The path with the highest sum of weights

Mr. Katsaros owns a rectangular olive grove divided into 5 rows and 4 columns. He notes down the amount of olives (pounds) possibly obtainable from each of 20 square sections. The picking starts from ...
0
votes
0answers
6 views

Joining split vertices

Suppose you have two sets of edges, where in one of the sets, an edge is split into two sub-edges, like in the depiction below. Each "o" is a vertex of the edges, which are drawn by "----". Set 1: o--...
0
votes
0answers
52 views

Multi agent graph traversal with edge discovery

Suppose we are given a set of agents (say $P_1 , \dotsc, P_M$), an undirected graph G(V,A) and a set of initial vertices on $G$ where each agent is located. Initially only the edges connected to these ...
1
vote
1answer
65 views

Printing all paths of a tree and sorting the weight of edges

Let $T=(V,E)$ be tree and each edge has a positive scalar weight. I need to print all paths in the tree and then sort the weight of edges in each paths. it needs $O(n^3\log(n))$ time. To solve this ...
2
votes
0answers
83 views

Algorithm to find nodes with given a distance

We have a map of a branching river without any islands (tree of confluences, see picture), there are piers on the river bank ( not necessarily on the confluences). We are given the distances between ...
0
votes
0answers
64 views

Time complexity proof of finding the $i$ object in binary search tree is $O(h+i)$ by inorder

I'm looking for time complexity proof of finding the $i$ object in binary search tree is $O(h+i)$ by inorder run. when $h$ is the height of the tree.
4
votes
1answer
127 views

Given an oriented graph, return true if paths have a specified length

I'm having trouble solving this exercise about graphs, I hope you can help me: Given a graph $G = (V,E)$, two sets of vertices $A \subseteq V$ and $B \subseteq V$ (represented as arrays), and an ...
2
votes
1answer
28 views

Prove that the depth of every vertex in a cycle is $\le \lfloor \frac{n}{2} \rfloor$ in a breadth first search?

Suppose I have an undirected graph that consists only of a cycle. Each vertex has a depth value that must be $1$ greater than its predecessor (i.e. if we reach vertex $F$ from vertex $C$ which has a ...
1
vote
1answer
106 views

Find a path that contains specific nodes without back and forward edges

I have a directed graph and and a set of nodes(set = [1,2,5,9,24...]). I want to find a path that contains all the set of nodes and this path dont contain back edges(cycles) and forward edges. For ...
0
votes
1answer
58 views

Find all sets of nodes that can be connected with a single path

** Edit: I just noticed my current algorithm is incorrect, as it only finds paths starting/ending at the given node. I'm trying to figure out a solution, but I'm a bit stuck. Say I have an ...
1
vote
0answers
28 views

Dynamic path planning and waypoint sorting

Good evening everyone, I have a question that I am having a bit of trouble formulating properly and thus it is making it complicated to look up literature on the subject. What I am looking for is a ...
1
vote
1answer
72 views

How to minimally extend a digraph such that all nodes are on a cycle?

Let's say we have a directed graph with $n$ nodes and $m$ edges. For each node we want to make path that will start from this node, possibly traverse some other nodes and finish in the same node, in ...
0
votes
0answers
72 views

BFS time complexity

I would like to express the time complexity of BFS as the number of nodes generated with respect to the branching factor $b$ and the depth of the goal $d$. I am assuming that nodes are goal tested at ...