Jump to content
  • Advertisement
Sign in to follow this  
Lazofury

Binary Search Tree's Sorting

This topic is 4599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i would like to ask if i want to sort a set of number.. let's say n. By constructing those numbers into a binary tree then do in-order walk to print them.. wut would be the best-case and worst-case running times?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Extrarius
This sounds like homework, which means you can ask for help but not for answers


i did it myself once.. but not sure if i am correct
i found it to be (nlgn) and (n^2) for best and worst.

but to my understanding..
constructing a binary tree = O(nlgn)
in-order-walk = O(n)

shouldnt it be O(n(1+lgn))

Share this post


Link to post
Share on other sites
When two terms are added, if you take the limit going to infinity, one of them will be much larger than the other. That is the whole idea of asymptotic notation, and when comparing "n" to "n*log(n)", the latter will be far larger with huge numbers and is thus the only one considered.

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
When two terms are added, if you take the limit going to infinity, one of them will be much larger than the other. That is the whole idea of asymptotic notation, and when comparing "n" to "n*log(n)", the latter will be far larger with huge numbers and is thus the only one considered.


o.. really...
so. just take o(nlgn) as the best case?

if so.. for the worst case:
since.. worst time for contructing a binary tree would be n^2
and so it would be n + n^2 => O(n^2)
rite?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!