0% found this document useful (0 votes)
70 views4 pages

Linked List Lecture Note

Linked lists are a data structure where each element contains both data and a pointer to the next element. This allows elements to be dynamically inserted and deleted without rearranging the entire structure. The key advantages of linked lists over sequential arrays are flexibility of size, faster insertion and deletion in the middle of the list, and less data movement when modifying elements. Linked lists use more memory than arrays due to storing pointers between elements but allow efficient random access of elements.

Uploaded by

Melat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views4 pages

Linked List Lecture Note

Linked lists are a data structure where each element contains both data and a pointer to the next element. This allows elements to be dynamically inserted and deleted without rearranging the entire structure. The key advantages of linked lists over sequential arrays are flexibility of size, faster insertion and deletion in the middle of the list, and less data movement when modifying elements. Linked lists use more memory than arrays due to storing pointers between elements but allow efficient random access of elements.

Uploaded by

Melat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Linked list

In sequential representation of a data structure, the items are implicitly ordered by the sequential
order of storage. Thus, if items[x] represent an element in a data structure the next item in the data
structure will be items[x+1]. Since the storage structure of the data structure helps to know the
address of a particular item within the data structure there is no need to worry about the address of
the item in the data structure. Suppose that the items of the data structure are explicitly ordered,
that means, each item contains within itself the address of the next item. Such explicit ordering
gives rise to a new data structure known as Linked List. And the resulting representation is called
Linked List Representation.
Definition
A Linked List is a collection of elements called nodes. Each node contains a data portion and a
pointer that contains the location of (points to) the node that logically follows this node. The entire
list is referenced by a separate pointer to the first element of the list.

head …

Data Pointer
Portion part

Node

Linked list can also be represented in the following way. Where start is a pointer to the first node
of the list and the pointer part of the first node points to the second node. The pointer part of the
last node points to NULL.

Data Structure, Unity University Page 1|4


Differences between Sequential and Linked List Representations

In sequential representation of lists one major problem is limitation in size. The most important
advantage of linked lists in dynamic storage is flexibility. Overflow is no problem until the
computer memory is exhausted. The other important advantage of linked lists is that insertions and
deletions can be made in the middle of the linked list more quickly than in the middle of a
contiguous list. If the records are large it is much quicker to change the values of a few pointers
than to copy the records themselves from one location to another. If the data items are arranged in
some type of order and it becomes necessary to insert into or delete from the middle of the list, a
considerable amount of data movement is involved in the case of contiguous lists. This data
movement requires computer time and decreases program efficiency. The central motivation
behind the linked list data structure is to eliminate the data movement associated with insertion
into and deletions from the middle of the list.

The first drawback of Linked Lists is the links (pointers) themselves take space. However, the
space used for a list node is not usually twice the space used by an array element, since the elements
in such a list usually consists of structures with many sub-fields. The other disadvantage of
linked lists is that they are not suited to random access. With sequential storage, the program can
refer to any position within the list as quickly as to any other position. With a linked list, it may be
necessary to traverse a long path to reach the desired node.

The following table compares arrays and Linked Lists


Linked List Array
Not limited Limited
Insertion is on O(1) Insertion is on O(n)
Deletion is on O(1) Deletion is on O(n)
Traversal O(n/) Traversal O(n) (n/ > n )
Search O(n) Search -sequential O(n)
-binary O(log2n)

Sequential representation is preferable under the following conditions

- when the records are individually very small

Data Structure, Unity University Page 2|4


- when the size of the list is known when the program is written
- when few insertions and deletions need to be made except at the end of the list
- when random access is important

Linked List representation is preferable under the following conditions

- when the records are large


- when the size of the list is not known in advance
- when flexibility is needed in inserting, deleting and rearranging the entries

Basic Operations on Linked Lists

Operation Explanation
Initializes an empty linked list
1. create_list(head)
referenced by head
Checks whether the linked list
referenced by head is empty or not;
2. is_empty(head)
does it contain
any active node?
Checks whether the linked
list referenced by head is full; for
3. is_full(head)
array
implementation of a linked list
Inserts the node pointed by p into the
4. insert_node(head,p)
linked list referenced by head
Deletes the node pointed by p from
5. delete_node(head,p)
the linked list referenced by head
Searches the linked list referenced by
6. search_node(head,target) head for the node whose data field
matches a specified target value

Data Structure, Unity University Page 3|4


Array Implementation of Linked Lists
Since a Linked List is simply a collection of nodes, an array of nodes can be used to implement it.
However, the nodes can not be ordered by the array ordering; each must contain within itself a
pointer to its successor.
A Linked List of integers is declared as an array of nodes as follows:

//Global declaration

#include<iostream.h>
#include<stdlib.h>
#define MAX 100
#define null -1
struct node
{
[data type] data; //eg. int data, stores the data part of the node
int next; //next stores the address of the next node.
};

Data Structure, Unity University Page 4|4

You might also like