3
N›[  ã               @   s    d Z ddlZdd„ Zdd„ ZdS )z6
Created on Wed Apr 11 14:17:32 2018

@author: ctchou
é    Nc             C   s|   d}t | ƒd }tj|| d ƒ}| | }d}xH||krv||krJ|d }n|d }tj|| d ƒ}| | }|d7 }q0W |S )a}  
    Purpose: To find a number in an array using binary search 
    
    Inputs:
       array       (numpy array) a vector of numbers arranged in 
                   descending order
       target      a number from the array
    
    Output:
       position    the index at which the number target is located 
                   in the array, i.e. array[position] = target  

    r   é   é   )ÚlenÚmathÚceil)ÚarrayÚtargetÚindex1Úindex2Ú	index_midÚname_midÚnum_queries© r   úz/Users/ctchou/Documents/Work/teaching/engg1811/2018s2/college-dictaat/week09/code/code_lecturer_only/find_name_routines.pyÚbinary_search   s    

r   c             C   s&   d}x|| | kr|d }qW |d S )ah  
    Purpose: To find a number in an array
    
    Inputs:
       array       (numpy array) a vector of numbers arranged in 
                   descending order
       target      a number from the array
    
    Output:
       position    the index at which the number target is located 
                   in the array, i.e. array[position] = target  

    r   r   r   )r   r   Úpositionr   r   r   Úsimple_scan5   s    r   )Ú__doc__r   r   r   r   r   r   r   Ú<module>   s   )