Is there an algorithm to find shortest path (hop count) between only the connected dominating nodes? - graph-algorithm

Given a connected dominating nodes D in an undirected graph G; I search for an algorithm that can find the shortest paths (hop count) only between those dominating nodes.
Thank you.

Related

neo4j cypher filter nodes apoc dijkstra

I have a graph, and i want to use the apoc dijkstra algorithm on it, so far everything is working. But i want to exclude certain nodes or node properties from the possible path, so that the dijkstra algorithm doesnt return a path that contains these excluded nodes or properties.
Is it possible, for example, to filter all existing nodes BEFORE calling the apoc.dijkstra algorithm?
I know that is it possible to filter the found path AFTER the algorithm, but then it is possible that there is a possible path in the graph that was not found, because the filterting of the nodes occurred afterwards..
Apoc dijkstra is an old an deprecated implementation of Dijkstra algorithm. You should check out the Graph Data Science plugin at https://neo4j.com/docs/graph-data-science/current/. It supports shortest weighted path algorithm or otherwise known as dijkstra algorithm, https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/shortest-path/. You can can define which nodes you want and relationships you want to traverse when projecting the graph.
Hope this helps!

How to find maximal eulerian subgraph?

How to find maximal eulerian subgraph of a given graph? By "maximal" I mean subgraph with maximal number of edges, vertices, or both. My idea is to find basis of cycle space and combine basis cycles in a proper way, but I don't know how to do it (and is it a good idea or not).
UPD. Source graph is connected.
Some thoughts. Graph is eulerian iff it is connected (with possible isolated vertices) and all vertices have even degree.
It is 'easy' to satisfy second criteria by removing (shortest) paths between pairs of odd degree vertices.
Connectivity is problematic since removing edges can produce unconnected graph.
An example which shows that 'simple' (greedy) solution is not easy to produce. Modify complete graph K5 by splitting each edge in two edges (or more). Take two these modified K5 graph and from each one take two vertices (A, B from first and C, D from second). Connect A-C and B-D. Greedy approach would remove these added edges since they are the shortest paths. With that graph becomes unconnected. Solution would be to remove paths A-B and C-D.
It seems to me that algorithm should take a care about subgraph connectivity while removing edges. For sure algorithm should preserve that each subset of odd degree vertices, of which no pair are used to remove path between them, should have connectivity larger than cardinality of subset.
I would try (for a test) with recursive brute force solution with optimization. O is list of odd degree vertices.
def remove_edges(O, G):
if O is empty:
return solution
for f in O:
for t in O\{f}":
G2 = G without path edges between (f,t)
if G2 is unconnected:
continue
return remove_edges(O\{f,t}, G2)
Optimization can be to order sets O and O{f} by vertices that have shortest paths. That can be done by finding shortest lengths between all pairs of vertices from O before removing edges. That can be done by BFS from each O vertex.
It is proved in 1979 that determining if a given graph contains a spanning Eulerian subgraph is NP-complete.
Ref: W. R. Pulleyblank, A note on graphs spanned by
Eulerian graphs, J. Graph Theory 3, 1979, pp.
309–310,
Please refer to this
Finding the maximum size (number of edges) of spanning Eulerian subgraph of a graph (if it exists) is an active research area.
Consider the following standard definitions. Given a graph G = (V, E)
A circuit is a sequence of adjacent vertices starting and ending at
the same vertex. Circuits do not allow repeated edges but they do allow
repeated vertices.
A cycle is a special case of a circuit in which vertices also do not
repeat.
Note that circuits and Eulerian subgraphs are the same thing. This means that finding the longest circuit in G is equivalent to finding a maximum Eulerian subgraph of G. As noted above, this problem is NP-hard. So, unless P=NP, an efficient (i.e. polynomial time) algorithm for finding a maximal Eulerian subgraph in an arbitrary graph is impossible.
For undirected graphs, one way of randomly producing an Eulerian subgraph is to identify a cycle basis for G. A cycle basis is a set of cycles that, when combined using symmetric differences, can be used to form every Eulerian subgraph of the original graph G. Hence, we only need to take a random selection of cycles from this set and combine them to get our arbitrary Eulerian subgraph.
Given that an Eulerian subgraph is basically a collection of overlapping cycles, here is a greedy, polynomial-time algorithm that I'd like to suggest for finding large (but not necessarily maximum) Eulerian subgraphs. This works for both directed and undirected graphs and produces a set of edges (or arcs) E’ that define an Eulerian subgraph containing a user-defined source vertex s. The following steps are for directed graphs but can be easily modified for the undirected case.
Let U = {s} and E' = {}
while U is not empty
Let u be a random element in U
Form a cycle C from u in G
if no such cycle C exists
Remove u from U
else
Add the arcs of C to E'
Remove the arcs of C from G
Add the vertices of C to U
Here’s a few points to note about this algorithm.
Here, the set U holds the vertices that are yet to be fully considered by the algorithm.
To apply this method to undirected graphs, just replace the word
"arcs" with "edges"
This method can be seen as a generalisation of
Hierholzer's algorithm. Hence, if the input graph G is already
an Eulerian graph, then the returned set E’ will contain all of the
edges from G.
Various methods can be used to generate a cycle C from
vertex u. For directed graphs, a simple method is to create an
additional dummy vertex u' and temporarily redirect all of the incoming arcs
from u to u'. Various algorithms can then be used to determine a
u-u'-path (which represents a cycle), such as BFS, DFS, or
Wilson's algorithm.
This algorithm can be said to produce a maximal Eulerian subgraph with respect to G and s. This is because, on termination, no further cycles can be added to the solution contained in E'. Note that we should not confuse the terms maximal and maximum here: finding a maximal Eulerian subgraph is easy (using the above method); finding a maximum Eulerian subgraph is NP-hard. Similar terminology is used with matchings.

Shortest positive path in a directed acyclic graph

We are given a directed acyclic graph with arbitrary weights on edges and two specific nodes, s and t, where in-degree of s and out-degree of t is 0. How to determine the shortest path from s to t that has positive cost?
Use a modified Bellman-Ford, which removes edges from the graph if a resulting shortest path cost is <0 until you reach a cost, that is not <0.

How can I find max of multiplication of subtree nodes?

A tree that has N nodes is given. Nodes have weights between -1000 and 1000. That is asked from me is to find maximum of multiplication of subtree nodes. Do you have any idea/algorithm to solve this problem?
For example
I'd just traverse the tree keeping track of a cumulative product until you reach the leaf node.
Select the leaf node with the highest product.
Optionally:
Along the way you /can/ optimize by traversing only the highest child of each node.
Note For this optimization we assume that no negative values exist.

Shortest path algorithm that passes through certain edges

I need to find the shortest path in a graph that passes through at least one edge marked as "must pass". Any ideas? Could Dijkstra's algorithm be modified in order to achieve this?
For the path from A to B that must pass through C, compute it as two shortest paths, one from A to C, and another from C to B.

Resources