• What will be the change in complexity if we will choose 2 and 3 pivots in the quicksort algorithm


    Q:

    What will be the change in complexity if we will choose 2 and 3 pivots in the quicksort algorithm ?
    The exact complexity and why ??

    A:

    if we use 2 element as a pivot (suppose 1st and last element) then we partisan the array into three part and we use quick shot in every partisan

    So the new recurrence relation became

    T(n) = 3 x T(n/3) + O(n)
    we assume the array partisan in equal parts and finding the exact position of pivot is O(n)
    now applying master theorem f(n) = O(n); a=3; b=3; 
    f(n) = O(n ^ (log a/log b))

    so complexity is O(nlogn)

    Now if we take k-1 pivot element the partisan the array in k part so
    T()= k x T(n/k) + O(n)
    which complexity is also O(n long)

    so irrespective of how many partisan we do the complexity of quick sort remains same.

  • 相关阅读:
    3
    2
    1
    11
    12
    8888888888
    99999999999
    88888888888
    77777777
    10.23
  • 原文地址:https://www.cnblogs.com/yayagamer/p/2560852.html
Copyright © 2020-2023  润新知