views:

321

answers:

2

This is a simple question from algorithms theory. The difference between them is that in one case you count number of nodes and in other number of edges on the shortest path between root and concrete node. Which is which?

+2  A: 

Depth is edges, height is vertices.

Peter Alexander
Gabriel Ščerbák
@Peter Alexander: Does it make any sense for depth and height to have different conventions? What if they both were `edges` or `vertices`?
Lazer
+8  A: 

I learned it as a Node having a depth and height. The depth of a node is the number of edges from the node to the tree's root, and the height of a node is the number of nodes on the longest path from the node to a leaf. When you take the root of the tree as the subject node, the depth would be 0 and the height would be the number of nodes on the longest path to a leaf.

Virtlink
+1 was about to add quote with same content from here: http://en.wikipedia.org/wiki/Tree_%28data_structure%29
Péter Török
hmm I thought the terminology is not ambiguous, however thanks for the link.
Gabriel Ščerbák