【发布时间】:2015-06-12 06:10:44
【问题描述】:
我有以下伪代码:
SelectionSort(A)
n = A.length
for j=1 to n-1
smallest = j
for i=(j+1) to n
if A[i] < A[smallest]
smallest = i
exchange A[j] with A[smallest]
我认为第一个for循环测试会执行n次,嵌套的for循环会执行1 + 2 + ... + n = n(n+1)/2次(如果我有请纠正我'我错了)。但我不明白如何知道嵌套的 if 语句将执行多少次?是 1/2 * n(n+1)/2 吗?
【问题讨论】:
标签: algorithm sorting big-o time-complexity complexity-theory