COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### bucket sort

• Email
• 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

See related articles to this posting

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

"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

thank u Walter
bruno thx for the advice ill try to do that with accumarray
 0

3 Replies
644 Views

Similar Articles

12/9/2013 7:28:39 PM
[PageSpeed]