Minimum in an array which is first decreasing then increasing | Function to find the smallest number 's index ; Do a binary search ; Find the mid element ; Check for break point ; Return the index ; Driver Code ; Print the smallest number
< ? php function minimal ( $ a , $ n ) { $ lo = 0 ; $ hi = $ n - 1 ; while ( $ lo < $ hi ) { $ mid = ( $ lo + $ hi ) >> 1 ; if ( $ a [ $ mid ] < $ a [ $ mid + 1 ] ) { $ hi = $ mid ; } else { $ lo = $ mid + 1 ; } } return $ lo ; } $ a = array ( 8 , 5 , 4 , 3 , 4 , 10 ) ; $ n = sizeof ( $ a ) ; $ ind = minimal ( $ a , $ n ) ; echo $ a [ $ ind ] ; ? >