Git Product home page Git Product logo

dag-ordering's Introduction

DAG Ordering problem.

Source code requires GMock >= 1.1.0 & CMake >= 2.6. Use following commands to configure & build example:

cd build
cmake ..
make

Problem: Find out ordering of Query pairs in DAG. print output 1 if a < b, -1 if a > b, and a zero if the ordering between a and b is undefined.

Solution: 'findQueryOrdering' API uses BFS with queue based mechanism which gives time complexity of O(v + e) where v = vertices and e = edges when using additional visited array of size v. Additional space complexity of O(v) due to tracking if vertices are visited or not.

Additionally tried using topographical sort to squeeze out the additional time complexity by using divide and conquer but bfs seems to be the clear cut case as we use list to store vertices and access them like array.

The speed of the algorithm is always O(v + e) in terms of time complexity and additional space of O(v) for tracking the destination vertices to be searched.

The function 'findQueryOrdering' is already optimized to use caching or visited list vertices so it shouldn't be scanned again. Addtionally, Dijkstra’s algorithm can be used if each vertices has additional data structure consists of weights that can keep track of its underlying DAG. Then we can solve in O(E + VLogV) time using Dijkstra’s algorithm. Since this is an un-weighted DAG, Dijkstra’s algorithm is un-optimized.

With unlimited memory accessible, I'd use hashtable with linear probing. That means each vertices has singular entry in the hashtable with separate chaining. This linked list can contain chains that are stored on heap that points to any of the hashtables slots. This will be treated as edges and serve low memory as linked lists can be simply pointers to the hash slots. Cache of already visited hashslot via traversing chains need to be added for performance. Additionally, a locked hashtable will suit the purpose of traversing a single hashslot treated as 'findQueryOrdering' to find the ordering. h[source] = --> --> --> destination. Utilizing CPU core programming to provide exclusive access to each hashslot can dramatically increase the processing time for each query search. This can be also done on Nvidia GPU's using CUDA programming.

dag-ordering's People

Contributors

thandadude avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

cryptomonger

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.