Introduction to Linkedlist

Introduction to Linkedlist

Ram has completed his learning and practice in array data structure, He understood all the pros and cons of arrays, Now he wanted to learn LinkedLists which is a dynamic data structure. While he was wondering why this new data structure was invented in the first place.

No alt text provided for this image
What are Linked lists

Ram continued doing some other programming problems, while solving various problems Ram encountered some situations where he was not sure how much array space to be declared prior. Ram was in a dilemma what If I declare more space but the code can use significantly less, or declare less space for an array but the code takes more space?

No alt text provided for this image
What to do, I can't resize array in runtime


Ram understood arrays were not just sufficient and he need to learn another data structure to solve the remaining questions. While ram thinking regarding this, he listed out all the different problems he’s facing while using arrays ….

  • Ram has to know the size of the total data beforehand to declare an array and use it.
  • Ram understood that this array can’t shrink or expand at will.
  • If he wants to delete any data in between, he needs to shift all the right-side elements of the deleted block to the left to maintain the array function of contiguous memory.
  • He also thought what if he wants more contiguous memory and the sequence memory is not available? ?

After thinking of various other issues he’s facing while using arrays, Ram got fed up and opened the book to see what are these linked lists.

No alt text provided for this image
A typical Linked List


To his surprise, Ram is reading all the solutions for the issues with arrays, as he started to learn, He understood that just like any long object is divided and stored at home like if any long vegetable is unable to fit in the refrigerator, his mom just cuts and stores at two parts. Similarly when we wanted to declare a long space of similar datatypes and not sure of memory, this LinkedList helps a lot.


Every data block of the linked list is called a Node which is divided into 2 parts consisting of data and the address of the following Node. And the best thing about this data structure is that you can add any number of nodes at any point at his will and he can remove any number of nodes without the tension of shifting numbers, all these happen with the game of addresses.

No alt text provided for this image
A Node in Linked List


Ram, understood the theory of what a linked list is, but he knows that there is a user-defined datatype he learned namely struct and class, So he can take any datatype which has two variables data of integer type and address of another structure or class.

No alt text provided for this image
Node using structure, which has data & address of next node


Ram understood that this data structure is like a connected cycle chain where he has the address of the head only, the remaining blocks are stored somewhere in the memory and he can only access the next block with the address he’s holding in the current block.

No alt text provided for this image
Broken chain

?The linked list is like the above cycle chain, you can just open the link between any two chain pieces and you can change the piece, add more pieces to increase the length, or remove more pieces to decrease the length.

Learn more about linked lists from below link

Happy Learning and Happy Coding, If you find this article helpful please do like, share, and comment your views.


要查看或添加评论,请登录

Putta Hemanth Kumar的更多文章

  • Merge Sort Technique

    Merge Sort Technique

    Ram is determined to conquer the formidable Merge Sort, a sorting algorithm that had always been a bit of a puzzle for…

  • Binary Search Algorithm

    Binary Search Algorithm

    Ram, who is passionate about coding had managed to learn all the fancy data structures, much to the amazement of his…

    2 条评论
  • Introduction to Stacks

    Introduction to Stacks

    Ram, had recently completed his studies on arrays and linked lists, and now he was ready to embark on a new data…

  • Introduction to Array Datastructure

    Introduction to Array Datastructure

    Ram understands very well that in order to tackle any programming challenge, he must learn about data structures and…

  • A brief Introduction to DSA

    A brief Introduction to DSA

    Ram, who is knowledgeable about various programming datatypes and functions, wanted to learn more about data structures…

  • Introduction to Functions

    Introduction to Functions

    Ram, has learned and experienced what are primitive datatypes and what are user defined datatypes. Now he tries to…

  • Introduction to Structures and Classes

    Introduction to Structures and Classes

    Ram, now has a good clarity on Primitive Datatypes, now he’s learning User defined datatypes. While doing so he…

  • Introduction to Primary Data Types

    Introduction to Primary Data Types

    Ram, a curious student who wants to learn DSA and started with primary datatypes. Ram is confused after looking at…

    3 条评论

社区洞察

其他会员也浏览了