473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Binary Search Tree

I recently had to write some code which required me to use a binary
search tree (BST) due to running time concerns. I found that there is no
BST class in the Standard C++ library. I have been told that other
container classes such as set use a balanced BST internally. Is it
possible to access this functionality or is the only solution to write a
BST class from scratch?
-Ravi.
Jul 22 '05 #1
5 7653
Ravi wrote:
I recently had to write some code which required me to use a binary
search tree (BST) due to running time concerns. I found that there is no
BST class in the Standard C++ library. I have been told that other
container classes such as set use a balanced BST internally. Is it
possible to access this functionality or is the only solution to write a
BST class from scratch?
-Ravi.


The standard library does not provide a BST. If you need one you'll have
to get it elsewhere, possibly by writing it yourself.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #2
On Fri, 16 Apr 2004 14:59:24 -0400 in comp.lang.c++, Ravi
<Ra**@xxx.yyy.zzz> wrote,
container classes such as set use a balanced BST internally. Is it
possible to access this functionality or is the only solution to write a
BST class from scratch?


The ordinary solution is to use std::set or std::map. They were meant
to be used. What functionality do you want that they do not provide?

Jul 22 '05 #3

"Ravi" <Ra**@xxx.yyy.zzz> wrote in message
news:c5*********@prometheus.acsu.buffalo.edu...
I recently had to write some code which required me to use a binary
search tree (BST) due to running time concerns. I found that there is no
BST class in the Standard C++ library. I have been told that other
container classes such as set use a balanced BST internally. Is it
possible to access this functionality or is the only solution to write a
BST class from scratch?
-Ravi.


There is no guarantee that the Standard Library containers are implemented
as a binary search tree, but you *are* guaranteed the performance of a
binary search tree (i.e. O(lg N) time complexity). So, if you must have a
literal binary search tree, you'll have to roll your own. However, if
performance is your only concern, you should take a look at std::set<> or
std::map<> (or their multi counterparts).
Jul 22 '05 #4

"Dave" <be***********@yahoo.com> wrote in message
news:10*************@news.supernews.com...

"Ravi" <Ra**@xxx.yyy.zzz> wrote in message
news:c5*********@prometheus.acsu.buffalo.edu...
I recently had to write some code which required me to use a binary
search tree (BST) due to running time concerns. I found that there is no
BST class in the Standard C++ library. I have been told that other
container classes such as set use a balanced BST internally. Is it
possible to access this functionality or is the only solution to write a
BST class from scratch?
-Ravi.


There is no guarantee that the Standard Library containers are implemented
as a binary search tree, but you *are* guaranteed the performance of a
binary search tree (i.e. O(lg N) time complexity). So, if you must have a
literal binary search tree, you'll have to roll your own. However, if
performance is your only concern, you should take a look at std::set<> or
std::map<> (or their multi counterparts).


As an aside, given the performance requirements that must be met, there
aren't too many data structures besides balanced binary search trees that
could be used to implement the associative containers. Someone had told me
once that "skip lists" might be an alternative, but I am not familiar with
them, so I can't corroborate that statement myself...
Jul 22 '05 #5
Dave wrote:
As an aside, given the performance requirements that must be met, there
aren't too many data structures besides balanced binary search trees that
could be used to implement the associative containers. Someone had told me
once that "skip lists" might be an alternative, but I am not familiar with
them, so I can't corroborate that statement myself...


Skip lists are supposed to have favorable performance compared to most
types of balanced search tree (in one experiment I read about, only
non-recursive AVL did better, if I recall correctly).

However, skip lists have a random component, which means there's a
chance (remote though it is) that the performance will degrade severely.
This would probably be enough to make a map or set implementation using
skip lists not strictly compliant (though nobody would ever know the
difference, I think).

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: jova | last post by:
Is there a difference between a Binary Tree and a Binary Search Tree? If so can someone please explain. Thank You.
0
by: j | last post by:
Hi, Anyone out there with binary search tree experience. Working on a project due tomorrow and really stuck. We need a function that splits a binary tree into a bigger one and smaller one(for a...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
15
by: Foodbank | last post by:
Hi all, I'm trying to do a binary search and collect some stats from a text file in order to compare the processing times of this program (binary searching) versus an old program using linked...
1
by: mathon | last post by:
hi, now i facing a problem which i do not know how to solve it...:( My binary search tree structures stores a double number in every node, whereby a higher number is appended as right child...
1
by: hn.ft.pris | last post by:
I have the following code: Tree.h defines a simple binary search tree node structure ########## FILE Tree.h ################ #ifndef TREE_H #define TREE_H //using namespace std; template...
4
by: whitehatmiracle | last post by:
Hello I have written a program for a binary tree. On compiling one has to first chose option 1 and then delete or search. Im having some trouble with the balancing function. It seems to be going...
5
gekko3558
by: gekko3558 | last post by:
I am writing a simple binary search tree (nodes are int nodes) with a BSTNode class and a BST class. I have followed the instructions from my C++ book, and now I am trying to get a remove method...
11
by: Defected | last post by:
Hi, How i can create a Binary Search Tree with a class ? thanks
7
by: Vinodh | last post by:
Started reading about Binary Trees and got the following questions in mind. Please help. Definition of a Binary Tree from "Data Structures using C and C++ by Tanenbaum" goes like this, "A...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.