## graphs – How to prove that Bellman-Ford algorithm detects a negative cycle?

I have read that if we run the outer-loop of the Bellman-Ford algorithm for |V| times (where |V| is the number of nodes in the graph) and check if any distance has changed in the |V|th iteration (i.e. the last iteration) then there exists at least one negative weight cycle in the graph. But why does this work? Why only run for |V| times, why not more than that?

1. I am looking for a mathematical proof on why a change in the value of the distance of a node during the last iteration (|V|th iteration) implies that there is a negative weight cycle?

2. Can we detect all the nodes that are either reachable or are parts of the negative weight cycles after the |V|th iteration (can this also be proved mathematically)?

It would be helpful if someone can either provide the proofs and explanations or direct to the relevant resources.

Thank you.

## ❕NEWS – Two new commers Cryptos will surge alongside Bitcoin , Ethereum and ripple in the next bull cycle. | Proxies123.com

To those you who are willing and ready to trade on New coins.

A crytpo analyst Nicholas Merten has advised the intending Investors to keep an eye on Cardano (ADA) and Tezos (XTZ) as they warm up for the next bullish breakout.
He also said the bull run I’m bitcoin, ethereum and ripple will continue for a while, also litecoin is not left behind.

## Complexity of Finding Every Cycle in a Graph?

What’s the best asymptotic complexity of finding every cycle in a simple, directed graph?

I haven’t been able to find anything regarding this online. I’m able to use DFS for cycle detection, but I’m looking to determine the weight of each cycle in a graph, thus I’d like to be able to determine them all.

## combinatorics – Must there exists a tour and cycle given that there exists a closed walk in a multigraph?

First of all some definitions:
multigraph: a graph with edges that appear more than once and loops (a vertex v can be neighbors with itself).
closed walk: a sequence of edges not necessarily distinct s.t. the first and last vertex is the same.
tour: a closed trail, where a trail is a walk with distinct edges.
cycle: a trail where the only repeated vertex is the first/last vertex.
finally, with definitions out of the way, if there is a closed walk containing two vertices $$u_1$$ and $$u_2$$ in a multigraph $$G=(V,E)$$, must there be a tour and cycle containing $$u_1$$ and $$u_2$$?

I’ve previously proven that if there exists a walk between two vertices, then there must be a path between the two points. Since a path (no repeated vertices) is also a trail. This implies that there must a tour between the two vertices $$u_1$$ and $$u_2$$. Because we can simply add the edge $$u_1u_2$$ to the end of the path to get a tour. Thus this tour generated from a path will automatically be a cycle as well. Therefore there must be a tour AND cycle if there is a closed walk containing $$u_1$$ and $$u_2$$. Is my logic correct or is there something I missed?

## trees – Can Edge Belong to a cycle if it is part of multiple BFS products

Given a simple connected undirected graph. with V vertices and E edges.
Let e be some edge from E.

If I perform |V| different BFS runs – meaning started each time from a different vertex – and in every run e is part of the Spanning tree produced from the run.
Can it be belonging to some cycle?

The multiple answers I have to choose from are:

1. it does not belong to any cycle
2. e might belong to a cycle but if it belongs to an odd-length cycle, then it must belong to an even-length cycle.
3. e might belong to a cycle but if it belongs to an even-length cycle, then it must belong to an odd-length cycle.
4. None of the above.

My claim is, because BFS is deterministic and because we performed |V| BFS on the graph, each time from a different vertex. if e was on some cycle, and it doesn’t matter even-length or odd length, one of the vertices on the cycle would have caught up with it and remove it.

The only way that it belongs to every Spanning tree, is if it’s un replaceable, meaning it’s the only thing connecting two vertices.

Am I right? is there any formal proof th

## c# – Solving code without extra cycle outside for loop

This code reads barrel diameter and height from file, then, based on dimension make decisions and finally these decisions are printed out to a file. My pronbelm is how to avoid using the code wrtine on lines 70-101? Probably has to do with line 35, but I haven´t figured my way around it. Would be nice if there is a way (chance) to make this code shorter.

P.S d – diameter, h – height

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace TaaviSimsonTest
{
class Program
{
static void Main(string() args)
{
//Reads values from an input file
.Select(line => line.Split(' '))
.Select(barrels => new
{
diameter = int.Parse(barrels(0)),
height = int.Parse(barrels(1))
})
.ToArray();

//Puts diameter and height values to arrays
int() d = numbersList.Select(x => x.diameter).ToArray();
int() h = numbersList.Select(x => x.height).ToArray();

//Displays numbersList with line number, diameter and height
for (int i = 0; i < d.Length; i++)
{
Console.WriteLine("Line {0}: diameter: {1}, height: {2}",
i, d(i), h(i));
}

//comparing barrel sizes and making a decision
List<string> output = new List<string>();
for (int j = 0; j < (d.Length - 1); j++)
{
int a = j + 1;
int b = j + 2;
if (d(j) > d(j + 1) && h(j) > h(j+1))
{
string command = a + "<-" + b;  //1 <- 2, if j = 0
output.Add(command);            //puts command in array
}
else if (d(j) < d(j + 1) && h(j) < h(j+1))
{
string command = a + "->" + b;
}
else if (d(j+1) < h(j) &&
((d(j+1) * d(j+1) + h(j+1) * h(j+1)) <
d(j) * d(j)))
{
string command = a + "<-" + b;  // 2 <- 3
}
else if(d(j) < h(j+1) &&
((d(j) * d(j) + h(j) * h(j)) <
d(j+1) * d(j+1)))
{
string command = a + "->" + b;
}
else
{
string command = a + "--" + b;
}
}

//how to avoid this cycle?
int c = 1;
int e = d.Length;
if (d(0) > d(d.Length - 1) && h(0) > h(d.Length - 1))
{
string command = c + "<-" + e;
}
else if (d(0) < d(d.Length - 1) && h(0) < h(d.Length-1))
{
string command = c + "->" + e;
}
else if (d(d.Length-1) < h(0) &&
((d(d.Length-1) * d(d.Length-1) + h(d.Length-1) * h(d.Length-1)) <
d(0) * d(0)))
{
string command = c + "<-" + e;
}
else if (d(0) < h(d.Length-1) &&
((d(0) * d(0) + h(0) * h(0)) <
d(d.Length-1)*d(d.Length-1)))
{
string command = c + "->" + e;
}
else
{
string command = c + "--" + e;
}

//Writes values of array to a new file
String() outputlist = output.ToArray();
File.WriteAllLines(@"C:TempbarrelsOutput.txt", outputlist);
//Displaying output in console
Console.WriteLine("");
foreach (var item in outputlist)
{
Console.WriteLine(item.ToString());
}
}
}
}

## javascript – Google chart sankey– “Cycle found in rows” error

I’m using Google Chart – (Sankey Diagram)(1) to show flows within the same group of categories A, B, C, D over time. (Photo attached.)(2)

I want to remove the month and year e.g. “(Dec 2019)”, “(Apr 2020)” from my node labels, so that the labels read only “A”, “B”, “C”, “D”, and the month/year is printed below the graph for each level of the Sankey. I am unable to do this because when I remove the month/year from the labels, I get a “Cycle found in rows” error.

1. How can I make a graph which has the same node labels but don’t get this error?
2. How can I add a legend for each level of the Sankey, i.e. the month/year?

Many thanks.

Code:

<html>
<body>
<div id="sankey_multiple" style="width: 900px; height: 300px;"></div>
<script type="text/javascript">

function drawChart() {
var data = new google.visualization.DataTable();
( 'A (Aug 2019)', 'A (Dec 2019)', 83.94 ),
( 'A (Aug 2019)', 'C (Dec 2019)', 6.94 ),
( 'A (Aug 2019)', 'B (Dec 2019)', 6.11  ),
( 'A (Aug 2019)', 'D (Dec 2019)', 3.01 ),
( 'C (Aug 2019)', 'A (Dec 2019)', 1.29  ),
( 'C (Aug 2019)', 'C (Dec 2019)', 83.30 ),
( 'C (Aug 2019)', 'B (Dec 2019)', 9.87  ),
( 'C (Aug 2019)', 'D (Dec 2019)',  5.54  ),
( 'B (Aug 2019)', 'A (Dec 2019)', 1.23 ),
( 'B (Aug 2019)', 'C (Dec 2019)', 13.55 ),
( 'B (Aug 2019)', 'B (Dec 2019)', 78.79 ),
( 'B (Aug 2019)', 'D (Dec 2019)', 6.42 ),
( 'D (Aug 2019)', 'A (Dec 2019)', 0.36 ),
( 'D (Aug 2019)', 'C (Dec 2019)', 2.08 ),
( 'D (Aug 2019)', 'B (Dec 2019)', 1.90 ),
( 'D (Aug 2019)', 'D (Dec 2019)', 95.67 ),
( 'A (Dec 2019)', 'A (Apr 2020)', 38.3 ),
( 'A (Dec 2019)', 'C (Apr 2020)', 21.19 ),
( 'A (Dec 2019)', 'B (Apr 2020)', 9.82 ),
( 'A (Dec 2019)', 'D (Apr 2020)', 30.69 ),
( 'C (Dec 2019)', 'A (Apr 2020)', 4 ),
( 'C (Dec 2019)', 'C (Apr 2020)', 55.9 ),
( 'C (Dec 2019)', 'B (Apr 2020)', 6.23 ),
( 'C (Dec 2019)', 'D (Apr 2020)', 33.87 ),
( 'B (Dec 2019)', 'A (Apr 2020)', 3.53 ),
( 'B (Dec 2019)', 'C (Apr 2020)', 18.82 ),
( 'B (Dec 2019)', 'B (Apr 2020)', 20.31 ),
( 'B (Dec 2019)', 'D (Apr 2020)', 57.34 ),
( 'D (Dec 2019)', 'A (Apr 2020)', 0.73 ),
( 'D (Dec 2019)', 'C (Apr 2020)', 3 ),
( 'D (Dec 2019)', 'B (Apr 2020)', 1.65 ),
( 'D (Dec 2019)', 'D (Apr 2020)', 94.61 ),
( 'A (Apr 2020)', 'A (Aug 2020)', 37.38 ),
( 'A (Apr 2020)', 'C (Aug 2020)', 28.90 ),
( 'A (Apr 2020)', 'B (Aug 2020)', 22.01 ),
( 'A (Apr 2020)', 'D (Aug 2020)', 11.71 ),
( 'C (Apr 2020)', 'A (Aug 2020)', 4.26 ),
( 'C (Apr 2020)', 'C (Aug 2020)', 68.97 ),
( 'C (Apr 2020)', 'B (Aug 2020)', 14.35 ),
( 'C (Apr 2020)', 'D (Aug 2020)', 12.41 ),
( 'B (Apr 2020)', 'A (Aug 2020)', 3.78 ),
( 'B (Apr 2020)', 'C (Aug 2020)', 27.26 ),
( 'B (Apr 2020)', 'B (Aug 2020)', 49.72 ),
( 'B (Apr 2020)', 'D (Aug 2020)', 18.74 ),
( 'D (Apr 2020)', 'A (Aug 2020)', 0.98 ),
( 'D (Apr 2020)', 'C (Aug 2020)', 10.15 ),
( 'D (Apr 2020)', 'B (Aug 2020)', 10.87 ),
( 'D (Apr 2020)', 'D (Aug 2020)', 78 )
));

var colors = ('#355C7D', '#355C7D', '#6C5B7B', '#C06C84','#F8B195',
'#6C5B7B','#C06C84', '#F8B195', '#355C7D', '#6C5B7B',
'#C06C84','#F8B195', '#355C7D', '#6C5B7B', '#C06C84',
'#F8B195');

var options = {
height: 400,
sankey: {
node: {
colors: colors,
label: { bold: true}
},
colors: colors,
iterations: 0
}
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Sankey(document.getElementById('sankey_multiple'));
chart.draw(data, options);
}

</script>
</body>
</html>```

(2): https://i.stack.imgur.com/I4bsT.png

## Checking whether there is cycle of odd length in a k-coloring undirected graph

Also, what is the meaning of the notation used in the question- c: v->{0,1,2….k-1} such that c(u)!=c(v)?

## Solving shortest path problem with Dijkstra’s algorithm for n negative-weight edges and no negative-weight cycle

Although many texts state Dijkstra’s algorithm does not work for negative-weight edges, the modification of Dijkstra’s algorithm can. Here is the algorithm to solve a single negative-weight edge without negative-weight edges.

Let $$d_s(v)$$ be the shortest distance from source vertex s to vertex v.
Suppose the negative edge $$e$$ is $$(u, v)$$
First, remove the negative edge $$e$$, and run Dijkstra from the source vertex s.
Then, check if $$d_s(u) + w(u, v) leq d_s(v)$$. If not, we are done. If yes, then run Dijkstra from $$v$$, with the negative edge still removed.
Then, $$forall t in V$$, $$d(t) = min(d_s(t), d_s(u) + w(u, v) + d_v(t))$$

Given the above algorithm, I want to modify the above algorithm again to solve n negative-weight edges and no negative weight cycle. Any hint?

## representation theory – Let \$phi^lambda\$ be the character of \$M^lambda\$. Find a formula for the value of \$phi^{lambda}\$ on a conjugacy class of cycle type \$lambda\$.

Let $$lambda$$ be a partition of $$n$$. The permutation module $$M^lambda$$ is the free $$mathbb{C}$$-module with basis equal to the set of tabloids of shape $$lambda$$. An exercise in Sagan is to find the formula for the character of $$phi^lambda$$ of $$M^lambda$$ on a conjugacy class of $$S_n$$ corresponding to $$lambda$$.

I am familiar with the basic results of the theory but I am stuck on this. Any help would be appreciated.