Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

binary search

Former Member
0 Likes
1,093

Hi

what is the diff b/w

1. read table itab with key city = 'hyderabad'.

2. read table itab with key city = 'hyderabad' binary search.

8 REPLIES 8
Read only

Former Member
0 Likes
1,033

If the addition <b>BINARY SEA</b>RCH is specified, the search is binary instead of linear. This considerably reduces the runtime of the search for larger tables (from approximately 100 entries upwards). For the binary search, the table must be sorted by the specified search key in ascending order. Otherwise the search will not find the correct row.

Read only

0 Likes
1,033

1. by default is linear search

2. binary search

Read only

anversha_s
Active Contributor
0 Likes
1,033

hi,

the first one is slow in processing.

it will serach the whole table.

the second 1 is very faster. i recomment u to use that only.

it will search by using the INDEX, which is very faster.

for any clarifiaction pls mail me.

pls reward points, if this helped u.

regards,

anversha.

anversha.shahul@wipro.com

Read only

Former Member
0 Likes
1,033

Hi,

the statement,

<b> Read table ... Binary search.</b>

use binary search logic for reading the table.

Before using the binary search you must sort the table using field by which you are reading the table and you must sort in ascending order only.

Rgds,

Mohan

Read only

Former Member
0 Likes
1,033

1 . this search takes lot of time , it searches one by one

2 . binary search is faster

suppose say there are 100 records in the internal table and you had written

read table itab with key city = 'hyderabad' binary search.

now it splits its search to 50 records and searches for H as Hyderabad starts with H whether it is in top 50 records or bottom 50 records

if it is in bottom 50 records , then again it will split to 25 each and searches for the next leeter and so on which simplifies the search

Read only

Former Member
0 Likes
1,033

hi,

The prerequisite for 'Binary Search' to read record fastly is that the internal table has to be sorted by the same key with which we are reading the table. Prior to READ statement, if there is no SORT statement with the same key as of read statements' key, Binary Search addition is of no use. It just acts like without binary search.

Regards,

Vinny

Read only

Former Member
0 Likes
1,033

check this link,to know more about BINARY SEARCH with READ TABLE

Regards

srikanth

Read only

Former Member
0 Likes
1,033

I think the most of them have explained the importance of using binary search as well as pre-requisities and default.

I would just like to add the algorithm for binary search so that it becomes more clear how the table is read.

A binary search algorithm (or binary chop) is a technique for finding a particular value in a linear array, by ruling out half of the data at each step, widely but not exclusively used in computer science. A binary search finds the median, makes a comparison to determine whether the desired value comes before or after it, and then searches the remaining half in the same manner. A binary search is an example of a divide and conquer algorithm (more specifically a decrease and conquer algorithm). From the above it is very important to SORT the table otherwise it might be worse than linear search.

Regards

Anurag