Code Monkey home page Code Monkey logo

tree-konapaz-distribution's Introduction

tree-konapaz-distribution

Distributed Leaf Nodes Results of Unbalanced and No Binary Tree

https://github.com/konapaz/tree-konapaz-distribution

Assume We have a Tree (Not necessarily Βinary -or Balanced- Tree)

We want to get a list of its Leafs but not in standard way like pre-order post-order in-order ( https://en.wikipedia.org/wiki/Tree_traversal ) We want a balanced-circular order from the top to the bottom Parents Node and get only the Leafs into results, so recursive standard algorithms cannot be Applied.

For example, from the tree of the picture https://github.com/konapaz/tree-konapaz-distribution/blob/master/tree-konapaz-distribution.png we want to give balanced priority for each level Node (Started from Level 1, Nodes with k=1,7,9) So we get the first one Leaf from Node(k=1) then from Node(k=7) and then from Node(k=9) (where Leafs exists in sub-tree). Over and Over again (in Circular terms 1,7,9,1,7,9... ... 1,7,9) until we get all Leafs of the tree. The same Rule should be Applied to all Node's Levels 2,3,4,5... Until we reach the Leaf's Level. Note we don't want to apply the circular rule to the Leaf's Level.

In this example all the Rules will by Applied for Level 1 and Level 2 Level 1: Nodes with k=1,7,9 Level 2: Nodes with k=2,5,8 OR k=11 OR k=14,16 when its turn came from its Parent balanced-order

So the expected results should be:

N(k=0) -> Ν(k=1) -> N(k=2) -> L(k=3)

N(k=0) -> Ν(k=7) -> N(k=8) -> L(k=9)

N(k=0) -> Ν(k=9) -> N(k=11) -> L(k=12)


N(k=0) -> Ν(k=1) -> N(k=5) -> L(k=6)

N(k=0) -> Ν(k=7) -> N(k=8) -> <No any other Leaf!>

N(k=0) -> Ν(k=9) -> N(k=14) -> L(k=15)


N(k=0) -> Ν(k=1) -> N(k=2) -> L(k=4)

N(k=0) -> Ν(k=7) -> N(k=8) -> <No any other Leaf!>

N(k=0) -> Ν(k=9) -> N(k=16) -> L(k=17)


N(k=0) -> Ν(k=1) -> N(k=5) -> <No any other Leaf!>

N(k=0) -> Ν(k=7) -> N(k=8) -> <No any other Leaf!>

N(k=0) -> Ν(k=9) -> N(k=11) -> L(k=13)


N(k=0) -> Ν(k=1) -> N(k=2) -> <No any other Leaf!>

N(k=0) -> Ν(k=7) -> N(k=8) -> <No any other Leaf!>

N(k=0) -> Ν(k=9) -> N(k=14) -> <No any other Leaf!>


N(k=0) -> Ν(k=1) -> N(k=5) -> <No any other Leaf!>

N(k=0) -> Ν(k=7) -> N(k=8) -> <No any other Leaf!>

N(k=0) -> Ν(k=9) -> N(k=16) -> L(k=18)


No more Iterator of Recursive search required because we got all Nine Leaf Nodes! Final results it should be a list with nodes key:

3,9,12,6,15,4,17,13,18


PS: No matter how weird it may seem to you... I needed this code for a special merchant client! :)

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.