Hello Guys 1
In this Video We are going to see
Binary search in Python in Tamil
*****************************************
ALGORITHM:
1. Start the program.
2. Read the given elements from the user .
3. Find the middle element in the sort list in the search.
4. And the compare the search element with middle element in the sorted list.
5. If the both conditions are matching and then it display the given element found is display
and terminated it.
6. If both the element are not matching in the search and then it checks whether the search
element I smaller as longer than the with element .
7. If the search element is smaller than the given middle elements then repeat the 3,4,5,6, for
the left subsets of the middle elements.
8. If the search elements is smaller than the given middle elements the repeat the 3,4,5,6 for
the right subsets of the middle elements.
9. Repeat the same process until we find the search elements in the list or until subsets
contains the only one elements.
10. If that elements also does not makes with the search elements and then display the
“element are not found in the list”.
11. Terminate the program.
*************************************************
Source Code:
PROGRAM:
import random
size=10
a=[]
n= int (input("enter the upper limit: "))
for i in range (n):
a.append(int(input()))
x=int(input("enter element to search in the list: "))
a=sorted(a)
print(x,a)
def binary_search(number,array,lo,hi):
if hi(less than)lo:
return-1
mid=(lo+hi)//2
if number==array[mid]:
return mid
elif number(less than)array[mid]:
return binary_search(number,array,lo,mid-1)
else:
return binary_search(number,array,mid+1,hi)
def my_search(x,a):
return binary_search(x,a,0,len(a)-1)
pos=my_search(x,a)
if pos(less than)0:
print("not found")
else:
print("found at positon ",pos+1)
***********************************************
Keywords:
How to binary search in python , binary serach
in python tamil, Pythomn binary search , Anna University ,
Quick Thorugh Python Binary serach , What is Binary serach in tamil,
quick through tamil
****************************************************
Please Watch the video completly guys AND Subscribe to
our channel:)