Sie sind auf Seite 1von 9

# c  

##     



1)
-A Ǯ
ǯ consists of a finite set of elements, called Ǯǯ and a finite set of
directed lines, called Ǯ ǯ that connect the nodes.

2) The number of branches associated with a node is the  of the node.

3) The branches when directed towards the node, it is an  of the branch.

Node (root)
á

sub-tree



## ǯ has c=1 and Out-Degree=1

4) The branches when directed away from the nodes, it is an  of the branch.

## Branches directed away

á from node-c


 

## 5) c= (c +c)of  

6) If the tree is a non-empty, then the first node of the tree is called Ǯǯ.

## 7) The in-degree of root by definition is zero.

8) All nodes in a tree must have in-degree exactly one, except the root.
) All node can have zero or one or more branches leaving them, that they may have out-
degree of zero, one or more.

 á
  
 

 

   á   

Cousins




  ! 
 "#

10)  "- Nodes that are not root and not leaf are called as internal nodes.
11)\$ - A node is a parent if it has successor nodes; means  greater than
%.

## 12) &"- A node is a child node if  is .

13) 
- A sub-tree is any connected structure below the root.

14)  - A node with no successor (nodes after it)-there are usually many leaves in a tree.

15)  - A node which has both a parent and at-least one child.


 '


A  '
 is a finite set of elements that is either empty or is partitioned into three
disjoint subsets. Or in other words we can say, it is a directed tree in which out-degree of
each node is equal or less than 2, i.e. each node in the tree can have 0, or 2 children.

*c
-A directed tree is '" , which has only
one node with in-degree 0, and all other nodes have in-degree 1.
Properties:-

(1) The  contains only one element and it is called root of the tree, if root
contains null it is called an empty binary tree.

(2) The  is a binary tree called ". The left sub-tree can be empty.

## (3) The  is a binary tree called  can be empty.

_ 

L R

_________________________________________________________
Root Root Root Root Root

L L R R L R

## Binary Tree Operations:-

In a binary tree no node can have more than two sub-trees. In other words, a node can have
zero, one or two sub-trees.

"' '
:- If the out-degree of every node in a tree is either 0 or 2, then the
tree is said to be strictly binary tree i.e., each node can have maximum two child node or
empty left and empty right child node. Or we can say a "' '
 its when the
tree is fully expanded i.e., with 2 degree expansion.

 

 

 

:-

## A # " ' is a binary tree in which every level, ? ?

 ? , is completely
filled, and all nodes are as far left as possible.

ǮOrǯ

A strictly binary tree in which the number of nodes at any level i is Ú , then the tree is said to be a
complete binary tree.

## Number of nodes at each level from 0 to d:-

Level 0*Ú  Ú  

Level 1*Ú  Ú  Ú

Level 2*Ú  Ú  

Level 3*Ú   Ú 

........................

## Summation of the series;

S=a (  -1)(r-1)

## So, Total no. of nodes,   Ú   

Nodes at level d are all leaf nodes, so no. of non-leaf nodes are given by ;

=Ú     Ú

 Ú  
"#&# ""' '
:-

A tree with depth d is almost complete binary tree, if the tree is complete up to the level d-1
i.e. the total no. of nodes at the level d-1 should be Ú  .At level d the nodes should be
present only from left to right.

## All below are complete binary tree in respective ways:-

(a) (b)

(c) 0

1 2

3 4 5 6

7 8 

The nodes in an almost complete binary tree can be numbered level by level from left to
right as shown in figure (c) above.

##     ':-

The trees can be represented by using sequential allocation techniques (using arrays) or by
allocating the memory for a node dynamically (using linked allocation techniques).

## 1.Ê info-which contains the actual information.

Function getnode( )-Memory can be allocated and Function freenode( )-Memory can be de-
allocated.
  ( "  )  '  ).
0
á
1 2 0 1 2 3 4 5 6
 
3 4 5 6

   
A B C D E F G

(A) 0 1 2 3 4 5 6

0
á
A B C D E F
1  2 

4 5 6
  

(B)

## 2. c" Ȃ To delete a node from the tree.

3.
  " Ȃ Visiting the nodes of the tree one by one.

## 5.  Ȃ Search for specified items.

  :
á

 

  

 temp


## Figure: To insert an item

Nodes can be inserted into binary trees in between two other nodes or added after an , "
. In binary trees, a node that is inserted is specified as to which child it is.

-, "
Say that the external node being added on to is node A. To add a new node after node A, A
assigns the new node as one of its children and the new node assigns node A as its parent.

 "

Insertion on  " is slightly more complex than on external nodes. Say that the
internal node is node A and that node B is the child of A. (If the insertion is to insert a right
child, then B is the right child of A, and similarly with a left child insertion.) A assigns its child to
the new node and the new node assigns its parent to A. Then the new node assigns its child to B
and B assigns its parent as the new node.

á á
á 

 
   


## The process of inserting a node into a binary tree


c"  :

Deletion is the process whereby a node is removed from the tree. Only certain nodes in a
binary tree can be removed unambiguously.

 


á 
á   




## The process of deleting a node into a binary tree

  "  :

Traversing is the most common operation that can be performed on trees. In the traversal
technique each node in the tree is processed or visited exactly once systematically one after
other.


  " refers to the process of visiting (examining and/or updating) each node in
a tree data structure, exactly once, in a systematic way. Such traversals are classified by the
order in which the nodes are visited. The following algorithms are described for a binary
tree, but they may be generalized to other trees as well.
The different traversal techniques are:

1. In-Order

2. Pre-Order

3. Post-Order