Building Linked Lists With C Your Path To Data Structures
Building Linked Lists With C Your Path To Data Structures
• Unlike arrays, linked list elements are not stored at a contiguous locationA.
• linked list is a way to store data where each piece of data is connected to the next one.
• We use it because it's flexible in size, allows for efficient insertions and deletions, and is
memory-efficient.
WHY LINKED LIST ?
Use an Array when:
• You need to access elements quickly and directly by their index.
• Your data structure has a fixed size, and you don't need it to change dynamically.
• Memory efficiency is crucial, especially for smaller data structures with predictable memory allocation.
• Efficient insertions and deletions, particularly in the middle of the structure, are important.
• You aim to minimize memory waste, particularly for sparse data structures.
• You require a versatile foundation for building more complex data structures.
REPRESENTATION
In computer science, a linked list is a linear collection of data elements whose order is not given by their
physical placement in memory. Instead, each element points to the next. It is a data structure consisting
A linked list is represented by a pointer to the first node of the linked list. The first node is called the
head. If the linked list is empty, then the value of the head is NULL. Each node in a list consists of at
least two parts: 1) data 2) Pointer (Or Reference) to the next node
TYPES OF LINKED LIST
• Circular Linked List − Last item contains link of the first element as next and the
1. Start at the head node and traverse the list while keeping track of the current node and the previous node.
2. Check each node's data as you traverse to identify the node to delete.
3. Once you find the node to delete, update the "next" pointer of the previous node to skip the node to be deleted.
4. The node to be deleted can be removed from memory (deallocated), if needed, depending on the programming
language.
DELETION:
EASY TO CHANGE SIZE: YOU CAN EASILY MAKE THEM BIGGER OR SMALLER AS NEEDED,
UNLIKE ARRAYS, WHICH HAVE A FIXED SIZE.
INSERTIONS AND DELETIONS: ADDING OR REMOVING ITEMS IS OFTEN FASTER AND EASIER
THAN WITH ARRAYS, ESPECIALLY IN THE MIDDLE.
LESS WASTED SPACE: THEY DON'T WASTE MEMORY WHEN ITEMS ARE REMOVED OR THE LIST
CHANGES SIZE.
DISADVANTAGES OF LINKED LISTS
HARD TO FIND THINGS: IT'S SLOWER TO FIND AN ITEM IN A LINKED LIST COMPARED TO AN
ARRAY BECAUSE YOU HAVE TO START AT THE BEGINNING AND LOOK THROUGH EACH ITEM
ONE BY ONE.
EXTRA MEMORY USED: THEY USE EXTRA MEMORY TO STORE THE CONNECTIONS BETWEEN
ITEMS, WHEREAS ARRAYS STORE ONLY THE DATA.
NOT GOOD FOR QUICK ACCESS: IF YOU NEED TO QUICKLY ACCESS ITEMS IN A SPECIFIC ORDER,
LINKED LISTS MIGHT NOT BE THE BEST CHOICE BECAUSE THEY'RE NOT GOOD FOR JUMPING
AROUND TO DIFFERENT ITEMS.
CAN BE MORE COMPLICATED: THEY CAN BE MORE COMPLICATED TO WORK WITH AND
UNDERSTAND COMPARED TO ARRAYS.
THANK YOU