BinarySearch_algoritjm

Add to Favourites
Post to:

Description
Algorithm for binary search

Comments
Presentation Transcript Presentation Transcript

Algorithm : Algorithm Let A[n] be the given array sorted in ascending order and “data” be the item to be searched. Let lb and ub represent the lower bound and the upper bound respectively Step 1. start Step 2. read data to be searched (data) Step 3. set lb = 0 , pos = -1 and mid = 0. Step 4. set ub = n-1 Step 5. while( lb <= ub ) do step7 through step10 { Step 6 mid = (lb + ub ) / 2 Step 7. if (data = A[mid] ) then go to step 8 else go to step 9 Step 8. { set pos = mid and go to Step10 } Step 9. if(data= 0 ) { Step 11 Display " 'data' is found at position 'pos' " } else Step 12 { "Display 'data' is not in the list " } Stap13. end.

Want to learn?

Sign up and browse through relevant courses.

Name:
Your Email:
Password:
Country:
Contact no:


Area code Number
Subjects you are interested in:
Word verification: (Enter the text as in image)


Sign Up Already a member? Sign In
I agree to WizIQ's User Agreement & Privacy Policy
5 Members Recommend
46 Followers

Your Facebook Friends on WizIQ

Give live classes, create & sell online courses

Try it free Plans & Pricing

Connect