DEV Community

Code_Regina
Code_Regina

Posted on

Binary Search Trees

                   -Intro to Trees
-Intro to Binary Trees
Enter fullscreen mode Exit fullscreen mode




Intro to Trees

Trees are a data structure that consists of nodes in a parent/child relationship. Tree data structures brach off from on node to the other in a top-down direction.

Alt Text

Each node can point to another node.

Alt Text

Trees are nonlinear data structures because they branch off of other nodes and do not move in a straight forward fashion. The branching makes trees flexible. Meanwhile, lists are linear data structures because they move from one after the other in a straight line direction.

Alt Text

When a data structure is not a tree

Alt Text

This picture is a graph not a tree.
Not a tree because there are nodes that are references other nodes that are not below them.

A node can only point to a child.

A child can not point to a parent.

Alt Text

The root of a tree is the top node.
The child is a node directly connected to another node when moving away from the root.
The siblings is a groups of nodes with the same parent.
The leaf is a node with no children.
The edge is a connection between one node and another.

Intro to Binary Trees

Alt Text

A binary tree is when a node can only have a max of two children. A node may have a single child or no children and still be a binary tree.

Binary Search Tree

Alt Text

Special case of a binary search tree that is sorted in a specific way. BST are used to store data that can be compared.
Every node to the left of a parent node is always less than the parent.
Every node to the right of the parent node is always greater than the parent.

Top comments (0)