Mergesort - Is Bottom-Up faster than Top-Down?

前端 未结 3 1279
清酒与你
清酒与你 2021-02-07 13:16

I\'ve been reading \"Algorithms, 4th Ed\" by Sedgewick & Wayne, and along the way I\'ve been implementing the algorithms discussed in JavaScript.

I recently took the

3条回答
  •  花落未央
    2021-02-07 14:01

    If by faster you mean fewer "iterations" then yes. If you're wondering about execution time maybe.

    The reason is some of those 21,513 iterations are doing more than the 22,527 iterations.

    From looking at the source it seems like some of the leaf nodes in your diagram are being sorted together not individually resulting in fewer merges and sorts but them taking longer.

提交回复
热议问题