Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

share|improve this question
3  
What makes you doubt it? –  delnan Jan 5 at 1:00
1  
As long as the parent links and the children links are distinct, you can assume that the children links make the tree and the parent links are just an implementation detail. –  mouviciel Jan 6 at 10:13

3 Answers 3

up vote 8 down vote accepted

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.

share|improve this answer
    
+1 for pointing out that having parent links (links in both directions) makes the graph equivalent to an undirected graph. –  Giorgio Jan 5 at 9:33
    
Can we say any acyclic graph is a tree? –  Mohsen Jan 5 at 16:41
3  
@Mohsen A (directed) acyclic graph that includes a node with two parents is not a tree –  Izkata Jan 5 at 21:23
    
@Mohsen: You can also define a tree as a graph with a distinct root node such that there exists a unique path from the root to any other node. Clearly, there are acyclic graphs that do not fulfill this definition. –  Giorgio Sep 28 at 13:39

Tree (graph theory) wikipedia :

In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two vertices are connected by exactly one simple path. In other words, any connected graph without simple cycles is a tree. A forest is a disjoint union of trees.

There is tones of cycles in this graph, so no it's not a tree.

share|improve this answer
4  
There are tons of cycles in this directed graph, but none in this undirected graph. –  U2EF1 Jan 5 at 19:38

Let's follow this definition. Will surely get the ans.

A connected graph G is called a tree if the removal of any of its edges makes G disconnected. So, as the graph given above, does not support this statement, so we can not say that the graph given is a tree.

For more info you can continue this link.

http://win.ua.ac.be/~vanhoudt/graph/trees.pdf

share|improve this answer
1  
You are using the mathematician's point of view here. Note that U2EF1 says in their answer: A computer scientist would probably still call these things trees, a mathematician would not.. Your answer is basically the same as Uiquité's in this respect. –  Martijn Pieters Sep 28 at 9:11
    
The cited paper assumes undirected graphs. This definition of trees is not appropriate for a directed graph, because (a) it would have to mention that DAGs including trees can at most be weakly connected, and because (b) it allows multiple root nodes. Now notice that the graph in the question is a directed graph (albeit one with backlinks), and that there still is a concept of a root node (hierarchy is denoted by vertical position). A better definition for a directed tree would be: “A (directed) tree is empty or has exactly one root node from which all nodes are reachable”. –  amon Sep 29 at 9:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.