Dynamic Storing of Elements through Linked Lists

in #honouree8 months ago

One more way to store elements of data is through linked lists. Linked lists are linear data structures that consist of nodes. The nodes in these linked lists have elements and references to the next node. Using linked lists provides a dynamic way of storing and organizing elements. Therefore, it also provides efficient insertion, deletion, and traversal. Linked lists will grow or shrink dynamically once elements are inserted or removed.

There are two types of linked lists. The first type is the "singly linked list." In the singly link list, each node has data and a link or reference to the next node. The first node is called the head, while the next reference in the last node in the linked list will be set to null.

download.png

The second type of linked lists is the "doubly linked list." In the doubly linked list, each node has data and a link or reference to the previous and next node, which allows traversal in both directions. Using the head node as the basis, its reference to the previous node will be set to null. The next reference in the last node in the linked list will also be set to null.

DLL1.png

In order to manipulate and use the elements within the linked lists, there are operations that can be used. There are three main operations that can be used in the linked list. The first operation is insertion. In insertion, it inserts a node into a linked list. The nodes can be inserted anywhere with the data structure while making sure of the connectivity of the nodes with each other. The second operation is deletion. In deletion, it deletes or removes a node from the linked list. The same goes for deletion. It is also important to maintain the connection of the relationship between the nodes by adjusting the reference if necessary. The third operation is searching. In searching, it is traversing along the linked list to find the node that the programmer wants to use. As it is traversing in the list, it compares each value of data in each node until a match is found based on the criteria that the programmer created. This operation is efficient in the retrieval of elements.

Let us focus on the traversing and manipulation of linked lists. Traversing through linked lists means that every node will be looked at to perform an operation. It will be based on the references that one node has for the next until it reaches the end of the list. The most common operations used in the traversal of data are printing the data, doing calculations, or modifying the nodes themselves.

There are ways to implement linked lists and their several use cases. Linked lists can be used to store and manipulate data that need to be resized dynamically. Linked lists can also be used to implement stacks and queues, build hash tables and hash maps, represent polynomials (mathematics), and handle large datasets whose memory allocations are uncertain. Using linked lists is efficient for insertion and deletion of elements, but random access is not that efficient in comparison to arrays.

There is a certain variation of linked lists called circular linked lists. In the circular linked list, the lists form a loop wherein the last node in the linked list will be linked or referred back to the head node. This means that there will be no null at the beginning (for doubly linked list) and end of the list. Circular linked lists can be singly or doubly linked lists. This variation of the linked list efficiently traverses to any node that requires looping in the algorithms.

Overall, linked lists, with their storing and organizing of data dynamically, offer flexibility and efficiency. As they grow and shrink based on the insertion and removal of elements, they can be used to build scalable programs.

Posted using Honouree

Sort:  

Congratulations @beatricearapoc! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 10 upvotes.
Your next target is to reach 50 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

LEO Power Up Day - October 15, 2023

There is reasonable evidence that this article is machine-generated. Posting such content is considered fraud. Fraud is discouraged by the community and may result in the account being Blacklisted.
Guide: AI-Generated Content = Not Original Content

If you believe this comment is in error, please contact us in #appeals in Discord.