6. With respect to linked lists, establish the relationship between the size of the list and the time it takes to perform an insertion at the beginning of the list. Provide empirical evidence to support your answer.
It takes O(1) to insert at the beginning of the list
public void addFront(int n){
Node newNode= new Node(n);
newNode.next=head;
head=newNode;
}
if you see the above code we just changing the links between the newNode and head which will insert the node at the beginning..Here we are not using any loops or recursion for iteration so it just O(1)
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME
Get Answers For Free
Most questions answered within 1 hours.