Calculate depth of a full Binary tree from Preorder | C # program to find height of full binary tree using preorder ; function to return max of left subtree height or right subtree height ; calc height of left subtree ( In preorder left subtree is processed before right ) ; calc height of right subtree ; Wrapper over findDepthRec ( ) ; Driver program
using System ; class GFG { static int findDepthRec ( char [ ] tree , int n , int index ) { if ( index >= n tree [ index ] == ' l ' ) return 0 ; index ++ ; int left = findDepthRec ( tree , n , index ) ; index ++ ; int right = findDepthRec ( tree , n , index ) ; return Math . Max ( left , right ) + 1 ; } static int findDepth ( char [ ] tree , int n ) { int index = 0 ; return ( findDepthRec ( tree , n , index ) ) ; } static public void Main ( ) { char [ ] tree = " nlnnlll " . ToCharArray ( ) ; int n = tree . Length ; Console . WriteLine ( findDepth ( tree , n ) ) ; } }