0

i was little confuse to make recursion (T) what if we divide the array (n/4). and why it is always recommended to use odd division of array why specifically 5. when we divide into 5 the recursion is like this T(n) <= theta(n) + T(n/5) + T(7n/10)

what will be the recursion (T) of this and is it effect time complexity as well because when we divide the array into (n/5) the time complexity is theta(n).

Sam
  • 1
  • 1
  • 1
    4 is even which makes it rather inconvenient to work with medians. – n. m. could be an AI Oct 26 '22 at 05:14
  • can you explain it how it is inconvenient please? – Sam Oct 26 '22 at 16:30
  • I am not quite sure how to explain that, but here you go. Your goal is to choose a pivot that is as close to be in the middle of the array as possible. Now look at 4 numbers `1 2 3 4`. None of them is exactly in the middle. If you choose 2, there are fewer elements on the left of it than on the right. If you choose 3, there are fewer elements on the right than on the left. In either case your pivot is biased and you need to take this into account when proving complexity. – n. m. could be an AI Oct 26 '22 at 17:41
  • but you can make median by taking average of 2+3/2 = 2.5 that will be your median of this group. – Sam Oct 27 '22 at 01:41
  • No you can't. This is not how quicksort or quickselect work. – n. m. could be an AI Oct 27 '22 at 06:04

0 Answers0