User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Computer Science and Software Design section within the Software Development category of DaniWeb, a massive community of 402,446 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,974 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Computer Science and Software Design advertiser: Programming Forums
Views: 2049 | Replies: 4
Reply
Join Date: Sep 2005
Posts: 7
Reputation: hider is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
hider hider is offline Offline
Newbie Poster

bst complexity

  #1  
Oct 6th, 2005
hi
please i am confused with bst complexity

what is the complexity for
balanced
search
insert
delete
-------------
unbalanced
seach
insert
delete


please help and correct me if i am doing things wrong

thanx
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Troy
Posts: 1,277
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 36
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: bst complexity

  #2  
Oct 7th, 2005
Originally Posted by hider
hi
please i am confused with bst complexity

what is the complexity for

Wait a second. You can't ask for a complexity without giving us algorithms. You've only explained the function of the algorithms, not the implementation. You haven't asked if you want a worst-case, average-case, or best-case value.

Generally speaking, the worst-case runtime for sanely-written search, insertion, and deletion algorithms is O(h), where h is the height of the tree.
Reply With Quote  
Join Date: Sep 2005
Posts: 7
Reputation: hider is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
hider hider is offline Offline
Newbie Poster

Re: bst complexity

  #3  
Oct 7th, 2005
hi

well if you noticed from the start i said i am confused. there are many cases and i need some one to explain all the cases yes i need to know best worst and average for all

now for balanced
B - O(1)
A - LOG(N)
W - 0(N)

UNbalanced
B - ?
A - ?
W - 0(N)

for search balanced BAW (MEANS BEST AVERAGE WORST)?
for insert balanced BAW= ?
for DELETE balanced BAW= ?

......

I APPRECIATE YOUR HELP IF YOU HAVE A LIST OR A SITE EXPLAIN ALL THE CASES.
THNAX

I HAVE AMIDTERM IN 4 DAYS.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,067
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: bst complexity

  #4  
Oct 7th, 2005
>now for balanced
>B - O(1)
>A - LOG(N)
>W - 0(N)
You're not thinking in terms of scalability. The best case performance for a balanced binary search tree during search operations is O(log N), so is the average and worst case, which is why balanced trees are so desirable. Insertion and deletion strategies can vary from the naive and inefficient to the complicated and fast, so the cases can vary from O(N) or worse to O(log N). Assuming a decent balancing strategy like AVL, you can expect search, insertion, and deletion to be O(log N). But that depends heavily on the quality of the implementation.

Unbalanced binary search trees are harder because the performance relies on the order in which data arrives or is deleted. But in general terms, the worst case of an unbalanced tree is O(N) and the best case is O(log N). The average case varies between O(N) and O(log N) for degenerate sequences and random sequences, respectively.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Jun 2005
Location: Troy
Posts: 1,277
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 36
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: bst complexity

  #5  
Oct 7th, 2005
Narue must mean a different thing by best case then (than what I usually mean).

Given one way to interpret the term, the best case for search is O(1) in both the balanced and unbalanced cases. This happens when the root node contains what we're looking for. The best case for insertion and deletion in a balanced tree is still O(log n).

The best case for insertion, and deletion in an unbalanced tree is O(1).

If you average the runtime of these operations over all the keys in the tree, and measure this runtime, then Narue's statements are correct, and that is probably the measurement she was implying.

Anyway, this message is for the other poster, not Narue, since Narue knows what she's talking about. (Hopefully, now hider also knows what Narue's talking about.) Anyway, hider, you'll have to decipher what they mean on your midterm as to what they are measuring when discussing runtimes.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Computer Science and Software Design Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Computer Science and Software Design Forum

All times are GMT -4. The time now is 2:57 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC