help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recursive find of set of maximum numbers


From: Jordi Gutiérrez Hermoso
Subject: Re: Recursive find of set of maximum numbers
Date: Thu, 20 Oct 2011 14:56:27 -0500

2011/10/20 Jordi Gutiérrez Hermoso <address@hidden>:
> On 20 October 2011 03:11, thombark <address@hidden> wrote:
>> I have a vector of integers sorted in descending order. I need to extract the
>> indexes of the maximum sum of N values, then the next maximum sum etc.
>>
>> For example, there are 10 integers a(1) to a(10), where a(1) is the largest
>> number and a(10) is the smallest. Let's say N=3. The first max sum would
>> give me the obvious vector of (1,2,3) then the next max sum would give me
>> (1,2,4).  But the next max sum vector could be (1,2,5) or (2,3,4) depending
>> on the values in a(). If a is (10000,10,9,8,7...) then (1,2,5) is the
>> resulting vector but if a is (100,90,80,70,10...) then (2,3,4) is the
>> result. The very last vector to be returned would be (8,9,10).
>>
>> Is there a built-in function that would cut down the processing time of this
>> algorithm?
>
> Well, you realise you're asking for exponentially many values, but if
> this really what you want...
>
>   n = 10; k = 3
>   v = sort(rand(1,n), "descend");
>   idx = nchoosek (1:n, k);
>   [~, idx_s] = sort (sum(v(nchoosek (1:n, k)), 2), "descend");

Oops, this last line should have been

     [~, idx_s] = sort (sum(v(idx), 2), "descend");

- Jordi G. H.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]