Difference between revisions of "W3151 Trees"

From Coder Merlin
(→‎Structure: add structure instruction)
Line 11: Line 11:
The use of Trees as Data Structures can be seen everywhere: file systems, relationship hierarchies, visual displays and GUIs and many more. This is why developers ought to understand this data structure and how to apply it.
The use of Trees as Data Structures can be seen everywhere: file systems, relationship hierarchies, visual displays and GUIs and many more. This is why developers ought to understand this data structure and how to apply it.
== Structure ==
== Structure ==
As has been mentioned, the structure of a Tree is made entirely of '''Nodes''' where each node has some data that's being stored and references to other Nodes lower in the tree. If you look at a Node in a tree, it will likely be referencing one or several Nodes beneath it. These Nodes that are being referenced are called the '''Children''' or '''Child Nodes''' while the Node they come from is their '''Parent.'''
Its important to understand that in a typical Tree, ''a Node can only have One Parent but multiple children.''
Now, looking at the Structure of a tree, it starts with '''The Root.''' The root is the very top of a Tree's hierarchy and can be recognized because it is the only Node that is not referenced to by another Node. Conversely, a Tree will end with '''Leaves.''' Leaves are simply the Nodes that do not reference any other Node.
Additionally, in Trees there's the concept of '''Level.''' The Root will always be Level 0 and its immediate Children will be Level 1, their children will be level 2 and so on. Note that a Leaf can come up in any Level greater than 0, not just the lowest level in the tree.
For clarification on a Tree's Structure, consult the following diagram.


== Complexities ==
== Complexities ==

Revision as of 21:05, 20 January 2022

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
A Magnolia Tree

Prerequisites[edit]

Introduction[edit]

In Computer Science, Trees are a hierarchal data structure that are very commonly used. At its core, the Tree is a series of nodes where each node contains some data and references one or multiple other nodes called Children. These structures are called Trees because of the visual resemblance between the data structure and a tree's roots. It's because of this that the top most Node is called the root.

The use of Trees as Data Structures can be seen everywhere: file systems, relationship hierarchies, visual displays and GUIs and many more. This is why developers ought to understand this data structure and how to apply it.

Structure[edit]

As has been mentioned, the structure of a Tree is made entirely of Nodes where each node has some data that's being stored and references to other Nodes lower in the tree. If you look at a Node in a tree, it will likely be referencing one or several Nodes beneath it. These Nodes that are being referenced are called the Children or Child Nodes while the Node they come from is their Parent.

Its important to understand that in a typical Tree, a Node can only have One Parent but multiple children.

Now, looking at the Structure of a tree, it starts with The Root. The root is the very top of a Tree's hierarchy and can be recognized because it is the only Node that is not referenced to by another Node. Conversely, a Tree will end with Leaves. Leaves are simply the Nodes that do not reference any other Node.

Additionally, in Trees there's the concept of Level. The Root will always be Level 0 and its immediate Children will be Level 1, their children will be level 2 and so on. Note that a Leaf can come up in any Level greater than 0, not just the lowest level in the tree.

For clarification on a Tree's Structure, consult the following diagram.

Complexities[edit]

Swift Implementation[edit]

Beyond Basic Trees[edit]

Key Concepts[edit]

Exercises[edit]

References[edit]