Application Development 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: 

abap question

Former Member
0 Kudos
110

1. what is the prerequiste for binary search?

11 REPLIES 11

Former Member
0 Kudos
90

hi,

SORT the table on the fields on Which you are going to Apply BINARY Search.

Regards

Sumit Agarwal

0 Kudos
90

Sort your table based on a key field.

Regards,

Sinu.

Former Member
0 Kudos
90

Hi,

Before going for Binary Search, Sort the table By that Field.

Follow this Link,it has detail description-

Regards,

Sujit

Former Member
0 Kudos
90

Hi Prabhakar,

First you search the SDN for such basic questions and even though you cannot find then post it.

Regards,

Chandra Sekhar

Former Member
0 Kudos
90

Hi,

Sorting the table is the prerequisite for the binary search.

Edited by: chandrika chireddy on Jul 21, 2008 7:17 AM

Former Member
0 Kudos
90

Hi,

I didn't get your query exactly..

If you want to sort through binary search then try this one..

READ TABLE WITH KEY BINARY SEARCH.

Example is shown below:

Field1 Field2

-


John 12345

Alice 23478

Sam 54321

john 50000

DATA: BEGIN OF ICODE OCCURS 0,

FIELD1(5),

FIELD2(5),

END OF ICODE.

READ TABLE ICODE WITH KEY FIELD1 = 'John' BINARY SEARCH.

Former Member
0 Kudos
90

Hi,

Sort the table by the key fields............

before performing a binary search...

Former Member
0 Kudos
90

Hi prabhakar,

If you read entries from standard tables using a key other than the default key, you can use a binary search instead of the normal linear search. To do this, include the addition BINARY SEARCH in the corresponding READ statements.

READ TABLE <itab> WITH KEY <k1> = <f1>... <kn> = <fn> <result>

BINARY SEARCH.

The standard table must be sorted in ascending order by the specified search key. The BINARY SEARCH addition means that you can access an entry in a standard table by its key as quickly as you would be able to in a sorted table.

Binary search repeatedly divides the search interval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half.

one pre-requisite for binary search is that table has to be sorted in ascending order,

E.g.

say Itab[] has 5 entries.

10

20

30

40

50,

Now say you want to serach value 20.

Binary serach divides the sorted internal table into 2 halves 5/2 gives

1) 10

20

30

2) 40

50

Now it compares the value to be searched(i.e. 10) with last entry of the first half

if search value is less than last entry of first half it again performs this division on first half of the table.

else compares search value with first entry of 2nd half search value is greater or equal to first entry of second half it dividies the second half till the seasrch value is found.

Note: you cannot do binary search on tables sorted in descending order.

thnks

anurodh

Former Member
0 Kudos
90

hi,

sorting the elements or fields is a prerequisite for binary search..for more details you can log on to saptechnical.com

Former Member
0 Kudos
90

Hi,

Go through this link:

Regards,

Shailaja

Former Member
0 Kudos
90

hi,

sorting the elements or fields is a prerequisite for binary search..for more details you can log on to saptechnical.com.

note:you cannot sort the elements in descending order in binary search