Code Monkey home page Code Monkey logo

algorithms's Introduction

Algorithms

Some algorithms implemented in C.

Bellman-Ford:

Computes shortest paths from a single source to all other vertices in a weighted directed graph.

./a.out <input file> <source>

input file: line1: number of vertices, line2~n: adjacency matrix of the graph.
source: the source vertice.

This will save a bellman_ford_out.txt file to the directory.

Find Max Sum in Array:

Find maximum sub-array in an array.

./a.out

elements: the size of the randomly generated array

Also provide an optimized version.

Johnson Algorithm:

Computes shortest paths between all pairs of vertices in a sparse, edge weighted, directed graph.

The algorithm works as this:

  1. add a node q to the graph, connected by zero-weight edges to each of the other nodes.
  2. do bellman ford algorithm from source q, resulting h(v) of a path from q to v. Terminate if negative weight cycle is found.
  3. reweight the graph by w(u, v)' = w(u, v) + h(u) - h(v)
  4. remove q and do dijkstra algorithm to find the shortest paths from each node s to every other vertex in the reweighted graph.
./a.out <input file>

input file: line1: number of vertices, line2: number of edges, line3~n: .

This will save a johnson_out.txt file to the directory.

Merge Inversion:

Counts how many inversions used in a merge sort.

./a.out

10 numbers: give an array.

N-Queen problem:

The classic N-Queen problem.

Optimal Binary Search Tree:

Computes the optimal binary search tree given probabilities pi and qj.

./a.out <input file>

input file: line1: (node 1, probability p1) (node 2, proba...), line2: (dummy keys 0, probability q0) (dummy keys 1, proba...)

This will save a optimal_bst_out.txt file to the directory.

Shannon-Fano coding:

Construct a prefix code based on a set of symbols and their probabilities.

./a.out

8 elements: number in sorted order

algorithms's People

Contributors

markdtw avatar

Watchers

 avatar

algorithms's Issues

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.