Comments (4)
Hi, it's been a long time since I looked at Baobab, so forgive me for any imprecision.
The tree built in a nested set model is not a binary tree. Every node can have 1 to N children, so children are not really split between left and right.
Your red "left most" node is not left most at all, it's not left or right of its child (or left or right of its parent), so it's not special in any way.
Here's your tree using some labels (easier to talk about, using mermaid syntax in markdown)
graph TD;
A-->B;
A-->C;
B-->D;;
B-->E;
D-->G;
G-->L;
C-->F;
F-->H;
F-->I;
H-->M;
I-->N;
N-->O;
If I were to search for leftmost and rightmost, I'd say they are L
and O
.
You can find them using getLeaves()
, then in the resulting array they will be the first one (L
) and the last one O
from baobab.
Thank you for your kindly reply
I do understand that the nested set lft and rgt are not RIGHT LEFT of the node.
for that reason, am only add 2 children for the node, and to mark if this child is on the left or right side of the node to create binary tree, I created another field named a position which I will mark the node if it is On The LEFT or Right, and when I want to insert a new node I will give it this mark.
Noe let's assume the "L
" has a new child on the RIGHT. So L will not be Leave
but the "LEFT" as a binary is empty.
So how can i get if the node is Leave or it has one child?
from baobab.
Uh, that's quite special, let's see. In your tree, every parent of a single leaf have rgt - lft == 3
, so you could search for them using a SQL query and then see if their only child is left or right. This is not fast but it's not terrible either (you have to investigate only children of single parents)
from baobab.
Thank you , problem solved
from baobab.
Related Issues (15)
- Vertebrates HOT 1
- Any plan to add PDO support? HOT 3
- Boabab build error
- View definition error
- Composer autoload fails on Linux
- How to create binary tree?
- Retrieve from tree to display a nav menu ? HOT 2
- Get all trees HOT 6
- SQL query: Error HOT 1
- Concurrent user
- Is there a node version about this? HOT 1
- Error with no detail on DeleteNode HOT 3
- Is there a way to rebuilding or repairing tree ?
- Duplicate branch? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from baobab.