**Linear Search vs 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 an 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 field 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:**

100010

100011

100022

100033

100044

so** linear search **will start search from 100010 to 100011 to 100022 and then 100033.

we proceed 1 by 1 : it takes 4 iterations

**Binary search:**

In binary search it breaks the list into two parts and take middle value(100022) compare with 100033 now we are left with

100033,100044

we compare (100033) and (100044) with 100033

Thus process completed in 2 iterations. so it is very fast.

Binary search must be preferred over linear search.

Binary search requires sorted data. If you have to invest time to sort the data first you might be faster if you use linear search.