aspose file tools
The moose likes Java in General and the fly likes TreeSet - TreeMap:  What is Balenced Tree Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "TreeSet - TreeMap:  What is Balenced Tree" Watch "TreeSet - TreeMap:  What is Balenced Tree" New topic
Author

TreeSet - TreeMap: What is Balenced Tree

Sandeep Mukherji
Ranch Hand

Joined: Mar 23, 2008
Posts: 46
I am going through the topic TreeSet and Tree Map where I found the following line:

Searching in a HashSet or HashMap can be faster than in a TreeSet or TerrMap, as hashing algorithm usually offer better performance than the search algorithms for balenced tree

My query is "What is a balenced tree?"
Eugene Wee
Greenhorn

Joined: Dec 17, 2007
Posts: 5
The NIST Dictionary of Algorithms and Data Structures defines a balanced tree as: A tree where no leaf is much farther away from the root than any other leaf. Different balancing schemes allow different definitions of "much farther" and different amounts of work to keep them balanced.

In other words, a balanced tree is guaranteed not to degenerate into a linked list. As such, a search will take time proportional to the height of the tree (effectively O(log n)) instead of proportional to the number of elements (O(n)).
[ May 09, 2008: Message edited by: Eugene Wee ]
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
Check this out and try to figure out the complexity of lookup operations.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: TreeSet - TreeMap: What is Balenced Tree
 
Similar Threads
Tree Object in Java
Set interface in K&B SCJP book
Comparator ClassCastException
ArrayList without duplicates
Tree