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,104

Hi,

Can anyone explain Binary Search Concept

Regards,

Maya

10 REPLIES 10
Read only

Former Member
0 Likes
1,081

Hi,

binary search is for improving the performance while fetching the data from internal table

for more info see this link

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb373d358411d1829f0000e829fbfe/content.htm

rds,

bharat.

Read only

Former Member
0 Likes
1,081

Hi MAya,

Go through below link,

Reward if useful!

Read only

Former Member
0 Likes
1,081

Hi,

It is used to find/read the record fast.

Have to sort the ITAB1 first before this by that field/s.

loop at itab.

clear itab.

read table itab1 with key f1 = itab-f1 binary search.

if sy-subrc = 0.

...........

endif.

endloop.

reward points if useful

regards,

ANJI

Read only

Former Member
0 Likes
1,081

hi,

first sort the table content,

and then Mark HIGH(High Value),LOW(Low Value), Mid(middle value)

search the value inside two half High to Middle and then Middle to LOW

if the value in High to Middle then Separation happen inside that

its keeps on moving just like that.

Reg,

Hariharan

Read only

Former Member
0 Likes
1,081

hi,

In a set of records, if we want to search for a record by using binary search concept..

First of all, the set of records are divided into two subsets. It searches in the first subset by again dividing it into subsets. If it is not found in first subset, then it searches in the next subset.

Regards

sailaja.

Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
1,081

Hi

Suppose you have 10 records and 6 th record is your search record.

In linear search we have to search record by record.

In binary search search can split the entire records into 2 groups and suppose if it finds the searching record in 1 group,it can ignore the other group.

Now in that considered group agian it split entire records into 2 groups and begin searching.

searching can be carriedout until it finds the searching records.

Processing time is very fast.O(log (2)).

Restriction to use the Binary search on a table is the table must be in a sorted order.

Regards,

Sreeram

Read only

Former Member
0 Likes
1,081

Never forget to sort the internal table on keys in "with key" statement before.


SORT bin_tab BY k1 k2 ... kn.

LOOP AT itab.

   READ TABLE bin_tab WITH KEY k1 = itab-k1 k2 = itab-k2 ... kn = itab-kn

ENDLOOP.

Read only

Former Member
0 Likes
1,081

Hi Maya,

It is something like this.

If a table has 100 records.

You are searching for 97th record.

If you search sequentially, then you need to take 97 steps in the worst case.

If you use binary search, you will split the contents into two.

1-50 and 51-100

If the search key is greater than half of the total records, then you don't need to search the lower half.

here in our case, you don't need to look in 1-50 set as 97 >50.

Now.

YOu split 51-100 as 51-75 and 76-100.

again you compare 97 with 75. YOu can disregard 50-75.

The set you need to search is 76-100.

Split it again 76-87 and 88 to 100.

97> 87 so disregard 76-87 set.

Similarly you gave to continue this algorithm till you find the match.

This will improve the performance logarithmitically.

Means, the worst case for a search for 1024 records will be 32 takes.

The worst case for a search of 10 power 100 records will be just 100.

Regards,

Ravi

Read only

Former Member
0 Likes
1,081

Hi Raghuram,

<b>

Clear description about Binary search...... from the scratch.</b>

What is what ?

Go through this link...........

http://en.wikipedia.org/wiki/Binary_search

<b>Reward all helpful answers.</b>

Regards,

V.Raghavender.

Read only

Former Member
0 Likes
1,081

Simple way find to have a no 7 from a list of 1-10 numbers

1st step check between (n = 10 ) / 2 => 5 search betn lower range 1-5

2nd step check between ( n = 5 ) / 2 =>2 search betn 6-7

3rd Step check between (n = 2 ) / 2 => 1 check with 6

4th Step check with 7

its like a tree structure.

Hope you have undertsand

Reward if helpful