Tree
A Tree is a collection of nodes in a hierarchical tree structure
What is a Tree? π³
A Tree is a collection of nodes in a hierarchical tree structure. nodes = elements

Fork in the Road πΎ
In a Binary "left 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 π π
If you are a Windows , Mac, or Linux user, think of a File System. A file system is a Tree data structure.
Using """No Code Computer Science""" folder as an example:
Turn on PC, while viewing the desktop
π±οΈ Click on the folder "No Code Computer Science"
3 more folders appear:
"No Code Computer Science", "Data Structure", "Algorithms"
π±οΈClick on the folder "Data Structure"
6 files appear:
"Primitive", "Array", "Dictionary (Hash Map) (Hash Table)", "Linked List", "Tree", "Graph (network)"
π±οΈClick on the file "Tree"
The text for the file "Tree" is shown
You Win!
π¬ View the file structure on Github, not for the faint of hear π¬
https://github.com/KyleMcClay/no-code-computer-science
Why Trees?π³ π΄ π²
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
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.
Last updated
Was this helpful?