我们编写了一个函数来编写一个从最小到最大排序数组的伪代码。这就是我写的:
Function sorting(list)
;define
index = 0
for i in list.length:
;take first element from unsorted part in array
small = list[0+i]
;length of unsorted list
for n in list.length-i:
;runs on all elements in list starting from unsorted part (i)
if list[n+i] <= small:
;if it is smallest, take smallest place
small = list[n+i]
;save it's index
index = n+i
put where the smallest is, the first element in unsorted part
list[index] = array[i]
;put in first place of unsorted the smallest. we actually exchange smallest with first
array[i] = small
return list
所以对于第一个循环,我做了n次,
N(1 + ....)
但是第二个循环,它总是变小,我不知道如何计算它。
请帮助
Ps,我不需要大o,我知道它是O(n²),我需要复杂的公式