Find n | function to find nth stern ' diatomic series ; SET the Base case ; Traversing the array from 2 nd Element to nth Element ; Case 1 : for even n ; Case 2 : for odd n ; Driver Code
< ? php function findSDSFunc ( $ n ) { $ DP [ 0 ] = 0 ; $ DP [ 1 ] = 1 ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) { if ( $ i % 2 == 0 ) $ DP [ $ i ] = $ DP [ $ i / 2 ] ; else $ DP [ $ i ] = $ DP [ ( $ i - 1 ) / 2 ] + $ DP [ ( $ i + 1 ) / 2 ] ; } return $ DP [ $ n ] ; } $ n = 15 ; echo ( findSDSFunc ( $ n ) ) ; ? >