You are viewing a single comment's thread. Return to all comments →
What is the Big O notation for this code? Does creating a pointer to the head of the list actually copy it all over again one by one? if not, is it constant time?
O(1) aka Constant time
You are not copying anything other than the pointer to the head node into the newly created node. Linked lists are not like arrays in that you don't have to copy elements to insert/delete elements.