我无法理解 Big-O 表示法。如何找到该函数的 Big-O 和最坏情况运行时间?
我编写这个函数是为了反转双向链表的顺序。
public void reverse() {
Node<T> temp = head;
Node<T> current = head.next;
head.next = null;
head.previous = current;
while(current != null)
{
Node<T> next = current.next;
current.next = temp;
current.previous= next;
temp = current;
current = next;
}
head = tail;
}
最佳答案
查找嵌套循环的数量。
由于没有,所以它只是 O(n),因为在循环过程中 n
没有几何减少
关于java - 如何找到这个Java程序的Big-O复杂度和最坏情况运行时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54338187/