TYPES OF LINKED LIST IN DATA STRUCTURES
Introduction
● Today we are starting Linked List very important topic for interviews being asked
quite a lot. Also Trees, Hash Maps, and Heaps are important, but linked list and
trees are like the most important ones.
● Linked list is very popular and is used in Trees as well. In this Document, we'll
learn about linked list, what is it, how we do it, and how to create one on our own.
● The second Document will be interview questions Document, and we'll solve
questions from the lead code and the previous year. We'll look into the approach
to solve a problem, what type of questions are asked in linked list, and how to
know which particular question to solve in which particular way.
● In this Document, I'm going to cover recursion with linked list, applying merge
sort and bubble sorting link list, and iterations.
Limitations of Array/ArrayList
● In Java, arrays are not continuous memory allocations. If an array gets full, you
cannot really add new items in that make sense, so you can use Rlist to solve
this problem.
● If you have an array with five items and you want to insert a sixth item, you will
double the array.
● It will copy all of these, then add a new item over here. It's not really cool, but it's
efficient.
Working of LinkedList
● Link list is a data structure that does not use continuous memory allocation, but
instead uses a random memory allocation for each item. The items are
connected via arrows.
, ● A linked list is a collection of items that can be found in different places in
memory and are connected with each other using a pointer. The pointer is not
the C Plus pointer, it's something else.
Singly LinkedList
● A linked list is a graph where every item knows about the next item.
● In linked list, a reference variable called head points to the very first node, and a
reference variable called tail points to the last node. Each box in the list has its
own type, and each box has its own value.
● Okay, the next pointer is to another node of type, which is pointing to another
object of type, which is pointing to another object of type.
● Every single object in a linked list is represented by an arrow that points to a
node type. The problem with linked lists is that you cannot directly access the
index, and the list only ends when you reach the last node.
● If you want to go to the third node, create a temporary node, point it to head, and
run the for loop three times. This is a very simple linked list, just a class node,
that has two things. It's important to know how to work with just the head in the
linked list, because tail value makes it easier for us.
● If tail was not provided, you would have to first find the last element, traverse till
the end, then just add on to it. This would take o of n time obviously.
● In the implementation part, I'll definitely teach you with the tail because it's one
more variable or whatever, and the theory part is almost same. We'll do insertion,
deletion, traversal, and questions as well, so let's get started.
● We are having a node class, so we can just create a linked list, and we can use
the internal link list as well. We want to actually see how this add function is
working and all these other things, so we will create a custom link list. Okay, so
I'll make a private class node that has int value and node next. I don't want
anyone to access these things directly.
Introduction
● Today we are starting Linked List very important topic for interviews being asked
quite a lot. Also Trees, Hash Maps, and Heaps are important, but linked list and
trees are like the most important ones.
● Linked list is very popular and is used in Trees as well. In this Document, we'll
learn about linked list, what is it, how we do it, and how to create one on our own.
● The second Document will be interview questions Document, and we'll solve
questions from the lead code and the previous year. We'll look into the approach
to solve a problem, what type of questions are asked in linked list, and how to
know which particular question to solve in which particular way.
● In this Document, I'm going to cover recursion with linked list, applying merge
sort and bubble sorting link list, and iterations.
Limitations of Array/ArrayList
● In Java, arrays are not continuous memory allocations. If an array gets full, you
cannot really add new items in that make sense, so you can use Rlist to solve
this problem.
● If you have an array with five items and you want to insert a sixth item, you will
double the array.
● It will copy all of these, then add a new item over here. It's not really cool, but it's
efficient.
Working of LinkedList
● Link list is a data structure that does not use continuous memory allocation, but
instead uses a random memory allocation for each item. The items are
connected via arrows.
, ● A linked list is a collection of items that can be found in different places in
memory and are connected with each other using a pointer. The pointer is not
the C Plus pointer, it's something else.
Singly LinkedList
● A linked list is a graph where every item knows about the next item.
● In linked list, a reference variable called head points to the very first node, and a
reference variable called tail points to the last node. Each box in the list has its
own type, and each box has its own value.
● Okay, the next pointer is to another node of type, which is pointing to another
object of type, which is pointing to another object of type.
● Every single object in a linked list is represented by an arrow that points to a
node type. The problem with linked lists is that you cannot directly access the
index, and the list only ends when you reach the last node.
● If you want to go to the third node, create a temporary node, point it to head, and
run the for loop three times. This is a very simple linked list, just a class node,
that has two things. It's important to know how to work with just the head in the
linked list, because tail value makes it easier for us.
● If tail was not provided, you would have to first find the last element, traverse till
the end, then just add on to it. This would take o of n time obviously.
● In the implementation part, I'll definitely teach you with the tail because it's one
more variable or whatever, and the theory part is almost same. We'll do insertion,
deletion, traversal, and questions as well, so let's get started.
● We are having a node class, so we can just create a linked list, and we can use
the internal link list as well. We want to actually see how this add function is
working and all these other things, so we will create a custom link list. Okay, so
I'll make a private class node that has int value and node next. I don't want
anyone to access these things directly.