Unit-2 2
Unit-2 2
It is a compact way of collecting data types where all entries must be of the same data
type.
It is a collection of elements of same datatype referred by a single name.
All the elements of linear list are stored in sequential/contiguous memory locations
which allow faster/direct access to any element through index.
The principle of the list is, “Insertion at anywhere and Deletion from anywhere”
Insertion Operation:
First Verify, whether the list is full or not. If the list is full, then insertion not possible.
Otherwise, get the position at which the element to be inserted
If the position is valid, Shift the array elements from that position till the end to one
position forward(towards right)
Insert the element at the given position as this is now empty.
Increase the no. of elements by one.
Deletion Operation:
First Verify, whether the list is empty or not. If the list is empty, then deletion not
possible.
Otherwise, get the position at which the element to be deleted
If the position is valid, Delete(print) the element at the given position.
Shift the array elements from next to that position till the end to one position
backward(towards left)
Decrease the no. of elements by one.
Display (Traversal) Operation:
First Verify, whether the list is empty or not. If the list is empty, then there are no
elements to display.
Otherwise, Print all the elements from firsat element to last element i.e. 0 to n-1.
Linked Lists:
To avoid the disadvantages of linear list( Size of list fixed, time consuming process of
insertion, deletion) the concept of Linked Lists is used.
In Linked list, each element is called a node. So, linked list consists set of node in which each
node contains a field called a link( a pointer) which consists the address of the next element
in the list. Thus successive elements in the list need not occupy adjacent space in memory.
There are three types of linked lists. They are,
Singly Linked List (SLL)
Doubly Linked List (DLL)
Circular Linked List
Singly Linked List:
A singly linked list is a collection of nodes in which every node consists of two parts: one
part contains the data (value) of the element and the other part consists the address of the next
node . The address part of the last node consists a value called the ‘NULL’ and the address of
the starting node is stored in a pointer called “head”.
Singly linked list is represented as,
Ex:
A Doubly linked list is a collection of nodes in which every node consists of three parts: one
is data part and two are address parts, data part contains the data (value) of the element, one
address part consists the address of the next node and the other address part consists the
address of previous node. The next address part of the last node and previous address part of
the first node consists a value called the ‘NULL’ and the address of the starting node is stored
in a pointer called “head”.
Doubly linked list is represented as,
Ex:
A circular linked list is a type of linked list in which the first and the last nodes are also
connected to each other to form a circle.
There are basically two types of circular linked list:
All the data elements are stored in a All the nodes are stored in random memory
contiguous memory locations. locations.
The memory is allocated at compile time. The memory is allocated at run time.
Direct accessing of elements is possible i.e. Sequential accessing of elements only possible
It is easier and faster to access the element i.e. In a linked list, the process of accessing
in an array. elements takes more time.