Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Level (or depth) of a node #17

Open
giacomoratta opened this issue Aug 23, 2018 · 1 comment
Open

Level (or depth) of a node #17

giacomoratta opened this issue Aug 23, 2018 · 1 comment

Comments

@giacomoratta
Copy link

When I use the Iterator, I would want to know the level of a node.
Is there a (low complexity) way to have the level of a node?

Level: "The level of a node is defined as: 1 + the number of edges between the node and the root."
Depth: "The depth of a node is the number of edges from the tree's root node to the node."
(from Wikipedia)

Would be also interesting to have other characteristics about the tree:

  • is Branch node (or is Internal node)
  • Height of node
  • Height of tree
  • Depth
@Joris-van-der-Wel
Copy link
Member

There already is a method to figure out if something is an internal vs external node: tree.hasChildren(obj).

Figuring out the depth/level could be sped up by using a cache. On a static tree it would then average out to O(1). This is similar to how tree.index(obj) works (the number of preceding siblings). I think figuring out the height could be done in a similar way. But i'll have to see when i have some time to add this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants