BSCS_CS213
BSCS_CS213
G1 BSCS-2CSE CS-213
What is a Linked list?
◦A data structure called a linked list uses a chain to hold data.
Every piece of data in a linked list is connected to every other
piece of data (and perhaps to the data before it as well)
because of the way the list is structured. A node is any
element in a linked list. Imagine it as a real chain, with each
ring or node connected to the next. Something along these
lines.
ADVANTAGES
- Dynamics: Think of a linked list as a chain of connected boxes. Each box
contains an element and a pointer to the next box. When a customer adds an
item, you simply add a new box to the chain. If it deletes an item, you delete
the corresponding box. This dynamic nature allows linked lists to grow or
shrink as needed, unlike fixed-size arrays.
- Efficient: Because you only allocate memory for the boxes you need, you
avoid wasting space like you would with an array that requires space for a
maximum number of elements. This makes linked lists memory efficient,
especially when dealing with unpredictable data sizes.
- Easy redraft: Adding a new item to a shopping cart (inserting into a linked
list) is as simple as creating a new box, linking it to the previous box, and
updating the pointer. Deleting an item is just as easy.
- Versatile: Linked lists are the building blocks of more complex data
structures. Stacks (think of a stack of disks) and queues (like a queue in
a store) are both implemented using linked lists. Trees and graphs used
to represent relationships between data are also based on linked lists.
- Scalability: Adding a new element to the end of a linked list is a
constant-time operation, meaning it takes the same amount of time
regardless of the number of elements already in the list. This makes
linked lists scalable to handle large amounts of data.
DISADVANTAGES
- Memory cost: Each instance in a linked list requires additional memory for the pointer
to the next instance. This can be a disadvantage if you are working with limited memory.
- Limited random access: Imagine you want to find the 5th item in a shopping cart.
With a linked list, you have to start from the beginning and follow the pointers until you
get to the 5th item. This is called linear search and can be slow, especially for large lists.
- Search Complexity: Searching for a particular element in a linked list can be time
consuming, especially if the element is near the end of the list. In fact, you have to
traverse the entire list until you find the element.
- Backward Traversal: Navigating a linked list in reverse order (from the last element to
the first element) is inefficient and cannot be done in a singly linked list. You need to
store additional information about the previous element to achieve this.
Four types of linked lists:
◦Charline T. Santos
REFERENCES
◦https://www.freecodecamp.org/news/introduction-to-linked-lists-in-pytho
n/
◦https://www.geeksforgeeks.org/introduction-to-linked-list-data-structure/
◦https://www.simplilearn.com/tutorials/data-structure-tutorial/types-of-link
ed-list