Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
35.1k views
in Computer by (25.0k points)

Write an algorithm to search an element in an array using binary search.

Algorithm: Binary_search(A,ele,N)

1 Answer

+1 vote
by (26.0k points)
selected by
 
Best answer

Step 1: low = 0
Step 2: high = n-1
Step 3: while (low <= high) repeat step 4 through step 6
Step 4: mid = (low + high) / 2
Step 5: Is ( ele = = a[mid]) then
Loc = mid
goto step 7
Otherwise
Step 6: is ( ele < a[mid])? then
high = mid – 1
otherwise
low = mid + 1
[end while – step 3]
Step 7: Is ( Loc >= 0 ) ? then
Print “search element found at location “, loc
Otherwise
Print “search element not found”.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...