Difference between Linear Search and Binary Search
Linear Search: It is a sequential search or it searches line by line. So it is slow and it takes too much time to find out the data, it is also know as Sequential Search.
Binary Search: In Binary search it divide the table into two parts, a lower value part and a upper value part, after dividing It will check with the middle value if its lesser than the searched element than it goes to right half else it goes to left half. Therefore it is necessary that the search filed of the table should be in Ascending order. If you sort the list in descending order then binary search fails.
You can't use BINARY SEARCH with SORTED or HASHED tables - you'll get a syntax error. BINARY SEARCH is used for internal table ,you must Sort your Internal Table in ASCENDING order for BINARY SEARCH.
E.g suppose we have 5 sales order like this and you have to find 100033:
so linear search will start search from 100010 to 100011 to 100022 and then 100033.
we proceed 1 by 1 : it takes 4 iterations
In binary search it breaks the list into two parts and take middle value(100022) compare with 100033 now we are left with
we compare (100033) and (100044) with 100033
Thus process completed in 2 iteraions. so it is very fast.
Binary search must be preffered over linear sarch.