【发布时间】:2020-03-05 23:57:34
【问题描述】:
给定一个数组上的插入排序,您在其中进行 O(n) 比较以找到要插入的索引,然后插入,时间复杂度是否为 O(n^3)?
因为对于每个元素 (n),您遍历排序列表 (n),然后插入 (n)。
据我了解,正常的实现没有任何插入,只有交换将其减少到 O(n^2),因为项目通过交换而不是插入放置在正确的位置。
O(n^3) 插入排序的伪代码:
for element in array
find the correct location
then insert in the correct location
【问题讨论】:
标签: sorting big-o complexity-theory insertion-sort