# Tree

## What is a Tree? :deciduous\_tree:&#x20;

A **Tree** is a collection of nodes in a hierarchical tree structure. nodes = elements

![Left or Right?](/files/-MLxy-M1qpgJ7XTmAzoX)

## Fork in the Road :feet:&#x20;

In a **Binary "**&#x6C;eft or right" **Tree**, (start with looking at the picture first) the root node connects to a left node and a right node. The left node then connects to a left node and a right node. The right node also connects to a left node and a right node. and etc etc...

```
        Start (Root Node)
               '
       -------------------
      '                   '
      A                   B
      '                   '
 -----------         -----------
'           '       '           '
C           D       E           F
```

## Folder -> Folder -> File :file\_folder: :open\_file\_folder:&#x20;

If you are a Windows , Mac, or Linux user, think of a **File System**. A file system is a **Tree** data structure.&#x20;

Using """No Code Computer Science""" folder as an example:

* *Turn on PC, while viewing the desktop*
  * :mouse\_three\_button: *Click on the folder "No Code Computer Science"*
* *3 more folders appear:*&#x20;
  * *"No Code Computer Science", "Data Structure", "Algorithms"*
  * :mouse\_three\_button:*Click on the folder "Data Structure"*
* *6 files appear:*&#x20;
  * *"Primitive", "Array", "Dictionary (Hash Map) (Hash Table)", "Linked List", "Tree", "Graph (network)"*
  * :mouse\_three\_button:*Click on the file "Tree"*
* The text for the file "Tree" is shown
  * You Win!

:grimacing: View the file structure on Github, not for the faint of hear :grimacing:&#x20;

<https://github.com/KyleMcClay/no-code-computer-science>

## Why Trees?:deciduous\_tree: :palm\_tree: :evergreen\_tree:&#x20;

Trees are great for searching, every level deeper in the tree results in cutting the possible nodes in half (finds the answer fast).

* *1000 nodes -> 500 nodes -> 250 nodes -> 125 nodes ->  60 nodes  -> 30 nodes -> 16 nodes -> 8 nodes ->  4 nodes -> 2 nodes -> 1 node*&#x20;

A **Tree** is useful when the data is evenly distributed throughout the tree for quick search. If a tree stored all data only on the right side, then you would have a linked list data structure and not a tree data structure.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ksmcclay.gitbook.io/no-code-computer-science/data-structures/tree.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
