-3

I've been working on a piece of java code to determine the best threshold for a mergesort to switch to insertion sort at and my results have been less than satisfactory.

The tests I'm running take nearly an hour and produce data which doesn't really represent any particular pattern to me. So I'm hoping to ask what I should expect for the best threshold. Should it be constant? Should it be N/(some number)? is it constant after a certain N value? Roughly what would you expect?

(if it matters I am comparing Integer objects in java)

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
Ysehporp
  • 11
  • 3
  • Really? between 10 and 50? Thanks that kind of range is actually exactly what I was looking for! Like I said in my ask i've been trying to benchmark myself but i wasn't sure if i should be testing thresholds like 1000 or if i should be nearer to 100. Does the size N impact if its closer to 50 or 10? – Ysehporp Sep 28 '16 at 08:38
  • Awesome I'll give that a go – Ysehporp Sep 28 '16 at 08:39
  • Thanks for the help! Testing in that range there is finally a pattern emerging in my data. That was super helpful. – Ysehporp Sep 28 '16 at 08:47

1 Answers1

0

It depends somewhat on your actual hardware.

The best approach is to benchmark on your target hardware.

It's usually between 10 and 50, but test between 10 and 100.

In implementations I worked on some time ago, the threshold was 22 items.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541