Binary tree and Binary search tree

MayeeshaSamiha 2,304 views 16 slides Dec 13, 2015
Slide 1
Slide 1 of 16
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16

About This Presentation

Binary tree came from data structure.This slide is very important for Cse engineers


Slide Content

Binary Tree

What Is Binary Tree? A binary tree is made of nodes, where each node contains a "left" pointer, a "right" pointer, and a data element. The "root" pointer points to the topmost node in the tree. The left and right pointers recursively point to smaller " sub-trees " on either side. A null pointer represents a binary tree with no elements -- the empty tree. The formal recursive definition is: a  binary tree  is either empty (represented by a null pointer), or is made of a single node, where the left and right pointers (recursive definition ahead) each point to a  binary tree . 

Parts Of Binary Tree A B C F D G E H I Root node & parent node Children Node & successor of Node A Sub tree A is the ancestor of B & C Edge These are Terminal node

Complete Binary Tree A complete binary tree is a  binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible

Extended Binary Tree A   binary tree  in which special nodes are added wherever a null subtree was present in the original tree so that each node in the original tree (except the root node)

Traversing Binary Tree Often we wish to process a binary tree by "visiting" each of its nodes, each time performing a specific action such as printing the contents of the node. Any process for visiting all of the nodes in some order is called a  Traversal.

Preorder traversal  we might wish to make sure that we visit any given node  before  we visit its children. This is called a  Preorder traversal. Preorder traversal Result: A B D C E G F H I .

In order Traversal An  In order Traversal  first visits the left child (including its entire subtree ), then visits the node, and finally visits the right child (including its entire subtree ). The  binary search trees  makes use of this traversal to print all nodes in ascending order of value . Inorder result:   B D A G E C H F I .

Post-Order Traversal we might wish to visit each node only  after  we visit its children (and their subtrees ). For example, this would be necessary if we wish to return all nodes in the tree to free store. We would like to delete the children of a node before deleting the node itself. But to do that requires that the children's children be deleted first, and so on. This is called a postorder Traversal. Post order resullt : D B G E H I F C A .

Depth Of Node The depth of a node is the number of edges from the root to the node. The height of a node is the number of edges from the node to the deepest leaf. The height of a tree is a height of the root. A full binary tree.is a binary tree in which each node  has exactly zero or two children .

Degree Of Tree The number of subtrees of a node is called the degree of the node. In a binary tree, all nodes have degree 0, 1, or 2. A node of degree zero is called a terminal node or leaf node. A non-leaf node is often called a branch node . For this tree the degree of “A” is 2.

Height Of Tree The  height  of a node is the number of edges on the longest path from the node to a leaf . Here the Height of the tree is 3(H). A C B G D E F H

Binary Search Tree A binary search tree (BST) is a binary tree where each node has a Comparable key (and an associated value) and satisfies the restriction that the key in any node is larger than the keys in all nodes in that node's left subtree and smaller than the keys in all nodes in that node's right subtree .

Heap A binary heap is a complete binary tree which satisfies the heap ordering property. The ordering can be one of two. 1.Max heap 2.Min heap

Max Heap A max-heap is a complete binary tree in which the value in each internal node is greater than or equal to the values in the children of that node.

Min Heap the value of each node is greater than or equal to the value of its parent, with the  minimum -value element at the root.