Giter Site home page Giter Site logo

etrian-dev / spt Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 58.52 MB

Algorithm that solves the SPT problem on a graph G = (N, A)

License: GNU General Public License v3.0

C 91.00% Makefile 2.15% C++ 6.86%
spt bellman-ford dijkstra directed directed-graph

spt's Introduction

Shortest Path Tree on a graph

This repository contains a simple implementation of two algorithms for solving the shortest paths tree problem (SPT) on a directed weighted graph G = (N, E). The file spt.l.c contains the implementation of the Bellman-Ford algorithm, whereas the file spt.s.c contains the implementation of Dijkstra's algorithm. The latter is more efficient on graphs whose weights are all positive, especially if they are dense (that is, E is closer to O(n^2), rather than O(n)). Bellman-Ford, moreover, detects negative cycles in the graph and exits (no lower bound exists on these instances). Otherwise, the algorithms find one optimal solution and ouput in as a predecessor array and labels array.

Specifying input

The algoritms read a graph from standard input; the format is the one supplied in the tests directory: an integer representing the number of nodes in the graph (its order) and a series of lines, representing a node's adjacency list.
A few remarks:

  • Nodes with an empty adjacency list (degree 0) are represented by empty lines (\n)
  • Nodes are referred to as integers ranging from 0 to n-1, where n is the graph's order
  • To specify the (directed) edge i -> j one should write in i's adjacency list (the i-th line) j:weight, where weight can be any real number, and then a blank
  • The algorithm asks for a root node, the nodes where all paths start from, so one should include it as the last line of the input as well. Obviously root must follow the above rules for vertices'indexes

License

GPLv3.0, provided in COPYING

spt's People

Contributors

etrian-dev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.