Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: stl and set
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 8 Topic 9548 of 9971
Post > Topic >>

Re: stl and set

by Greg Herlihy <greghe@[EMAIL PROTECTED] > Apr 26, 2008 at 09:43 AM

On Apr 26, 2:35 am, "Jeff Baker" <algort...@[EMAIL PROTECTED]
> wrote:
> In reading about <set> it is described as a binary tree without
duplicates.
> Why is it a binary tree rather then a linear tree. Is this really just
the
> same?

No, the performance of a linear list would degrade linearly as items
are added to the container, whereas the performance of a binary tree
would degrade logarithmically as more items are added. In other words,
there is a tremendous difference between a linear list and a binary
tree.

> Why not a straight line from top to bottom?

Consider the average number of comparisons needed to find a particular
item in a linear list versus a binary tree. For a container with, say,
64 items, a linear search would require on average 32 comparisons to
find the requested element - whereas a binary tree would average
around five comparisons - just one sixth as many. For a container with
1,024 elements, a linear list would need on average 512 comparisons to
find an item - whereas a binary tree would avere just nine (a fifty-
six fold difference). And by the time the container has grown to
1,048,576 items, searching for an item in the binary tree (19
comparisons on average) is about twenty-thousand times faster than
searching for the same item in the linear list (which would require
524,288 comparisons on average).

Greg




-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 8 Posts in Topic:
stl and set
"Jeff Baker" &l  2008-04-26 03:35:37 
Re: stl and set
Brendan <catphive@[EMA  2008-04-26 08:43:23 
Re: stl and set
alasham.said@[EMAIL PROTE  2008-04-26 09:09:22 
Re: stl and set
Greg Herlihy <greghe@[  2008-04-26 09:43:21 
Re: stl and set
"Jeff Baker" &l  2008-04-26 16:27:17 
Re: stl and set
"Jeff Baker" &l  2008-04-27 07:12:39 
Re: stl and set
Carl Barron <cbarron41  2008-04-27 07:12:45 
Re: stl and set
Pavel Minaev <int19h@[  2008-04-27 15:48:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Sep 4 23:57:37 CDT 2008.