473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Fastes way to do binary search

Hi,

I've got to byte arrays, and want to search first array for the position of
the first occurance of the other.

How is this best implemented ?

Kr. Soren
Nov 17 '05 #1
6 1870
On Sat, 5 Nov 2005 23:39:37 +0100, "Soeren S. Joergensen"
<no****@nodomain.com> wrote:
Hi,

I've got to byte arrays, and want to search first array for the position of
the first occurance of the other.

How is this best implemented ?

Kr. Soren


First of all, don't call it binary search. Binary search already has
another meaning. :)

Anyway, it is pretty straight forward. You use brute force. Start on
the first byte of the first array and see if the second array matches
at that position. If it doesn't try the second byte, and so on.

--
Marcus Andrén

Nov 17 '05 #2
>
First of all, don't call it binary search. Binary search already has
another meaning. :)
Sorry :)

Anyway, it is pretty straight forward. You use brute force. Start on
the first byte of the first array and see if the second array matches
at that position. If it doesn't try the second byte, and so on.


Well, that's also my first aproach.
But first array could potentially be rather large, and second array might
not exist, so the iteration time could take a while.
I hoped some clever head had thought oif a way to optimize such a task.

Anyway, thanx...

Soren
Nov 17 '05 #3
Soeren S. Joergensen wrote:
Hi,

I've got to byte arrays, and want to search first array for the position of
the first occurance of the other.

How is this best implemented ?


I think you could try to implement the boyer moore string searching
algorithm if you need a "best implementation". Check google or wikipedia
for an explanation of how it works.

hth,
Max
Nov 17 '05 #4
It depends.... If you are going to do multiple searches over time for
values in a
fairly stable array, then it may be more efficient to create a sorted
index and do
a binary search on the index. .NET has built in support for collections
with both
ordinal access and indexed access on a key.

Regards,
Jeff
I've got to byte arrays, and want to search first array for the

position of
the first occurance of the other.

How is this best implemented ?<

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #5
On Sat, 5 Nov 2005 23:39:37 +0100, "Soeren S. Joergensen"
<no****@nodomain.com> wrote:
Hi,

I've got to byte arrays, and want to search first array for the position of
the first occurance of the other.

How is this best implemented ?

Kr. Soren


It seems to me that what you are doing is a bit like string searching:

Given array1 = ABCDEFGHIJKLMNOP

and array2 = GHI

find the first position of array2 in array1.

Search for Boyer-Moore Algorithm, Knuth-Morris-Pratt algorithm or
Rabin-Karp algorithm. One of them should help you.

rossum

The ultimate truth is that there is no ultimate truth
Nov 17 '05 #6
Hi,

Seems like Boyer-Moore Algorithm will fit my needs and is fairly easy to
implement :)

Thanx all...

Kr. Soren
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ravi | last post by:
I recently had to write some code which required me to use a binary search tree (BST) due to running time concerns. I found that there is no BST class in the Standard C++ library. I have been told...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
9
by: Hemang Shah | last post by:
Hello fellow Coders! ok, I"m trying to write a very simple application in C#. (Yes its my first program) What I want to do is : 1) Open a binary file 2) Search this file for a particular...
8
by: Gordon Knote | last post by:
Hi can anyone tell me what's the best way to search in binary content? Best if someone could post or link me to some source code (in C/C++). The search should be as fast as possible and it would...
1
by: Andrew | last post by:
Hi, im trying to create a small function which can create a binary tree from the entries in a text file and after that we can perform all the usual operations like search, insert and delete etc....
10
by: free2cric | last post by:
Hi, I have a single link list which is sorted. structure of which is like typedef struct mylist { int num; struct mylist *next;
2
by: Timmy | last post by:
The bigger problem is with the Binary Search. The program crashes when it's excuted. and Visual Studio 2005 indicates stack over flow and shows a break at that function. Sequential search is...
0
by: Vince Filby | last post by:
Hi, We are working with distributing Lucene.net. We have Master Index Server which takes responsibility of distributing the index searching to multiple Index Servers by calling the remote...
0
by: Atos | last post by:
Binary search is used to locate a value in a sorted list of values. It selects the middle element in the array of sorted values, and compares it with the target value; that is the key we are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.