Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why we usually divide in two parts in divide and conquer algorithms?

In merge sort we divide in two parts while solving . Why we didn't divided it in 3 or more parts ? Similarly in many divide and conquer problems I have seen one tend to divide in two parts . Why not 3 or more parts ? What impact would it have on solution / complexity ?

like image 894
Rishav Avatar asked Oct 23 '17 08:10

Rishav


1 Answers

Dividing the problem in 3 or more parts is usually inconvenient and has no effect on the algorithmic complexity. It will usually impact real-world performance negatively because more complicated code tends to be less efficient in practice than simple streamlined code. But this is not always the case.

There are a few practical D&C algorithms that divide the problem in more than two parts because it's beneficial to do so. The dual-pivot quicksort is one example. It tends to be somewhat faster (by a constant factor) than the regular quicksort.

like image 129
n. 1.8e9-where's-my-share m. Avatar answered Jun 21 '23 19:06

n. 1.8e9-where's-my-share m.