Obviously your data must be sorted for the question to be relevant.  Is it
already sorted or is the cost of sorting it part of the difference?

If your search target is uniformly distributed against the key, then on
average a linear search will require 1750 iterations of your compare loop.
A binary search will require a constant 12 iterations regardless of
distribution.

Only you can decide if the savings in processing time is worth the cost to
make the change and the potential additional testing/maintenance effort due
to the added complexity.

:>: -----Original Message-----
:>: From: IBM Mainframe Assembler List [mailto:ASSEMBLER-
:>: [email protected]] On Behalf Of Dougie Lawson
:>: Sent: Monday, October 21, 2013 4:32 AM
:>: To: [email protected]
:>: Subject: Linear search vs binary
:>:
:>: If I have a table of 3,500 entries of twelve bytes (I'm doing a compare
:>: of
:>: eight bytes to find the entry I'm looking for and a check on a half word
:>: marker for the end of the table to avoid running off the end) then is it
:>: worth the pain of re-writing it as a binary search.
:>:
:>: If it is worth the pain and does anyone have a sample binary search
:>: tucked
:>: away.
:>:
:>: The table is built into a CSECT at the bottom of my code. I can
:>: restructure
:>: it if we need any special pointers to make a binary search work.
:>:
:>: Dougie

Reply via email to