Skip to content

amiresaye6/binary_trees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binary Tree Basics 🌳

This repository provides information and code related to binary trees.

Table of Contents 📚

What is a Binary Tree? 🌱

A binary tree is a data structure consisting of nodes, where each node has at most two children referred to as the left child and the right child. These children are usually known as the left subtree and right subtree, respectively.

Difference between Binary Tree and Binary Search Tree 🌲

While both are binary trees, a Binary Search Tree (BST) has an additional property. In a BST, the left subtree contains nodes with values less than the parent node, and the right subtree contains nodes with values greater than the parent node.

Time Complexity Gain compared to Linked Lists ⏰

Binary trees can offer significant improvements in terms of time complexity over linked lists for certain operations. For example, searching, inserting, and deleting elements in a balanced binary search tree can be performed in O(log n) time, whereas in a linked list, these operations typically take O(n) time.

Depth, Height, and Size of a Binary Tree 📏
  • Depth: The depth of a node is the number of edges on the path from the root node to that particular node.
  • Height: The height of a tree is the maximum depth of any node in the tree.
  • Size: The size of a tree is the total number of nodes in the tree.
Traversal Methods for Binary Trees 🚶‍♂️

There are several ways to traverse a binary tree:

  • Inorder Traversal
  • Preorder Traversal
  • Postorder Traversal
  • Level Order Traversal
Types of Binary Trees 🌿

Complete Binary Tree 🌐

A binary tree is considered complete if all levels of the tree are completely filled except possibly for the last level, which is filled from left to right.

Full Binary Tree 🌳

A binary tree is considered full if every node has either 0 or 2 children.

Perfect Binary Tree 🌲

A binary tree is considered perfect if all of its levels are completely filled.

Balanced Binary Tree ⚖️

A binary tree is considered balanced if the height of the left and right subtrees of every node differ by at most one.


Example Tree Structure 🌱

           1
         /   \
        2     3
       / \   / \
      4   5 6   7
     / \       / \
    8   9     10  11
   / \   \       / \
  12  13  14    15  16

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors