Amoraboti - Brainstorming
Rashed - Uz - Zaman (Rasel)
  Home About Me Brainstorming Facebook Fan Page Contact    
  Author
I'm Amoraboti
From

  Archives
April 2010
January 2012
February 2012
March 2012

  Current

  Previous Posts
d
f
g
2
B
B
Data Structures and Algorithms: Trees 2012-01-03 T...
Genetic Algorithms
Link

  My Link
Islam And We
My Diary (Bangla)
My Diary (English)
My Lyrics (Bangla)
My Lyrics (English)
My Poem (Bangla)
My Poem (English)
My Story (Bangla)
My Story (English)
General Knowledge
Fun And Jokes
Lyrics (Bangla)
Lyrics (English)
Lyrics (Hindi)
Quotations
 
 
  d  
  Friday, March 2, 2012  
 
d
 
  posted by Amoraboti At 3/02/2012 12:34:00 PM, ,  
     
  f  
  Thursday, March 1, 2012  
 
f
 
  posted by Amoraboti At 3/01/2012 09:08:00 AM, ,  
     
  g  
  Wednesday, February 29, 2012  
 
g
 
  posted by Amoraboti At 2/29/2012 09:27:00 PM, ,  
     
  2  
  Monday, February 27, 2012  
 
2
 
  posted by Amoraboti At 2/27/2012 01:33:00 PM, ,  
     
  B  
  Thursday, January 5, 2012  
 
b
 
  posted by Amoraboti At 1/05/2012 10:13:00 AM, ,  
     
  B  
  Wednesday, January 4, 2012  
 
b
 
  posted by Amoraboti At 1/04/2012 11:41:00 PM, ,  
     
  Data Structures and Algorithms: Trees 2012-01-03 Tuesday  
  Tuesday, January 3, 2012  
 
Binary Trees
The simplest form of tree is a binary tree. A binary tree consists of

a node (called the root node) and
left and right sub-trees.
Both the sub-trees are themselves binary trees.

You now have a recursively defined data structure. (It is also possible to define a list recursively: can you see how?)


A binary tree

The nodes at the lowest levels of the tree (the ones with no sub-trees) are called leaves.

In an ordered binary tree,

the keys of all the nodes in the left sub-tree are less than that of the root,
the keys of all the nodes in the right sub-tree are greater than that of the root,
the left and right sub-trees are themselves ordered binary trees.

Data Structure
The data structure for the tree implementation simply adds left and right pointers in place of the next pointer of the linked list implementation. [Load the tree struct.]

The AddToCollection method is, naturally, recursive. [ Load the AddToCollection method.]

Similarly, the FindInCollection method is recursive. [ Load the FindInCollection method.]

Analysis
Complete Trees



Before we look at more general cases, let's make the optimistic assumption that we've managed to fill our tree neatly, ie that each leaf is the same 'distance' from the root.

A complete tree
This forms a complete tree, whose height is defined as the number of links from the root to the deepest leaf.

First, we need to work out how many nodes, n, we have in such a tree of height, h.

Now,

n = 1 + 21 + 22 + .... + 2h

From which we have,

n = 2h+1 - 1

and
h = floor( log2n )

Examination of the Find method shows that in the worst case, h+1 or ceiling( log2n ) comparisons are needed to find an item. This is the same as for binary search.
However, Add also requires ceiling( log2n ) comparisons to determine where to add an item. Actually adding the item takes a constant number of operations, so we say that a binary tree requires O(logn) operations for both adding and finding an item - a considerable improvement over binary search for a dynamic structure which often requires addition of new items.
Deletion is also an O(logn) operation.

General binary trees

However, in general addition of items to an ordered tree will not produce a complete tree. The worst case occurs if we add an ordered list of items to a tree.
What will happen?
This problem is readily overcome: we use a structure known as a. However, before looking at heaps, we should formalise our ideas about the complexity of algorithms by defining carefully what O(f(n)) means.
 
  posted by Amoraboti At 1/03/2012 10:26:00 AM, ,  
     
 
  Problem In Font
Download then zip file unzip and install in your system. Or normal font file just install in your system font folder. Rz Rasel
Bangla Font
Bangla Font

  Find Me In Facebook
 
 

   aaaa
 

   aaaa
 
 
Copyright © 2010 - Amoraboti - Brainstorming. ® All right reaserved. Design and developed by:- Rz Rasl