Would you call it level or depth?

和自甴很熟 提交于 2020-01-24 02:59:06

问题


Which word would you pick to label the absolute stack level of an element—in other words its degree of nesting relative to the root/document element?

Between level and depth which one would you choose and why? What is commonly used or preferred? Which one would you find less confusing in the absence of a meaningful context?

I tried checking the XML specification without much success.


回答1:


I call it Depth.

As we know, XML is a Node based structure.

We all know that in Data Structures we use both terms at widely.

If we talk about a Binary Tree structure we generally say

In which depth level a node is situated/located?

We also use this term in DFS (Depth First Search) and BFS (Breadth First Search). When we go down we call it level depth/down (deep) and when we go up we call it level up. So level represents position at specific point but depth represents How Deep it is. Below is an representation of what I would like to convey

In XML, if we want to find out elements that are at a deeper level (depth) we use descendant. What does it means? We're referring to the depth level of the element.

In AVL Binary Tree, generally, we count the level of a Node and based on it we rotate the tree to make it balanced.

In other words,

The depth of a node is the length of the path to its root (i.e., its root path) or depth is the is maximum distance from any node to root.

The level of a node is the number of nodes on the longest path from the node to a leaf.

Reference from wikipedia

But if we talk about XML Structure, the term Depth is best to represent XML Nodes. So I choose Depth.

Edit: Thanks to @Alex for his valuable edition. After his addition I also edited few things to improve the answer.




回答2:


To me level means going up, and depth means going down.

So I'd pick depth.

But I've learned a rule: If you can't pick between two options it's because both options are equally good, so flip a coin and move on.




回答3:


A "level" represents all nodes that have the same depth within a tree (a grouping construct). The depth is therefore the integer representing the relative distance from the root node to any other node.

So imho I would go for "depth" as the integral value, and all nodes with the same "depth" are on one "level".




回答4:


I would go with depth.

Apparently a lot of people use level and depth interchangeably. But in my understanding level can refer to how far away from the root element one element is or to all element that share the same distance to the root element. To avoid this ambiguity I would prefer depth.

In addition trees are usually presented with their root element at the top, like NullVoid showed. Since you can treat XML elements as a tree with nodes, we have another argument to support depth. A last one would be that depth works, because of the way XML elements are represented in a XML file ;-)




回答5:


I use both interchangeably. ___




回答6:


If you're talking in terms of a 'stack', as in the data-structure, then depth is the preferred term. From the perspective of an XML document, both nesting depth and level seem to be in common usage. A quick google survey shows roughly 600000 results for 'xml nesting level' and 'xml nesting depth'.

I'd say pick one and stick with it consistently in the same context.




回答7:


Depth for a specific position in the tree, level for traversing the tree. I.e Go down one level from depth 5.

What is the depth of your level?

What is the level of your depth?

How many levels from the depth 5 are you?

How many depths from the level 5 are you?




回答8:


level and height are same but depth is the is maximum distance from any node to root... and reverse in the case of height.




回答9:


I would go with the term depth.

XML is Tree based representation and so is DOM.

If we take a Tree as an example:
Depth of a node denotes the #of edges between that node and the root. This is invariant.
On the other hand "level" is arbitrary. Level values are determined by what level I place the root node at (level 0 or level 1)

Since you are developing a programming language, I tried to look at places where they actually have a Depth Property for XML Nodes:
1. .NET : XMLTextReader has depth property.
2. Javascript : No Inbuilt depth property.



来源:https://stackoverflow.com/questions/16429127/would-you-call-it-level-or-depth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!