# Introduction to Tree Data Structure

In computer science, a tree is an abstract model of a hierarchical structure. A tree consists of nodes with a parent-child relation. Previous data structures placed data in linear order. Some data organizations require categorizing data into groups, subgroups. Trees are a hierarchical data structure of nodes. Nodes are linked by edges. A parent node references one or more nodes (children nodes) that are “lower” in the tree hierarchy.

If node u has address of node v, then v is the child of u

### Root Node

Node without parent is called root node. Except for the root (no parent), every node has exactly one parent (by definition). A tree has only one **root node.**

### Sibling Node

**sibling**.

### Internal Nodes

**internal**if it has one or more children.

### Leaf Node

**leaf**if it has no children

### Ancestor and Descendant Nodes

**ancestor**of a node is either the node’s parent or any ancestor of the node’s parent i.e. parent, grandparent, grand-grandparent. The root is an ancestor of every other node.

**Descendant**of a node: child, grandchild, grand-grandchild.

### Subtree

**subtree**of T rooted at node v is the tree consisting of all the descendents of v in T (including v)

### Depth of a Tree

### Height of a Tree

The path from the root, A, to the leaf, I, is denoted as AFI and has a length of 2. ABD is the path from the root, A, to the leaf, D, and also has a length of 2.

### Types of Trees

**1. General tree**– a node can have any number of children

**2. Binary tree**– a node can have at most two children

### Related Posts

- Binary Search Trees and Data Structure
- Heap data structure in C++
- Binary Trees and Binary Search Trees
- Binary Expression Trees
- Graph search in C++
- Heap Sort with Graphical Explanation
- Introduction to Graph data structure
- Queue Implementation in C++
- Operations on Binary Search Trees (BST)
- Doubly Linked Lists
- Circular Linked Lists
- Advanced Data Structures Tutorial using C++

### Popular Posts (last 30 days)

- Attendance Management Sys… 1185 view(s)
- Graph Implementation in C… 587 view(s)
- Implementing Stack Data S… 578 view(s)
- Circular Linked Lists 524 view(s)
- Applications of Stack in … 523 view(s)
- Simple Currency Converter… 442 view(s)
- GRASP Design Patterns 328 view(s)
- Advanced Data Structures … 265 view(s)
- C++ Tutorial for Intermed… 253 view(s)
- Sockets and Network Progr… 185 view(s)

### Related Links

### Tags

Android C-Sharp C/C++ language Classes Data structures Design Pattern Eclipse Game Development Graphics Design Books HTML iPhone JAVA JAVA GUI MIPS Assembly Mobile Programming Books Object Oriented PDF PHP Programming Programming Books Programming Languages Books Python RaphaelJS REST Source Code Threads Tutorial Web Development Books