Insertion Sort of O(n^2) complexity and using Binary Search on previous values to improve complexity

五迷三道 提交于 2021-01-28 06:04:04

问题


How would the algorithm's (of Insertion Sort of O(n^2)) complexity change if you changed the algorithm to use a binary search instead of searching previous values until you found where to insert your current value. Also, When would this be useful?


回答1:


Your new complexity is still quadratic, since you need to move all of the sorted parts rightward. Therefore, using binary search is only marginally better.

I would recommend a fast sorting algorithm (in O(n log n) time) for large arrays, the quadratic insertion sort algorithm is suited only for small arrays.



来源:https://stackoverflow.com/questions/50360582/insertion-sort-of-on2-complexity-and-using-binary-search-on-previous-values-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!