0% found this document useful (0 votes)
211 views7 pages

Introduction to Linked Lists and Types

The document discusses linked lists, which are dynamic data structures composed of nodes that point to the next node in the sequence. There are three main types: singly linked lists where each node has a data field and pointer to the next node; doubly linked lists where each node has pointers to both the next and previous nodes; and circular linked lists where the last node points back to the first node, forming a circular chain. Common applications of linked lists include implementing stacks, queues, graphs and allowing dynamic memory allocation during runtime.

Uploaded by

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

Introduction to Linked Lists and Types

The document discusses linked lists, which are dynamic data structures composed of nodes that point to the next node in the sequence. There are three main types: singly linked lists where each node has a data field and pointer to the next node; doubly linked lists where each node has pointers to both the next and previous nodes; and circular linked lists where the last node points back to the first node, forming a circular chain. Common applications of linked lists include implementing stacks, queues, graphs and allowing dynamic memory allocation during runtime.

Uploaded by

Ubaid Altaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Introduction to Linked Lists

Linked List is a very commonly used linear data structure which


consists of group of nodes in a sequence.

Each node holds its own data and the address of the next


node hence forming a chain like structure.

Linked Lists are used to create trees and graphs.

Advantages of Linked Lists

 They are a dynamic in nature which allocates the memory when


required.

 Insertion and deletion operations can be easily implemented.

 Stacks and queues can be easily executed.

 Linked List reduces the access time.

Disadvantages of Linked Lists


 The memory is wasted as pointers require extra memory for
storage.

 No element can be accessed randomly; it has to access each


node sequentially.

 Reverse Traversing is difficult in linked list.

Applications of Linked Lists

 Linked lists are used to implement stacks, queues, graphs, etc.

 Linked lists let you insert elements at the beginning and end of
the list.

 In Linked Lists we don't need to know the size in advance.

Types of Linked Lists

There are 3 different implementations of Linked List available, they are:

1. Singly Linked List

2. Doubly Linked List

3. Circular Linked List

Let's know more about them and how they are different from each
other.
Singly Linked List

Singly linked lists contain nodes which have a data part as well as


an address part i.e. next, which points to the next node in the
sequence of nodes.

The operations we can perform on singly linked lists


are insertion, deletion and traversal.

Doubly Linked List

In a doubly linked list, each node contains a data part and two


addresses, one for the previous node and one for the next node.
Circular Linked List
Circular Linked List is little more complicated linked data structure. In
the circular linked list we can insert elements anywhere in the list
whereas in the array we cannot insert element anywhere in the list
because it is in the contiguous memory. In the circular linked list the
previous element stores the address of the next element and the last
element stores the address of the starting element. The elements
points to each other in a circular way which forms a circular chain. The
circular linked list has a dynamic size which means the memory can be
allocated when it is required.

Application of Circular Linked List

 The real life application where the circular linked list is used is
our Personal Computers, where multiple applications are
running. All the running applications are kept in a circular linked
list and the OS gives a fixed time slot to all for running. The
Operating System keeps on iterating over the linked list until all
the applications are completed.

 Another example can be Multiplayer games. All the Players are


kept in a Circular Linked List and the pointer keeps on moving
forward as a player's chance ends.

 Circular Linked List can also be used to create Circular Queue. In


a Queue we have to keep two pointers, FRONT and REAR in
memory all the time, where as in Circular Linked List, only one
pointer is required.

Implementing Circular Linked List

Implementing a circular linked list is very easy and almost similar to


linear linked list implementation, with the only difference being that, in
circular linked list the last Node will have it's next point to
the Head of the List. In Linear linked list the last Node simply holds
NULL in it's next pointer.

So this will be oue Node class, as we have already studied in the


lesson, it will be used to form the List.

class Node {

public:

int data;

//pointer to the next node

node* next;

node() {

data = 0;

next = NULL;
}

node(int x) {

data = x;

next = NULL;

Copy

Circular Linked List

Circular Linked List class will be almost same as the Linked List class
that we studied in the previous lesson, with a few difference in the
implementation of class methods.

class CircularLinkedList {

public:

node *head;

//declaring the functions


//function to add Node at front

int addAtFront(node *n);

//function to check whether Linked list is empty

int isEmpty();

//function to add Node at the End of list

int addAtEnd(node *n);

//function to search a value

node* search(int k);

//function to delete any Node

node* deleteNode(int x);

CircularLinkedList() {

head = NULL;

Common questions

Powered by AI

Circular linked lists facilitate the management of running applications in a system by allowing the efficient cycling through active processes. Each active process or application is represented as a node in the circular list, enabling the operating system to allot fixed time slots to each application seamlessly. This dynamic scheduling improves resource utilization and performance consistency, as the operating system iterates through the circular linked list, minimizing the need for handling empty slots typically found in linear data structures . Moreover, it requires only a single pointer to traverse, reducing memory complexity compared to keeping separate beginning and end pointers .

The primary difference in implementing a circular linked list as opposed to a linear linked list is that the last node's pointer does not point to NULL but instead points back to the first node, creating a circular structure . This setup allows for constant time complexity O(1) for operations that effectively require wrapping around, such as cycling through running applications or game players. It offers more efficient memory utilization and increased flexibility for operations that need cyclical treatments, such as in operating systems or multiplayer games .

Circular linked lists are particularly beneficial in scenarios where cyclic navigation is needed, such as round-robin scheduling used in operating systems or continuous player rotations in multiplayer games . These scenarios benefit from the circular list’s ability to return to the beginning seamlessly without the need to reset pointers or manage additional end-of-list markers . While doubly linked lists facilitate bi-directional traversal, circular linked lists provide simpler architecture for repetitive, cyclic processes where backward traversal isn't necessary, thereby saving some memory space and simplifying implementation by only requiring one active traversal pointer .

Circular linked lists are highly suitable for real-time systems and gaming due to their efficient cyclical properties, which are ideal for round-robin scheduling and managing turn-based activities. In real-time systems, such as operating systems managing multiple concurrent applications, circular linked lists enable seamless rotation among tasks, evenly distributing processor time across tasks without manual reset or iteration break points . In gaming, circular lists allow for easy management of player turns, automatically progressing from one player to the next and looping back to the first seamlessly, which eliminates manual tracking of player order and managing end-of-turn events . These applications benefit significantly from the single-pointer navigation efficiency and elimination of arbitrary endpoint management found in linear structures .

A circular linked list enhances the implementation of a circular queue by maintaining a continuous loop of elements where the last node links back to the first, allowing queue operations to proceed without needing to distinguish between the beginning and end as separate entities. This contrasts with a linear queue, which requires explicit management of both front and rear pointers to orchestrate queue operations effectively . In a circular linked list, operations like enqueue and dequeue are simplified due to the inherent looping nature, minimal pointer adjustment, and single pointer navigation, ensuring consistency and decreasing complexity in cyclic processing tasks .

Traversing linked lists sequentially can be time-consuming because linked lists do not allow for direct access to elements; each node must be accessed consecutively starting from the head, making operations like searching inefficient . Reverse traversal in singly linked lists is particularly challenging since these lists do not maintain a reference to previous nodes, necessitating additional data structures or traversal from the beginning to achieve backward movement. Doubly linked lists mitigate some of these issues by maintaining pointers to both the next and previous nodes, thereby simplifying reverse traversal . Circular linked lists further offer traversal advantages by naturally looping back to the start, facilitating repetition without needing to reset pointers manually .

The requirement for extra memory to store pointers in linked lists contributes to overhead, particularly noticeable in environments with constrained memory resources. While linked lists provide dynamic memory allocation and facilitate efficient insertion and deletion operations, each node uses additional memory to store the pointer (or pointers in case of doubly linked lists) necessary for linking nodes together . This tradeoff affects performance by decreasing available memory for data storage, potentially increasing cache misses due to non-contiguous memory allocation, and making random access inefficient as elements cannot be accessed directly but must be traversed sequentially . Despite these drawbacks, in scenarios where flexibility in data management and structure expands as new data is introduced, the use of linked lists can be justified .

Linked lists’ ability to expand dynamically as needed without a preset size is advantageous in applications where the amount of data can vary unpredictably or grow substantially beyond initially anticipated bounds. This flexibility bypasses the memory allocation limitations of arrays, which require predefined sizing, potentially leading to inefficient memory usage if poorly estimated . Linked lists allow efficient usage of memory by only consuming space actively needed for the data stored, thus avoiding the fixed cost of over-allocation and allowing efficient scaling with the dataset's growth .

Singly linked lists consist of nodes where each node contains data and a pointer to the next node, making operations like insertion and deletion fairly straightforward, but traversal is strictly one-way . They are suitable for applications where memory efficiency is crucial and backward traversal is not needed. In contrast, doubly linked lists have nodes with two pointers, one pointing to the next node and another pointing to the previous node, allowing for more flexible traversal in both directions. This flexibility makes them ideal for applications that require frequent backward navigation, such as navigation systems or scenarios where reverse iteration is common .

Linked lists are dynamic in nature, which means they allocate memory as required, unlike arrays which need a predefined size. This eliminates the need to declare a fixed size at the beginning . Linked lists also allow easy insertion and deletion of elements since only the pointers need to be adjusted, which is generally more efficient than the shifting operations required in arrays. Additionally, linked lists can effectively implement other data structures like stacks and queues, reducing access time for certain operations . However, this comes at the cost of memory overhead due to the storage of pointers and the inability to access elements randomly, as linked lists must be traversed sequentially .

You might also like