LinkedList<Integer> lst = ...; int sum = 0; for (int i = 0; i < lst.size(); i++ ) sum += lst.get(i);
What is the Big O of this code?
Answer: D
Because LinkedList requires stepping down the list to find the requested element, the .get(i) operation is O(i). Since i is growing within the loop, this sets up a Bermuda Triangle situation, giving a time of O(n2).