13,554,429 members

Email

Password

Sign in with

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!

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!

Comments

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).

Comments

Since you are iterating over the entire list then no.

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!

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)

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

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!