0
Time Complexity
I get confused when it comes to this, but would the time complexity for this method be O(1)? public void push(T target) { //TODO // throw new UnsupportedOperationException("Not supported yet.") SinglyLinkedNode<T> temp = new SinglyLinkedNode<T>(target); temp.setNext(head); head = temp; size++; }
1 ответ
0
Yes. Creating a new node is O(1), .setNext is O(1), assigning temp to head is O(1).
You are not looping or recursing anywhere here so the code is O(1).