In Binary Search , which will be the scenario for Average Case performance ?


A. The 'Mid key’ is present, but it’s not the middle element O(logn).
B. The ‘input key’ is present, but it’s not the middle element O(logn).
C. The ‘Last key’ is present, but it’s not the middle element O(logn).
D. The ‘First key’ is present, but it’s not the middle element O(logn).

1

Answers

  • Brainly User
2016-04-16T16:06:05+05:30
Def bsearch(l,item):   
 lb=0   
 ub=len(l)-1 
  while lb<=ub: 
       mid =(lb +ub)/2 
      if item==l[mid]:   
        return mid     
  elif item > l[mid]:     
      lb= mid +1   
     else:       
    ub=mid-1
    else:        return false
l=[]n= input("enter how many element")
for i in range(n):   
 val= input("enter  element") 
  l.append(val)item=input("enetr the element to be searched")
index = bsearch(l,item)if index: 
   print " value found at pos",index +1
else:    print
"value not found"        
0