Skip to main content
gamedev.net
🔒 Locked

Binary Search Tree's Sorting

Started by Lazofury Apr 19, 2006 at 11:10 AM 4 replies 550+ views
Original Post
Lazofury
Lazofury
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?
Extrarius
Extrarius
This sounds like homework, which means you can ask for help but not for answers
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Lazofury
Lazofury
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))
Extrarius
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.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Lazofury
Lazofury
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.