DSA, Database System & Operating System β Data Structure, Lists, Linked Lists and Trees, NEC licence examination syllabus (Nepal Engineering Council).
Three closely related terms that examiners love mixing up on purpose.
Depth (of a node)Number of edges from the ROOT down to that node.
Height (of a node)Number of edges from that node DOWN to its deepest leaf.
LevelDepth + 1 (the root is commonly called level 1, though some texts start at 0 β always check your textbook's convention).
Depth counts upward to the root and belongs to a node. Height counts downward to the deepest leaf. Both are properties of a node β but "the height of the tree" conventionally means the height of the root.
The consequence worth internalising: every leaf has height 0, and the root has depth 0. If a question's numbers seem off by one, it is almost always because depth and height were swapped, or because a source counts nodes on the path rather than edges.Every BST operation costs the height of the tree, not the number of nodes β so height is the performance. For n nodes the height can be anywhere between about logβn when perfectly balanced and nβ1 when fully degenerate.
That range is the entire justification for AVL and other self-balancing trees: they do extra work on insertion specifically to keep the height near logβn, buying a guaranteed bound instead of hoping the input arrives in a lucky order.
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.
Loadingβ¦