Data Structures – Is a Tree with Nodes Referencing Parent Still a Tree?

data structurestrees

If we make reference to the parent for each node in a tree, do we still have a tree (by definition) anymore?

Wikipedia definition is:

In computer science, a tree is a widely used abstract data type (ADT)
or data structure implementing this ADT that simulates a hierarchical
tree structure, with a root value and subtrees of children,
represented as a set of linked nodes.

enter image description here

Best Answer

A tree is a connected acyclic graph. In the case where we have "parent" links this would just be an undirected tree, but definitely still a tree. If you were to specify that the example is a directed graph it would not be considered a tree (but of course there's no way of telling from the code which was intended).

Some computer science "trees" will include, for instance, links from each node back to the root, or links along each level of a B+ tree. A computer scientist would probably still call these things trees, a mathematician would not.