Linked list is one of the simplest but most popular datastructures, perhaps because good linked list problems can be solved within 15-20 minutes. Linked list problems are interesting, fun, thought provoking, and easy to describe, which is why they are very common in a programming interview. Microsoft loves asking linked list questions, I mean, you WILL get at least one linked list question if you ever interview with Microsoft!
Wikipedia defines, “a linked list is a data structure consisting of a group of nodes that together represent a sequence”. So, a typical linked list node will have a reference to the next node and a data field. This is called a singly linked list. Therefore, the first node (commonly known as the head) can represent the entire linked list, since one can traverse all the nodes from head by using the next reference. The Java code for the traversal of a linked list is below: Continue reading