We just count how many edges between the targeting node and the root, ignoring directions. The tree-depth of a complete graph equals its number of vertices. This is commonly needed in the manipulation of the various self-balancing trees, AVL Trees in particular. Depth. Given a binary tree, find its minimum depth. Depth –The depth of a node is the number of edges from the node to the tree's root node. The height of a node is the number of edges on the longest path from the node to a leaf. Note that the path must end on a leaf node.
To find the depth of the binary tree we will recursively calculate the depth of the left and right child of a node. The depth of a node is the number of edges from the node to the tree's root node. The depth of a node is the length of the path to its root (i.e., its root path). Else (a) Get the max depth of left subtree recursively i.e., call maxDepth( tree->left-subtree) (a) Get the max depth of right subtree recursively i.e., call maxDepth( tree->right-subtree) (c) Get the max of max depths of left and right subtrees and add 1 to it for the current node. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
The height of the root is the height of the tree. The diameter (or width) of a tree is the number of nodes on the longest path between any two leaf nodes. For example, minimum height of below Binary Tree is 2. Properties of a tree: The height of a tree would be the height of its root node, Similarly, the tree-depth of a complete bipartite graph K x,y is min(x,y) + 1. For example, D's depth is 2. The depth of a particular node in binary tree is the number of edges from the root node to that node. For example, the minimum height of below Binary Tree is also 2. For, in this case, the only possible forest F for which every pair of vertices are in an ancestor-descendant relationship is a single path. A root node will have a depth of 0. The depth of binary tree is the depth of the deepest node (leaf node). We don't care about path any more when depth pops in. or equivalently, the depth of its deepest node.