bucket sort

  • Follow


hello
as far as i know BucketSort is the fastest sort alg for K value in an array
i wrote the code but the sort() function of matlab is still working faster then my code 
any ideas?

// buckets sort with max value of k
for i=1:k
    Bucket(A(i))=Bucket(A(i))+1;
 end
i=1;
for j=1:k
    for m=1:Bucket(j)
        A(i)=j;
        i=i+1;
    end
end

thx yossi
0
Reply yossi 11/15/2010 8:36:05 PM

On 10-11-15 02:36 PM, yossi kfir wrote:
> hello
> as far as i know BucketSort is the fastest sort alg for K value in an array
> i wrote the code but the sort() function of matlab is still working
> faster then my code any ideas?
>
> // buckets sort with max value of k
> for i=1:k
> Bucket(A(i))=Bucket(A(i))+1;
> end

That part looks to me like a histogram sort rather than a pure bucket sort ?
> i=1;
> for j=1:k
> for m=1:Bucket(j)
> A(i)=j;
> i=i+1;
> end
> end

I would think it likely that matlab's sort is implemented at a lower level, 
able to avoid some of the overheads of using pure Matlab code. For example, 
not having to continually re-extract the actual data field from the internal 
structures that describe the variables.
0
Reply Walter 11/15/2010 8:46:04 PM


"yossi kfir" <yossikfir@walla.com> wrote in message <ibs5jl$sue$1@fred.mathworks.com>...
> hello
> as far as i know BucketSort is the fastest sort alg for K value in an array
> i wrote the code but the sort() function of matlab is still working faster then my code 
> any ideas?
> 
> // buckets sort with max value of k
> for i=1:k
>     Bucket(A(i))=Bucket(A(i))+1;
>  end
> i=1;
> for j=1:k
>     for m=1:Bucket(j)
>         A(i)=j;
>         i=i+1;
>     end
> end
> 
> thx yossi

FYI you can achieve the bucket sort with built-in command ACCUMARRAY. Then you might be able to beat sort.

Bruno
0
Reply Bruno 11/15/2010 8:59:04 PM

thank u Walter 
bruno thx for the advice ill try to do that with accumarray 
0
Reply yossi 11/15/2010 9:21:03 PM

3 Replies
546 Views

(page loaded in 0.037 seconds)

Similiar Articles:













7/24/2012 4:31:43 PM


Reply: