Neo4j Determine nearest node which has less then two children -


can me solve problem? assume have binary tree should append child following rules:

  • given random node within tree
  • node should apended "child" of given node in nearest available place (as direct child of node has leess 2 children)

i got stuck cypher query of deternine actual parent node (working not correctly).

what have

start n=node({0})  match child-[b_parent]->n  optional match child<-[r:b_parent]-()  count(r) c, child c < 2  return child order id(child) limit 1 

start n=node({0}) match (node1)-[r:b_parent]-(node2)  (node1 <> node2 , node1 = n , count(r)<2) or (node1 <> node2 , node1 <> n , count(r)<3) return node1 order id(node1) limit 1 

the logic here assuming given node in binary tree, @ max have 3 relationships. if root root node have max 2 relationships.

(node1 <> node2 , node1 = n , count(r)<2)  // work root node  (node1 <> node2 , node1 <> n , count(r)<3) //will work other nodes in tree 

so above query should return node open place child having least id.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -