The functionality achieved by a tree data structure which is not hierarchical is not of great use. For example, the Binary search tree or Red black tree or AVL tree each of them are have that hierarchical nature.
Example: (Both Hierarchical and linear)
In binary search tree when keys are monotonically increasing or decreasing starting from the root it boils down to a linear structure which is unable to provide us with the necessary searching capability that we want to obtain from tree. That's why we go for AVL or RB tree.
Yes tree can be both hierarchical and linear. The BST when skewed is still hierarchical (it has parent child grandparent relationship among
them ) but they are linearly accessible while searching. Hope this
explains.
A data structure is said to be linear if the elements form a sequence or a linear list, for example Array, Linked list, queue etc. Here in case of BST when skewed it forms basically a linked list like linear structure. That's why my answer mentioned it as linear.
Clarifiction-1
Doesn't that make a linear structure (like linkedlist)?
Yes it is a linear structure.
Linear structures: the time required to search a linear
list is proportional to the size of the data set. For example, if the size of the data set is n,(in case skewed tree) then the number of comparisons needed to find (or not find) an item may be multiple of n(here just one traversal).
Does that mean tree is linear?
A tree is a nonlinear data structure, compared to arrays, linked lists, stacks and queues which are linear data structures. But particular case of skewed-ness it becomes linear. That deviation from it's non-linearity gives it no advantage compared to linear structures like list.
To be more precise: there is no way we are mentioning that to be hierarchical it must be non-linear. Some times linear data structure can be hierarchical too.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…