An effective approach to solve this issue is to implement a modified version of Binary Search. For instance, if we have a sorted array like [1, 3, 5, 5, 5, 6, 8, 9] and we aim to locate the first instance of 5. Below is a Python code snippet to achieve that: def findFirst ( arr , low , high , key ) : if high >= low : mid = low + ( high - low ) // 2 if ( mid == 0 or key > arr [ mid - 1 ] ) and arr [ mid ] == key : return mid elif key > arr [ mid ] : return findFirst ( arr , ( mid + 1 ) , high , key ) else : return findFirst ( arr , low , ( mid - 1 ) , key ) return - 1 # test array arr = [ 1 , 3 , 5 , 5 , 5 , 6 , 8 , 9 ] key = 5 print ( "First occurrence of " , key , " is found at index: " , findFirst ( arr , 0 , len ( arr ) - 1 , key ) ) The function findFirst in the code utilizes binary search to locate the key within the array. It begins by examining the middle element. If the target key exceeds the middle element, it deduces that the key must be in the right half of the array, prompting a search there. Conversely, if the key is smaller than the middle element, it checks the left half of the array. This method effectively halves the search space with each iteration, resulting in a time complexity of O(log n).