Finding the index of a given value in a pre-sorted array
        Posted  
        
            by bobo
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by bobo
        
        
        
        Published on 2010-03-16T13:07:47Z
        Indexed on 
            2010/03/16
            13:16 UTC
        
        
        Read the original article
        Hit count: 237
        
Today, I went for an interview and the interviewer asked me how I would find the index of a given value (number) in a pre-sorted array like this:
$preSortedArr=array(23,32,36,41,45,54);
He also said that using recursion is not allowed.
I think the function should look like this:
function findIndexByValue($preSortedArray,$value){            
//some codes here       
}
What solution do you think he was expecting from me?
EDIT: sorry, I forgot to add that, he originally asked me to write psuedo codes but I said I don't know. I tried to write in PHP, but I think he's expecting a language-independent solution.
© Stack Overflow or respective owner