# Introduction to Trees

### Summary and Introduction to Trees

A major skill in computer programming is understanding how to work with data. The simplest way to store data is in a simple variable:

```
int	my_int = 3;
```

A slightly more complicated storage mechanism is the array:

```
int	my_array[MAX_SIZE];
```

Trees are simply another way of arranging and storing the data. Trees get their name because the general shape of the structure (if you draw it out) resembles a tree. All of the elements in the tree are called nodes. Just like a family tree, there is one node from which all the other nodes descend. This is the root node. Each of the descendents can also have descendents. In other words, each child of the root can be seen as the root of its own tree. It is in this way that a tree is naturally recursive. This means that at each level, we find essentially the same structure. If you pick any node in the tree and consider from it down, you still have a tree. Even if you pick a leaf, you have a tree, albeit a branchless one.

The next question is when and why you might want to use such a structure. There are situations in which the data itself can naturally be thought of as a tree. Such an example is a family genealogy, where each person is always a child of someone else and has the potential to have children. In addition, there are many situations where trees make implementing certain algorithms very simple. In the section on binary search trees we will see such an application. The fact that the data in a tree is arranged hierarchically makes it easier (quicker in terms of the number of branches between the root and any other node) to access nodes. This makes a tree a very appropriate structure for holding data that must be searched often.

## Take a Study Break

### Star Trek gets SEXY

Chris Pine and Zoe Saldana heat up the red carpet!

### Are you afraid of relationships?

Auntie SparkNotes can help!

### Sexy starlet style

See every single look from the Met Gala!

### Geeky Actors: Then and Now

Travel back in time!

### Villains We Want These Actresses to Play

From super cute to super bad!

### 10 Movies Better Than Their Books

What do you think?

### How To Look Like J-Law...

When you don't look like J-Law.

### 12 Scientific Inaccuracies in Into Darkness

What did Star Trek get wrong?

## The Book

### Read What You Love, Anywhere You Like

Get Our FREE NOOK Reading Apps