algorithmdata-structurestreenodesterminology# What is the difference between depth and height in a tree?

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?

Solution

I learned that depth and height are properties of a *node*:

The

**depth**of a node is the number of edges from the node to the tree's root node.

A root node will have a depth of 0.The

**height**of a node is the number of edges on the*longest path*from the node to a leaf.

A leaf node will have a height of 0.

Properties of a *tree*:

The

**height**of a tree would be the height of its root node,

or equivalently, the depth of its deepest node.The

**diameter**(or**width**) of a tree is the number of*nodes*on the longest path between any two leaf nodes. The tree below has a diameter of 6 nodes.

- Is there a way to generate a random variate from a non-standard distribution without computing CDF?
- How to check whether a matrix is a framed matrix?
- Most efficient way to calculate VWAP(VOLUME WEIGHTED AVERAGE PRICE) for trading algorithm
- How to find and replace all occurrences of a substring in a string?
- How to find kth smallest element in a BST when the tree may be modified frequently?
- Calculate distance between two latitude-longitude points? (Haversine formula)
- How does one make a Zip bomb?
- How to calculate the midpoints of each triangle edges of an icosahedron
- Calculate circular shift pairs in a list
- Uniformly randomly generate a vector of k unsigned ints that sums to N
- Identify connected subnetworks (R-igraph)
- Mapping elementwise Tuple Using Template Function
- Find the longest prefix for a table of tokenized strings
- Count Unguarded Cells in the Grid (recursion)
- Kalman Filter Prediction Implementation
- My ALV Tree balance factors calculate incorrectly
- Infix to postfix left one parentheses at the end when expression is fully enclosed
- C++ quick sort algorithm
- Merge Sort Function not working when size of vector is not 2^n
- Given an array a of n integers, and q queries, for each value from index l to index r, add x to the value
- Count mountain arrays
- Get the number of all possible combinations that give a certain product
- getting TLE in leetcode question 212- word search 2 using backtrcaking even after pruning, how do i optimize it more
- Maximizing the sum of Adjacent sum in an array
- Weighted random selection from array
- If f(n) = O(g(n)), is log(f(n)) = O(log(g(n))?
- Why is KNN slow with custom metric?
- Based on a condition, how to remove an item from the processed array and move it to another array?
- The simplest algorithm for poker hand evaluation
- Find longest repetitive sequence in a string