Probabilistic search - psearch.tar.gz
Rioshin an'Harthen
rharth75 at hotmail.com
Wed Apr 5 00:44:09 PDT 2006
"sundaresh" <sundaresh_member at pathlink.com> wrote in message
news:e0vqej$12o5$1 at digitaldaemon.com...
>I believe that I have replied to this already. My first suspisions was with
> comparisons, but there is nothing wrong with it. Comparisons is updated
> prior
> to call to the base case psearch, so why should it be updated again during
> the
> base case, since in the base case, no recursive call to psearch is being
> made.
That's just it. You don't count how many comparisons it takes to find a
match, just
how deep it has to go. And with an original size of 512, that always leads
to
log2(512).
Since you only count the depth of the search, not the amount of comparisons,
you'll
find it's almost always 9 - it may be shorter, depending on which item was
randomly picked to be searched for.
> Doing so might actually result in 256 or so as you claim, but that would
> be
> introducing a bug and not eliminating it.
Frankly, you are so wrong in this. Now you only count the depth, not how
many items it searches. And it's the items that matter, not the depth. It's
the amount of comparisons that tells what time the algorithm has - and in
the case of this, it's most definitely O(N).
> Sorry, these arguments have only served to convince me even further of the
> correctness and workability of this algorithm.
*sigh* A fool, then.
Many have shown you where you've gone wrong, but you seem to be "I'm right
and I know it, you'd just introduce a bug in it"... If you refuse to listen,
go ahead.
Mathematically, it is possible to prove that no search of unordered data can
be done in time less than O(N) - you always have to in the worst case test
*all* occurences.
I'm attaching an altered version of psearch with this message, so you can
test it yourself. It's a zip archive with MS-DOS line endings (since that's
the system I happen to be on). I strongly recommend after unzipping and
compiling that you invoke it by directing standard output to a file - it's
going to display so much data on the amount of comparisons it took to find
something, as well as how it found it. Then you'll see it's not
O(log N) but O(N).
begin 666 psearch.zip
M4$L#! H``````!=5A30````````````````(````<'-E87)C:"]02P,$% `"
M``@`%E6%-$XL)B*]`0``P at 0``!$```!P<V5A<F-H+W!S96%R8V at N8\5336_;
M, P]V[^"2Q%4CI7LZ[8L'89>B]YZ*U H$1T+<.1 4M9V0_][*4IVC6$8NNTP
M`P9D\I%\[XD^,W;7G31^]D&;?M5>E&>32&>V,50:&V#7'X[*&=];O^; 03W<
M:3R&=EV6WWJC87'TJ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!("``!P<V5A<F-H+W!S96%R8V at N8RYB86M02P$"% `4``(`" `7584T0<;[
M`=8```!'`0``$0`````````!`" ```!F`P``<'-E87)C:"]P<V5A<F-H+FA0
M2P$"% `4``(`" #HBGHT<OR4O,X````Q`0``%0`````````!`" ```!K! ``
M<'-E87)C:"]P<V5A<F-H+F at N8F%K4$L!`A0`% `"``@`F(IZ-%'^F>R@!0``
MJPP``!,``````````0`@````; 4``'!S96%R8V at O<'-E87)C:"YT>'102P$"
M% `4``(`" `7584T(P;I]\P!```X! ``#@`````````!`" ````]"P``<'-E
M87)C:"]T97-T+F-02P$"% `4``(`" !63'HT'AH.6Z(!``!R`P``$@``````
M```!`" ````U#0``<'-E87)C:"]T97-T+F,N8F%K4$L%!@`````(``@`]P$`
'``</````````
`
end
More information about the Digitalmars-d
mailing list