In: Computer Science
In Java, What is gained by having a Tail reference/pointer in your Linked List?
A. The tail is superfluous and offers no benefits
B. The tail allows us to speed up a few operations and gives us an end point to look for
C.Since we have head and tail we can now do a Binary Search on the list
D. It only makes deleting from the end of the list faster
In Java, having a tail reference/pointer in the Linked List allows us to speed up a few operations and gives us an end point to for.
Having a tail reference can speed up the insertion at the end of the linked list operation.
Without tail, in order to insert an element at the end of the linked list, we have to traverse the entire linked list to get the node at the end of the linked list. This operation requires a time complexity of O(N) where N is the number of nodes in the linked list.
With tail, in order to insert an element at the end of the linked list, we can directly insert it at the end of the tail and make this new node the tail of the linked list. This operation requires a time complexity of O(1) i.e constant time.