我正在读,有一段代码,我认为它是O(n)复杂性,但它是O(n²)。为什么这个for range循环被认为是O(n²)type Sequence []intfunc (s Sequence) String() string {
...for i, elem := range s { // Loop is O(N²); will fix that in n
我读了一个关于的关于TreeSet时间复杂性的文章,答案是它需要O(n)时间。但是,我不明白为什么迭代是O(n)而不是O(n*nlogn)。每个下一次调用都使用while (iterator.hasNext()){ //Runs N times
System.out.println(iterator.next(