[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math

Search:


View post   

>> No.2984074 [View]
File: 22 KB, 400x300, binary-tree-visualization[1].jpg [View same] [iqdb] [saucenao] [google]
2984074

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!

>> No.1791696 [View]
File: 22 KB, 400x300, binary-tree-visualization[1].jpg [View same] [iqdb] [saucenao] [google]
1791696

>Binary-tree visualization of the Yahoo search engine bot crawling the experimental website.

Navigation
View posts[+24][+48][+96]