0% found this document useful (0 votes)
47 views

Binary Tree Tahsin

Binary trees are a data structure where each node has at most two child nodes. A binary tree starts with a single root node, and each node contains data and pointers to its left and right child nodes. Common operations on binary trees include insertion, deletion, and traversal. Binary trees allow storing and organizing data efficiently with logarithmic time complexity for operations like search and insertion when the tree is balanced. They are used to implement memory allocators and search engines.

Uploaded by

Rojot Saha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Binary Tree Tahsin

Binary trees are a data structure where each node has at most two child nodes. A binary tree starts with a single root node, and each node contains data and pointers to its left and right child nodes. Common operations on binary trees include insertion, deletion, and traversal. Binary trees allow storing and organizing data efficiently with logarithmic time complexity for operations like search and insertion when the tree is balanced. They are used to implement memory allocators and search engines.

Uploaded by

Rojot Saha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Binary Tree

Presented By
Tahsin Akhter
183120018
What is Binary tree?

 A binary tree is a special type of tree in which every node or vertex has either no
child node or one child node or two child nodes. They are used to store and
organize data.

 A binary tree is a tree data structure composed of nodes, each of which has at
most, two children, referred to as left and right nodes. The tree starts off with a
single node known as the root.
Working Process:
 Each node in the tree contains the following:
 Data, pointer of left child and pointer of right child
 Here are the common operation are:
 Insertion : Elements may be inserted into a binary tree in any order. The very first insertion operation
creates the root node. Each insertion that follows iteratively searches for an empty location at each
level of the tree.
 Upon finding an empty left or right child, the new element is inserted. By convention, the insertion
always begins from the left child node.
 Deletion : An element may also be removed from the binary tree. Since there is no particular order
among the elements, upon deletion of a particular node, it is replaced with the right-most element.
 Let’s look at an example to get a better idea of how the deletion process works.
 3. Tree traversal
 Another frequently used tree operation is traversal. Tree traversal is the process of visiting each node
present in a tree. There are three methods of tree traversal:
 In-order traversal: Traverses a tree in a in-order manner.
 Pre order traversal: Traverses a tree in a pre-order manner.
 Post order traversal: Traverses a tree in a post-order manner.
Advantage of Binary tree
 we can always keep the cost of insert(), delete(), lookup() to O(logN) where N is the
number of nodes in the tree - so the benefit really is that lookups can be done in
logarithmic time which matters a lot when N is large.

 We have an ordering of keys stored in the tree. Any time we need to traverse the
increasing (or decreasing) order of keys, we just need to do the in-order (and
reverse in-order) traversal on the tree.

 BST can also be used in the design of memory allocators to speed up the search of
free blocks (chunks of memory), and to implement best fit algorithms where we are
interested in finding the smallest free chunk with size greater than or equal to size
specified in allocation request.
Limitations of Binary tree:

 The main disadvantage is that we should always implement a balanced binary


search tree - AVL tree, Red-Black tree, Splay tree. Otherwise the cost of operations
may not be logarithmic and degenerate into a linear search on an array.
Pseudo code:
 Insert operation: search operation:
Code implantation in c:
 Insert operation:
 Search operation:
Complexity analysis of BsT

 Time complexity of all BST Operations = O(n)

 Worst case : o(n)

 Best case: o(log n)


Application of BsT
 used to efficiently store data in sorted form in order to access and search stored
elements quickly.

 They can be used to represent arithmetic expressions (Refer here for more info )

 BST used in Unix kernels for managing a set of virtual memory areas (VMAs).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy