Class Arbitrage
 Object

 edu.princeton.cs.algs4.Arbitrage

public class Arbitrage extends Object
TheArbitrage
class provides a client that finds an arbitrage opportunity in a currency exchange table by constructing a completedigraph representation of the exchange table and then finding a negative cycle in the digraph.This implementation uses the BellmanFord algorithm to find a negative cycle in the complete digraph. The running time is proportional to V^{3} in the worst case, where V is the number of currencies.
This code is guaranteed to find an arbitrage opportunity in a currency exchange table (or report that no such arbitrage opportunity exists) under the assumption that all arithmetic performed is without floatingpoint rounding error or arithmetic overflow. Since the code computes the logarithms of the edge weights, floatingpoint rounding error will be present, and it may fail on some pathological inputs.
For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
 Author:
 Robert Sedgewick, Kevin Wayne


Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
main(String[] args)
Reads the currency exchange table from standard input and prints an arbitrage opportunity to standard output (if one exists).



Method Detail

main
public static void main(String[] args)
Reads the currency exchange table from standard input and prints an arbitrage opportunity to standard output (if one exists). Parameters:
args
 the commandline arguments

