Sorting an array with minimal number of comparisons

前端 未结 6 1249
情话喂你
情话喂你 2020-11-29 06:09

I need some help with my CS homework. I need to write a sorting routine that sorts an array of length 5 using 7 comparisons in the worst case (I\'ve proven that 7 will be ne

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 06:28

    Bucket sort can be implemented as a comparison algorithm as follows:

    Take an element.

    Compare it to all buckets.

    Drop it into the bucket that matches. <- Comparison needed.

    If bucket not found, create a new bucket.

    Therefore it's a dynamic bucket sort algorithm which I just described.

    I already invented/described this on newsgroup in the past.

提交回复
热议问题