<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: binary search performance in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711691#M628631</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when compared to linear search , binary search is better performance than linear search in case of large amount of data.&lt;/P&gt;&lt;P&gt;Binary search devides the data into 2 eq parts and start search for the given field value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex..&lt;/P&gt;&lt;P&gt;if we have 100 rec in itab. you are looking for 29th rec.&lt;/P&gt;&lt;P&gt;then Binary search devides into two halfs and search for the value 29 in two halfs.&lt;/P&gt;&lt;P&gt;if it is found in first half (1-50) then it again devides this into another two halfs (1-25 &amp;amp; 26-50) and start processing in the same way..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now the desired rec will be in 2nd half(26-50)&lt;/P&gt;&lt;P&gt;then it omits first half and start search in 2nd half by deviding again into 2 halfs..&lt;/P&gt;&lt;P&gt;like that the process goes until the 29th rec.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if there is less amnt of data its better to go for linear search.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Aug 2007 05:59:59 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-08-14T05:59:59Z</dc:date>
    <item>
      <title>binary search performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711687#M628627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;TYPES: begin of t_vbap,&lt;/P&gt;&lt;P&gt;       vbeln type vbap-vbeln,&lt;/P&gt;&lt;P&gt;       end of t_vbap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: i_vbap type table of t_vbap,&lt;/P&gt;&lt;P&gt;      w_vbap type t_vbap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hi all,&lt;/P&gt;&lt;P&gt;i'm curious about using the binary search, i get better performance with linear search compare to binary search with the following testing statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;anybody can advise what's going wrong on the query statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;binary search&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="------------------" /&gt;&lt;P&gt;select vbeln into table i_vbap&lt;/P&gt;&lt;P&gt;from vbap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort i_vbap by vbeln.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table i_vbap into w_vbap&lt;/P&gt;&lt;P&gt;with key vbeln = '0000000419'&lt;/P&gt;&lt;P&gt;binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;linear search&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="------------------" /&gt;&lt;P&gt;select vbeln into table i_vbap&lt;/P&gt;&lt;P&gt;from vbap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table i_vbap into w_vbap&lt;/P&gt;&lt;P&gt;with key vbeln = '0000000419'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THanks,&lt;/P&gt;&lt;P&gt;BK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 10:03:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711687#M628627</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T10:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: binary search performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711688#M628628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This can be a case like this&lt;/P&gt;&lt;P&gt;Suppose this is your list.&lt;/P&gt;&lt;P&gt; 1 2 3 4 5 6 7 8  9&lt;/P&gt;&lt;P&gt;Binary search will take around 3 to 4 steps to find value '1'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Where as Linear search will take only 1 step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Binary search will Devide the result list into TWO in each step and eliminate one HALF based on the Value being searched.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if you are searching 1 here it will first devided the group into&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 2 3 4 --  6 7 8 9&lt;/P&gt;&lt;P&gt;SInce 5 is &amp;gt; than 1 it eliminates 6 7 8 9&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And then same process till it gets 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 10:06:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711688#M628628</guid>
      <dc:creator>seshatalpasai_madala</dc:creator>
      <dc:date>2007-08-13T10:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: binary search performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711689#M628629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Of course, if you measure the whole process!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The read itself is muich faster than the read without binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, the sort is much more expensive than the read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The advantage of the binary search come in, if you use the read in a loop and&lt;/P&gt;&lt;P&gt;have to read nearly all lines of the internal table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab1 into wa1&lt;/P&gt;&lt;P&gt;   read itab2 with key k1 = wa1-k1 binary search&lt;/P&gt;&lt;P&gt;endloop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this construction the read without binarty search would kill your performance when itab2 becomes large.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Say, do 50 to 100 reads to justify one sort!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 10:19:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711689#M628629</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T10:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: binary search performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711690#M628630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;COMPARED TO LINEAR AND BINARY &lt;/P&gt;&lt;P&gt;BINARY IS THE BEST METHOD &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF UR RECORDS ARE TOO LESS THEN LINEAR SEARCH WILL GET FASTER OUTPUT &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHEN THE NUBER OF RECORDS ARE MORE THAN LINEAR SEARCH WILL TAKE SOME TIME &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SO ALL WAYS BETTER TO USE BINARY SEARCH &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF THE NUMBER OF RECORDS ARE VERY HIGH T HEN BINARY SEARCH WIL PERFORM VERY FAST THAN LINEAR SEARCH &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REWARD IF USEFULL&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2007 10:55:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711690#M628630</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-13T10:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: binary search performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711691#M628631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when compared to linear search , binary search is better performance than linear search in case of large amount of data.&lt;/P&gt;&lt;P&gt;Binary search devides the data into 2 eq parts and start search for the given field value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex..&lt;/P&gt;&lt;P&gt;if we have 100 rec in itab. you are looking for 29th rec.&lt;/P&gt;&lt;P&gt;then Binary search devides into two halfs and search for the value 29 in two halfs.&lt;/P&gt;&lt;P&gt;if it is found in first half (1-50) then it again devides this into another two halfs (1-25 &amp;amp; 26-50) and start processing in the same way..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now the desired rec will be in 2nd half(26-50)&lt;/P&gt;&lt;P&gt;then it omits first half and start search in 2nd half by deviding again into 2 halfs..&lt;/P&gt;&lt;P&gt;like that the process goes until the 29th rec.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if there is less amnt of data its better to go for linear search.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Aug 2007 05:59:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711691#M628631</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-14T05:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: binary search performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711692#M628632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The binary search (which requires a sorted table) will give you better performance &amp;lt;u&amp;gt;on average&amp;lt;/u&amp;gt;. For any one particular (unknown) input you can't say with certainty whether binary or linear search gives the best performance, but on average binary has better performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The reason is that the binary search, as mentioned, divides the search range in two for every 'lookup' until it finds a matching record, whereas the linear search trots sequentially along until it finds a match. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The average search time for a linear search will be N/2 where N is the number of entries in the table. A binary search will repeatedly cut the search range in half. The search time is therefore at most Log2(N).&lt;/P&gt;&lt;P&gt;Example: In an internal table with 128 entries the average linear search has to check 64 entries, and in the worst case all 128 entries have to be checked. The binary search will never have to check more than 8 entries for a 128-entry table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See also &amp;lt;a href="http://en.wikipedia.org/wiki/Binary_search"&amp;gt;Wikipedia&amp;lt;/a&amp;gt; where the binary search algorithm is well explained.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wikipedia also mentions that for a small number of entries in the table, linear lookup can exhibit better performance. But then again, when you have a small number of entries there usually will not be a performance problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Aug 2007 06:59:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711692#M628632</guid>
      <dc:creator>KjetilKilhavn</dc:creator>
      <dc:date>2007-08-14T06:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: binary search performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711693#M628633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hallo Kjetil,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you are of course right. However, the argument becomes much simpler, if you  take the sort into your discussion. For a single read, the costs for the sort can not be justified.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For many reads, the sort can be justified, and one can calculate with average costs, which make binary search better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The binary search works without sort, but the results will be INCORRECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Aug 2007 08:06:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711693#M628633</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-14T08:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: binary search performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711694#M628634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah... of course. I didn't think of that. Hmmm... since a binary sort costs up to (N - 1) * Log2(N) you can read quite a few times before you catch up with the total runtime of sorting and binary reading.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I prefer using sorted buffer tables for those tables where I will be READing entries anyway, so I don't need to sort before reading. It is just as easy, at least if you insert entries whenever they don't already exist. The READ statement gives you the index where the new entry must be inserted, so keeping the table sorted at all times is not difficult.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Aug 2007 17:31:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711694#M628634</guid>
      <dc:creator>KjetilKilhavn</dc:creator>
      <dc:date>2007-08-14T17:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: binary search performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711695#M628635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi chandra ur explanetion obout binary search is very nice&lt;/P&gt;&lt;P&gt;  keep it up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;happy coding&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;nagaraju&lt;/P&gt;&lt;P&gt;hcl technologies&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2007 11:20:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-performance/m-p/2711695#M628635</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-21T11:20:47Z</dc:date>
    </item>
  </channel>
</rss>

