•
•
•
•
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
![]() |
•
•
•
•
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.
•
•
Join Date: Sep 2005
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
>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.
>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.
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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Computer Science and Software Design Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp blog business software computer dell design developer development erp systems experiment firefox howto india intel internet it java linux media microsoft mmorpg msdn networking news office open open-source operating programming project management rss science security software software selection source sql sun super system technology evaluation toread vista warez web wiki windows xp
- Time complexity of algorithm (Computer Science and Software Design)
- To detect Space complexity.. (C)
- I'm having problem with the complexity of this algorithm! (Computer Science and Software Design)
Other Threads in the Computer Science and Software Design Forum
- Previous Thread: Lat/Long to binary
- Next Thread: SAS Help Please?



Linear Mode