Click here to Skip to main content
13,554,429 members
Rate this:
 
Please Sign up or sign in to vote.
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?

thanks!
Posted 18-May-13 5:13am
Comments
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
   
hey!
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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).
  Permalink  
Comments
Mehdi Gholam 18-May-13 12:55pm
   
Since you are iterating over the entire list then no.
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?
thanks!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02-2016 | 2.8.180515.1 | Last Updated 18 May 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100