DAY 5 — Tree

Yasir
2 min readSep 28, 2020

--

It’s a series of revising DS algo. Check this link for more details .

Photo by Glenn Carstens-Peters on Unsplash

Intuition

A tree is a data structure similar to a linked list but instead of each node pointing simply to the next node in a linear fashion, each node points to a number of nodes.

Terminologies

Depth of A Tree

The depth of a node is the length of the path from the root to the node . And it starts from zero .

Height of A Tree

Counting height for any node starts from left nodes to the target node . And starts from zero .

Balanced Trees

The depth difference in tree should not be more than 1.

Right Skew Tree AND Left Skew Tree

Binary Tree

A tree is called binary tree if each node has zero child, one child or two children. Empty tree is also a valid binary tree.

Types of Binary Trees

Strict Binary Tree or Full Binary Tree : A binary Tree is called strict binary tree if each node has exactly two children or no children.

Complete Binary Tree : Except the last level , tree is completely filled and last level from left to right .

Perfect Binary Tree : All interior nodes have two children and all leaves are at same level .

Binary Search Tree

All node in left tree should less then the parent node and all node in right should greater then the parent node .

If you have some elements in accessing order and you are making a BST , you will got a right skew tree and vise versa .

Implementations

To find all Implementations , please go through this link .

In the link given above , there are program with their complexity .

Sources

My LinkedIn — linkedin.com/in/my-pro-file

To become a part of this series checkout this link .

--

--

Yasir
Yasir

Written by Yasir

Exploring Swift, SwiftUI, and Apple Universe.

No responses yet