LinkedList is a part of the Java Collections Framework and is present in the java.util package. It implements a doubly linked list where elements are stored as nodes containing data and references to the previous and next nodes, rather than in contiguous memory locations.
- The size of the LinkedList can grow or shrink dynamically at runtime.
- Maintains the order in which elements are inserted.
- Multiple duplicate elements can be stored.
- LinkedList is not thread-safe by default; it can be synchronized using Collections.synchronizedList().
- Provides better performance than ArrayList for insertion and deletion operations, especially at the beginning or middle.
what is Singly Linked List ?
- Each node holds a single value and a reference to the next node in the list.
- The list has a head, which is a reference to the first node in the list. We can access all items of a list using the head node. Sometimes we also separately maintain tail of linked list to quickly access the last node. For example, in queue implementation of the linked list, we prefer to quickly insert at the end.
- The nodes are not stored in a contiguous block of memory, but instead, each node holds the address of the next node in the list.
what is doubly linked list ?
- A doubly linked list is a more complex data structure than a singly linked list, but it offers several advantages.
- The main advantage of a doubly linked list is that it allows for efficient traversal of the list in both directions. This is because each node in the list contains a pointer to the previous node and a pointer to the next node.
- This allows for quick and easy insertion and deletion of nodes from the list, as well as efficient traversal of the list in both directions.
what is Circular Linked List ?
A circular linked list is a data structure where the last node points back to the first node, forming a closed loop.
- Structure: All nodes are connected in a circle, enabling continuous traversal without encountering NULL.
- Difference from Regular Linked List: In a regular linked list, the last node points to NULL, whereas in a circular linked list, it points to the first node.
- Uses: Ideal for tasks like scheduling and managing playlists, where smooth and repeated.
Linked List vs Array
| Feature | Array | Linked List |
|---|---|---|
| Memory | Contiguous | Non-contiguous |
| Size | Fixed | Dynamic |
| Access | Fast (index) | Slow (traversal) |
| Insertion | Slow | Fast |



Top comments (0)