Article View: comp.os.ms-windows.programmer.tools.owl
Article #7Re: Searching in a sorted array
From: Frithiof Jensen
Date: Fri, 06 Oct 1995 14:53
Date: Fri, 06 Oct 1995 14:53
37 lines
1569 bytes
1569 bytes
In article <44prsv$ki7@news.netvision.net.il>, galor@netvision.net.il (Guy Naor) says:
>I'm looking for the best (fastest) way for finding the first occurence
>of a string in a sorted array, when entries aren't unique. For
>example:
>
>an array containing: AA,AB,AC,AD,BB,BB,BB,BC,BF,CG,CG,CT
>I want to find the first occurance of BB.
>
Why not compress the data?
Your sorted array is an array of structures like this:
data
{
int frequency;
char item[2];
}
or "chars" AA,AB,AC,AD,BB,BC,BF,CG,CT
"freqs" 1 1 1 1 3 1 1 2 1
so any occurance of "BB" is the first!
you might of course blow any speed advantage gained this way by the
compression, but this will depend on your problem.
And you will want to add >> and << operators to compress/expand the
array of course.
good luck,
frithiof jensen.
===============================================================================
The above article is the personal view of the poster and should not be
considered as an official comment from the JET Joint Undertaking
===============================================================================
Technical Details
Message-ID:
<453fsr$oc@postman.jet.uk>Path:
arc1-ca.pugleaf.net!jet.uk!usenetReferences:
<44prsv$ki7@news.netvision.net.il>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!jet.uk!usenet From: Frithiof.Jensen@jet.uk (Frithiof Jensen) Newsgroups: comp.os.ms-windows.programmer.tools.owl,comp.lang.c++ Subject: Re: Searching in a sorted array Date: 6 Oct 1995 14:53:15 GMT Organization: JET Joint Undertaking Message-ID: <453fsr$oc@postman.jet.uk> References: <44prsv$ki7@news.netvision.net.il> NNTP-Posting-Host: pc_0020afbf8f16.jet.uk X-Newsreader: WinVN 0.92.6+