Giter Club home page Giter Club logo

swiftydijkstra's Introduction

SwiftyDijkstra

Simple code showing how dijkstra's algorithms works when coded from scratch. The bulk of the work is in creating the priority queue / min heap.

Class Structure

  • Graph: Contains the list of vertices. Is used as a place to put data after Dijkstra's is run through the graph.
  • VertexEdges: Contiains Vertex class which contains a dictionary of edges whose value is a Vertex, and key is the Weight. It also contains id, and data. Each Vertex is comparable, hashable, & printable.
  • MinHeapMap: Special type of min heap that includes a map, so you can map vertices to priorities in the heap. Given a vertex, this heap will map the vertex to a position in the heap, where it's priority value resides. This makes for easier coding when dealing with dijkstra's.
  • Dijkstra: Main Playground where it shows initialization of all the vertices and weights. As well as Dijkstra's Algorithm. It uses the relaxtion principle which says the following:
Relaxation Principle
---------------------


d[v] -> Length of current shortest path from source s to v
PI[v] -> Predecessor of v in the shortest path from s to v
w(u,v) -> Weight function that calculates the weight from u to v
u -----2----- v
w = 2

relax(u,v,w)

-------------------------------------------------
if (  d[v] > d[u] + w(u,v)   )
then (   d[v] = d[u] + w(u,v);   PI[v] = u     )
-------------------------------------------------

d[v] -> Length of current shortest path from source to v
PI[v] -> Predecessor of v in the shortest path in s -> v

This current code of Dijkstra's is slow however. It runs in O( E(log(E)) + V(log(V) ) E -> Edges, V -> Vertices

  • Decrease Operation is log(V)
  • Extract-Min Operation is O(1) for actually extracting... but maintaining the heap after that takes log(V) time
  • You must run through every Edge and Vertex, so that's where the multiplying coefficients come into place

This can be speed up using a different data structure: Fibonacci Heap


Developing...

swiftydijkstra's People

Contributors

sgangele21 avatar sgangele36 avatar

Watchers

James Cloos avatar  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.