[7 / 1 / ?]
Quoted By:
Hi /sci/,
I want to give an algorithm wich gives me the depth of a node in a BinarySearch Tree (depth of the node is the number of edges on the path from the root to the node)
So first of all the root has a depth 0. So here is my question, Should I just each time go, from the root till the node, return the depth, check if it has a left child, return the depth, check the right child, return the depth and so one.
And will this be in O(n) running time?
Thanks in advance!
I want to give an algorithm wich gives me the depth of a node in a BinarySearch Tree (depth of the node is the number of edges on the path from the root to the node)
So first of all the root has a depth 0. So here is my question, Should I just each time go, from the root till the node, return the depth, check if it has a left child, return the depth, check the right child, return the depth and so one.
And will this be in O(n) running time?
Thanks in advance!