Git Product home page Git Product logo

tree-of-nodes-api's People

Contributors

tqc-michalp avatar

Watchers

 avatar

tree-of-nodes-api's Issues

Fix /common_ancestor logic

Your issue may already be reported! Please search on the issue tracker before creating one.

Context

It seems that the logic processing by CommonAncestorService for issue number #2 is returning incorrect results

Behavior

Actual

Steps to reproduce

Expected

Implement specs from the issue description #2 to ensure the logic is correct.

Possible Fix

System configuration

  • Version:
  • *.lock files as a text in a GitHub Gist:
  • Relevant stack(full preferred) traces:

Implement new endpoint /birds and model birds

Your issue may already be reported! Please search on the issue tracker before creating one.

Is your feature request related to a problem?

n/a

Describe

Nodes have_many :birds and birds belongs_to :node.

Solution

Endpoint should take an array of node ids and return the ids of the birds that belong to one of those nodes or any descendant nodes.

Alternatives

n/a

Additional

n/a

Import CSV Data into Database

Your issue may already be reported! Please search on the issue tracker before creating one.

Is your feature request related to a problem?

Currently data is in db/seeds/nodes.csv file. We need them to be persisted in database.

Describe

The objective of this feature request is to allow the storage of dynamic data in database to facilitate efficient retrieval and updating of data.

Solution

To achieve this, we will need to design a database schema then create migration to seed the database. Model should be named: Node.

Alternatives

n/a

Additional

n/a

Implement new endpoint /common_ancestor

Your issue may already be reported! Please search on the issue tracker before creating one.

Is your feature request related to a problem?

n/a

Describe

The /common_ancestor endpoint is used to find the lowest common ancestor of two given nodes in a tree. This endpoint requires two parameters, namely a and b, and returns three pieces of information about the lowest common ancestor. These include the root_id of the tree, the lowest_common_ancestor_id of the two nodes, and the depth of the lowest common ancestor in the tree. By providing these details, the /common_ancestor endpoint enables users to efficiently determine the relationship between any two nodes in a tree structure.

For example, given the data for nodes:

   id    | parent_id
---------+-----------
     125 |       130
     130 |          
 2820230 |       125
 4430546 |       125
 5497637 |   4430546

/common_ancestor?a=5497637&b=2820230 should return
{root_id: 130, lowest_common_ancestor: 125, depth: 2}

/common_ancestor?a=5497637&b=130 should return
{root_id: 130, lowest_common_ancestor: 130, depth: 1}

/common_ancestor?a=5497637&b=4430546 should return
{root_id: 130, lowest_common_ancestor: 4430546, depth: 3}

if there is no common node match, return null for all fields

/common_ancestor?a=9&b=4430546should return
{root_id: null, lowest_common_ancestor: null, depth: null}

if a==b, it should return itself

/common_ancestor?a=4430546&b=4430546 should return
{root_id: 130, lowest_common_ancestor: 4430546, depth: 3}

Solution

n/a

Alternatives

n/a

Additional

n/a

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.