0% found this document useful (0 votes)
9 views71 pages

11. Linked list notes lawanyashri

Uploaded by

asodariadhruv
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)
9 views71 pages

11. Linked list notes lawanyashri

Uploaded by

asodariadhruv
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/ 71

M.

Lawanyashri, SCORE
M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
Linked list
 A linked list is a linear data structure which can
store a collection of "nodes" connected together via
links i.e. pointers.
 Linked lists nodes are not stored at a contiguous
location, rather they are linked using pointers to the
different memory locations.
 A node consists of the data value and a pointer to
the address of the next node within the linked list.

M.Lawanyashri, SCORE
Why Linked List?

• Drawbacks of Array:
• The size of the array is fixed. Most often this size is specified at
compile time. This makes the programmers to allocate arrays, which
seems "large enough" than required.
• Inserting new elements at the front is potentially expensive because
existing elements need to be shifted over to make room.
• Deleting an element from an array is not possible.
• Generally array's allocates the memory for all its elements in one
block

M.Lawanyashri, SCORE
Linked list Analogy

M.Lawanyashri, SCORE
Linked list
 A linked list is a dynamic linear data structure whose
memory size can be allocated or de-allocated at run
time based on the operation insertion or deletion, this
helps in using system memory efficiently.
 Linked lists can be used to implement various data
structures like a stack, queue, graph, hash maps, etc

M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
Array vs Linked list

M.Lawanyashri, SCORE
Array vs Linked list

M.Lawanyashri, SCORE
Array vs Linked list

M.Lawanyashri, SCORE
Linked List Facts

 The data items comprising a linked list need not


be contiguous in memory.
 They are ordered by logical links that are stored as
part of the data in the structure itself.

M.Lawanyashri, SCORE
Linked list
 A linked list starts with a head node which points to
the first node.
 Every node consists of data which holds the actual
data (value) associated with the node and a next
pointer which holds the memory address of the next
node in the linked list.
 The last node is called the tail node in the list which
points to null indicating the end of the list.

M.Lawanyashri, SCORE
Declaration of node
 How to create structure of the node

M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
Advantages of Linked Lists
 Linked lists are dynamic data structures. i.e., they can
grow or shrink during the execution of a program.
 Linked lists have efficient memory utilization. Here,
memory is not pre allocated. Memory is allocated
whenever it is required and it is de-allocated
(removed) when it is no longer needed.
 Insertion and Deletions are easier and efficient. Linked
lists provide flexibility in inserting a data item at a
specified position and deletion of the data item from
the given position.
 Many complex applications can be easily carried out
with linked lists.

M.Lawanyashri, SCORE
Disadvantages of Linked List
 It consumes more space because every node requires
an additional pointer to store address of the next
node.
 No element can be accessed randomly; it has to
access each node sequentially.
 Reverse Traversing is difficult in linked list

M.Lawanyashri, SCORE
Basic Operations on Linked List
 There are certain basic operations that a linked list
data structure supports. These operations are:
 Traversal:
 Itmeans visiting each node from the beginning till the
end.

M.Lawanyashri, SCORE
Basic Operations on Linked List
 Insertion:
 This operation inserts an element at any given position
in the list.
 Insertion Types:
 Insertion at the Beginning
 Insertion at the end
 Insertion in a specific position

M.Lawanyashri, SCORE
Basic Operations on Linked List
 Deletion:
 Deletion operation helps in deleting a node from the
linked list.
 Deletion Types:
 Deletion at the Beginning
 Deletion at the end
 Deletion in a specific position

M.Lawanyashri, SCORE
Basic Operations on Linked List
 Search:
 search operation helps in searching an element by
traversing it.

M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
Types of Linked List
 Singly Linked List

 Doubly Linked List

 Circular Linked List

M.Lawanyashri, SCORE
Singly Linked List

M.Lawanyashri, SCORE
M.Lawanyashri, SCORE
Singly Linked List

M.Lawanyashri, SCORE
Doubly Linked List
A doubly linked list is a more complex data structure than
a singly linked list, but it offers several advantages.

The main advantage of a doubly linked list is that it allows


for efficient traversal of the list in both directions.

This is because each node in the list contains a pointer to


the previous node and a pointer to the next node.

This allows for quick and easy insertion and deletion of


nodes from the list, as well as efficient traversal of the list
in both directions. M.Lawanyashri, SCORE
Doubly Linked List
A doubly linked list is a data structure that consists of a
set of nodes, each of which contains a value and two
pointers, one pointing to the previous node in the list and
one pointing to the next node in the list.

This allows for efficient traversal of the list in both


directions, making it suitable for applications where
frequent insertions and deletions are required.

M.Lawanyashri, SCORE
Doubly Linked List

M.Lawanyashri, SCORE
Doubly Linked List

M.Lawanyashri, SCORE
Doubly Linked List

M.Lawanyashri, SCORE
Doubly Linked List

M.Lawanyashri, SCORE
Doubly Linked List

M.Lawanyashri, SCORE
Doubly Linked List

M.Lawanyashri, SCORE
Doubly Linked List

M.Lawanyashri, SCORE
Doubly Linked List

M.Lawanyashri, SCORE
Doubly Linked List

M.Lawanyashri, SCORE
Circularly Linked List

A circular linked list is a data structure where the last node connects
back to the first, forming a loop. This structure allows for continuous
traversal without any interruptions. Circular linked lists are especially
helpful for tasks like scheduling and managing playlists, this allowing
for smooth navigation. In this tutorial, we’ll cover the basics of circular
linked lists, how to work with them, their advantages and disadvantages,
and their applications.
What is a Circular Linked List?
A circular linked list is a special type of linked list where all the nodes
are connected to form a circle. Unlike a regular linked list, which ends
with a node pointing to NULL, the last node in a circular linked list points
back to the first node. This means that you can keep traversing the list
without ever reaching a NULL value.
M.Lawanyashri, SCORE
Circularly Linked List Types

M.Lawanyashri, SCORE
Circularly Linked List Types

M.Lawanyashri, SCORE
Circularly Linked List Operations

M.Lawanyashri, SCORE
Circularly Linked List Operations

M.Lawanyashri, SCORE
Circularly Linked List Operations

M.Lawanyashri, SCORE
Circularly Linked List Operations

M.Lawanyashri, SCORE
Circularly Linked List Operations

M.Lawanyashri, SCORE
Circularly Linked List Operations

M.Lawanyashri, SCORE
Circularly Linked List Operations

M.Lawanyashri, SCORE
Circularly Linked List Operations

M.Lawanyashri, SCORE
Circularly Linked List

M.Lawanyashri, SCORE
Applications of linked list
 Linked lists have numerous applications in computer
science and programming. :
1. Dynamic Memory Allocation: Linked lists enable
dynamic memory allocation, allowing for efficient use of
memory.
2. Database Querying: Linked lists are used in database
querying, particularly for indexing and retrieving data
efficiently.
3. Browser History: Web browsers use linked lists to
manage browsing history, allowing for forward and
backward navigation.
M.Lawanyashri, SCORE
Applications of linked list
4. Undo/Redo Functionality: Linked lists facilitate the
implementation of undo and redo features in
applications.
5. Social Network Feeds: Social media platforms
utilize linked lists to manage and display feeds,
updates, and notifications.
6. Compilers: Linked lists are used in compiler design
for parsing, syntax analysis, and memory management.

M.Lawanyashri, SCORE
Applications of linked list
7. Graph and Tree Representations: Linked lists help
represent graphs and trees, enabling efficient traversal
and manipulation.
8. Real-time Systems: Linked lists are used in real-time
systems for task scheduling, resource allocation, and event
handling.
9. File Systems: Linked lists are employed in file systems
for managing file metadata, directories, and file allocation
tables.
10. Artificial Intelligence: Linked lists are used in AI
applications, such as expert systems, decision-making
algorithms, and game development.

M.Lawanyashri, SCORE
Applications of linked list
GPS navigation systems- Linked lists can be used to store
and manage a list of locations and routes, allowing users to
easily navigate to their desired destination.
Robotics- Linked lists can be used to implement control
systems for robots, allowing them to navigate and interact
with their environment.
Symbol Table- Compilers use linked lists to build a symbol
table, which is a data structure that stores information
about identifiers used in a program.
Speech Recognition- Speech recognition software uses
linked lists to represent the possible phonetic pronunciations
of a word, where each possible pronunciation is
represented as a node in the list.
M.Lawanyashri, SCORE
Applications of Linked list
 Polynomial Manipulations:
 Polynomial manipulations are one of the most
important applications of linked lists.
 Polynomials are an important part of mathematics
not inherently supported as a data type by most
languages.
 A polynomial is a collection of different terms, each
comprising coefficients, and exponents. It can be
represented using a linked list.
M.Lawanyashri, SCORE
Polynomial Manipulations:
 polynomial can be represented using a linked list, in
which each polynomial term represents a node in
the linked list.
 Each node of a linked list representing
polynomial constitute three parts:
• The first part contains the value of the coefficient of
the term.
• The second part contains the value of the exponent.
• The third part, LINK points to the next term (next
node).
M.Lawanyashri, SCORE
Polynomial Manipulations:

M.Lawanyashri, SCORE
Polynomial Manipulations:
 Consider a polynomial
P(x) = 7x2 + 15x3 - 2 x2 + 9.
 Here 7, 15, -2, and 9 are the coefficients, and 4,3,2,0
are the exponents of the terms in the polynomial.

M.Lawanyashri, SCORE
Applications of Linked list
 Sparse Matrix:
 Sparse matrices are those matrices that have the
majority of their elements equal to zero.
 In other words, the sparse matrix can be defined as
the matrix that has a greater number of zero
elements than the non-zero elements.

M.Lawanyashri, SCORE
Sparse Matrix:
 There are the following benefits of using the sparse
matrix -
 Storage - We know that a sparse matrix contains lesser
non-zero elements than zero, so less memory can be
used to store elements. It evaluates only the non-zero
elements.
 Computing time: In the case of searching in sparse
matrix, we need to traverse only the non-zero elements
rather than traversing all the sparse matrix elements. It
saves computing time by logically designing a data
structure traversing non-zero elements.

M.Lawanyashri, SCORE
Stack Implementation using Linked List

 To implement a stack using the singly linked list


concept, all the singly linked list operations should
be performed based on Stack operations LIFO(last
in first out).

M.Lawanyashri, SCORE
Stack Node Creation

M.Lawanyashri, SCORE
Stack Node Creation

M.Lawanyashri, SCORE
Queue implementation – linked list
 In a linked queue, each node of the queue consists of two fields,
i.e., data field and reference field.
 Each entity of the linked queue points to its immediate next entity
in the memory. Furthermore, to keep track of the front and rear
node, two pointers are preserved in the memory.
 The first pointer stores the location where the queue starts, and
another pointer keeps track of the last data element of a queue.

M.Lawanyashri, SCORE
Queue implementation – linked list
 The insertion in a linked queue is performed at the rear end by
updating the address value of the previous node where a rear
pointer is pointing.
 For example, consider the linked queue of size 3. We need to
insert a new node located at address 350 and consisting 7 in its
data field. For that to happen, we will just update the value of
the rear pointer and address field of the previous node. .

M.Lawanyashri, SCORE
Queue implementation – linked list
 After deleting an element from the linked queue, the value of the
front pointer will change from 100 to 200. The linked queue will
look like below:

M.Lawanyashri, SCORE
Thank you

M.Lawanyashri, SCORE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy