🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java
Article #428

Re: Finding 2 biggest numbers in a row

#428
From: Andy Zaidman
Date: Tue, 14 Nov 2000 00:00
69 lines
3376 bytes
Well, it seems to me as if this algo just doesn't do the job... The problem
is that in your example the 2 biggest values are in the upper half of your
list of numbers... So, when you divide the list in 2, it will return the
biggest numbers of each of the halves... and not the biggest numbers of the
entire list...

If you definitly wanted to work recursively... Try the same algo, but return
only the biggest value and then reapply the algo to the same list, but with
the biggest value removed... Otherwise, just plainly run through the entire
list and keep the 2 biggest values in 2 variables...

Andy


"Bart Vandewoestyne" <Bart.Vandewoestyne@skynet.be> wrote in message
news:3A11B99A.2BB2E1E7@skynet.be...
> I am trying to write a program that implements an algorithm to find the
two
> largest integers out of a row of numbers.
> My algorithm should work this way:
>
> The number of elements in the row is a power of 2.
>
> I separate the row in two halves, and then i apply the same algorithm
recursivly
> to the two new rows.  If I have the two biggest numbers of these new rows,
then
> i can find the two biggest of the total with maximum 2 comparisons.
>
> The alorithm I implemented so far is located at:
>
> http://users.skynet.be/vandewoestyne/downloads/Searcher.java
>
> and
>
> http://users.skynet.be/vandewoestyne/downloads/BigThings.java
>
> But it seems to have a mistake in it, because this was an example of an
> incorrect output I got ('links' = left, 'rechts' = right, 'Grootste waarde
=
> Biggest value', 'Tweede grootste waarde='second largest value'):
>
> Heaven:~/projecten/ontwerpen02$ java Searcher
> 78 67 51 15 34 28 31 53 35 50 68 1 33 92 95 13
>
> links : 78 67 51 15 34 28 31 53
> rechts: 35 50 68 1 33 92 95 13
> links : 78 67 51 15
> rechts: 34 28 31 53
> links : 78 67
> rechts: 51 15
> links : 34 28
> rechts: 31 53
> links : 35 50 68 1
> rechts: 33 92 95 13
> links : 35 50
> rechts: 68 1
> links : 33 92
> rechts: 95 13
> Grootste waarde:        95
>
> Tweede grootste waarde: 78
>
> --
> Ing. Bart Vandewoestyne   Bart.Vandewoestyne@skynet.be
> Hugo Verrieststraat 48        GSM: +32 (0)478 397 697
> B-8550 Zwevegem http://hello.to/MC303
> ----------------------------------------------------------------------
> "Any fool can know, the point is to understand." - Albert Einstein
Technical Details
Message-ID: <8usf9t$fod$1@news1.skynet.be>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3A11B99A.2BB2E1E7@skynet.be>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5d71,470c011dba4db9c3
X-Google-Attributes: gidf5d71,public
X-Google-Thread: 113ae9,470c011dba4db9c3
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 10a146,470c011dba4db9c3
X-Google-Attributes: gid10a146,public
X-Google-Thread: fcea4,470c011dba4db9c3
X-Google-Attributes: gidfcea4,public
From: "Andy Zaidman" <Andy.Zaidman@(nospam)Bigfoot.com>
Subject: Re: Finding 2 biggest numbers in a row
Date: 2000/11/14
Message-ID: <8usf9t$fod$1@news1.skynet.be>
X-Deja-AN: 693669366
References: <3A11B99A.2BB2E1E7@skynet.be>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-Complaints-To: abuse@skynet.be
X-Trace: news1.skynet.be 974241917 16141 62.4.247.111 (14 Nov 2000 22:45:17 GMT)
Organization: Belgacom Skynet SA/NV
X-MSMail-Priority: Normal
NNTP-Posting-Date: 14 Nov 2000 22:45:17 GMT
Newsgroups: comp.lang.java,comp.lang.java.help,comp.lang.java.programmer,be.comp.programming