Value of k | PHP program to fin k - th element after append and insert middle operations ; Middle element of the sequence ; length of the resulting sequence . ; Updating the middle element of next sequence ; Moving to the left side of the middle element . ; Moving to the right side of the middle element . ; Driver code
< ? php function findElement ( $ n , $ k ) { $ ans = $ n ; $ left = 1 ; $ right = pow ( 2 , $ n ) - 1 ; while ( 1 ) { $ mid = ( $ left + $ right ) / 2 ; if ( $ k == $ mid ) { echo $ ans , " STRNEWLINE " ; break ; } $ ans -- ; if ( $ k < $ id ) $ right = $ mid - 1 ; else $ left = $ mid + 1 ; } } $ n = 4 ; $ k = 8 ; findElement ( $ n , $ k ) ; ? >