Time complexity 初始化数组和链表的代码段的Big-O表示法

Time complexity 初始化数组和链表的代码段的Big-O表示法,time-complexity,Time Complexity,我正试图对跑步时间有更多的了解 假设我的函数中有代码,每个语句都有一些不同的时间复杂性: LinkedList myLL = new LinkedList(); //O(1) myLL.addAtHead("1"); //O(1) myLL.addAtHead("2"); //O(1) myLL.addAtHead("3"); //O(1) int[] myArray = new int[n] //O(n) , depending on what n is <Some other st

我正试图对跑步时间有更多的了解

假设我的函数中有代码,每个语句都有一些不同的时间复杂性:

LinkedList myLL = new LinkedList(); //O(1)

myLL.addAtHead("1"); //O(1)
myLL.addAtHead("2"); //O(1)
myLL.addAtHead("3"); //O(1)

int[] myArray = new int[n] //O(n) , depending on what n is
<Some other statement> //O(n^2)
LinkedList myLL=new LinkedList()//O(1)
myLL.addathad(“1”)//O(1)
myLL.addathad(“2”)//O(1)
myLL.addathad(“3”)//O(1)
int[]myArray=new int[n]//O(n),具体取决于n是什么
//O(n^2)

确定运行时间是否为O(n^2)?我们是否只考虑花费最多时间的语句,并表示总运行时间为O(n ^ 2)?< /P> < P>是的,普遍的术语取消了所有其他的(好的,这使得它们在整体考虑中是微不足道的),因此,复杂性是O(n ^ 2)。