492 views
1 votes
1 votes
We want to find an algorithm for finding the deepest node of a binary tree.

My idea is to use BFS (Breadth-first search) and while visiting each node we will initialize it's node.dvalue(which will indicate how much far is node away from the source(root)).

When my algorithm will terminate, I will find that node for whose dvalue is maximum, and that will give me node with the highest depth.

Is my above-suggested algorithm correct?

1 Answer

0 votes
0 votes
As per my thinking we should go for DFS as we don't want to know about every intermediate node. We want to find the farthest node from root which will yeild the highest hight.

BFS will also be correct.

Related questions

1 votes
1 votes
0 answers
1
Rohit Gupta 8 asked Dec 25, 2017
1,146 views
If the average depth of a node in an $n$-node binary search tree is $O(\log{n})$, then the height of the tree is$O(n\log{n})$$O(n)$$O(\log{n})$$O(\sqrt(n\log{n}))$
2 votes
2 votes
1 answer
3
radha gogia asked Dec 10, 2015
1,647 views
If I have n elements in the heap then why does the index of leaf nodes ranges from index ⌊n/2⌋+1 to index n ?