Is Quicksort a potential security risk?

后端 未结 6 1064
粉色の甜心
粉色の甜心 2021-02-02 13:20

I just wondered whether (with some serious paranoia and under certain circumstances) the use of the QuickSort algorithm can be seen as a security risk in an application

6条回答
  •  你的背包
    2021-02-02 14:02

    Yes, it is a security risk - DoS, to be specific - which is trivially mitigated by adding a check for recursion depth in your quicksort, and switching to something else instead if a certain depth is reached. If you switch to heapsort, then you'll get introsort, which is what many STL implementations actually use.

    Alternatively, you just randomize the selection of pivot element.

提交回复
热议问题