Click here to Skip to main content
15,919,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey everybody!

i'm working on a code which its purpose is to print all the nodes in an ordinary binary tree, ,
which their value is an odd number.

if i will travel the tree's nodes by an Inorder , the running time will be 0(n) ,(where n is the number of the total nodes in the tree..)

my question is : if i was using a binary search tree for this purpose, would that make any different on the running time?

YvesDaoust 18-May-13 11:43am    
Your question is unclear as I (we) don't know what you call an "ordinary binary tree" vs. a "binary search tree".
Richard MacCutchan 18-May-13 11:46am    
You could always try both methods and time them.
ronnie1stpla 18-May-13 12:11pm    
thanks for the quick replay!
by writing "ordinary binary tree" i meant that i'm talking about the 'standard' binary tree that we all know (which have a root, and each node can have only a right/left node sons/two sons,or without any node sons..) , where in a binary search tree, the value of the left node of the root is smaller than the value of the root itself, and the value of the right node is bigger than the value of the root ...)
Richard, i tried to time them, and i got almost the same time, to make my question more clear, i wanted to know if there is a specific (different) algorithm which i can use on the binary search tree, which will give me a better running time than when i run the print algorithm on a 'standard' binary tree...
thanks again!

1 solution

If you are iterating over all the tree then just create a list of the values and go over that and get the odd values O(n).
Share this answer
ronnie1stpla 18-May-13 12:45pm    
Mehdi, this is my solution as well (where o(n) is my running time,
my question is : "if i was using a binary search tree for this purpose,can i write a different algorithm which could improve my running time?
Mehdi Gholam 18-May-13 12:55pm    
Since you are iterating over the entire list then no.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900