0% found this document useful (0 votes)
39 views5 pages

Week 5

Chapter 5 introduces linked lists, highlighting the differences between linear (arrays) and nonlinear (pointer) data structures, including their advantages and disadvantages. It explains the structure of linked lists, types (singly, doubly, and circular), and their applications in real-world scenarios such as image viewers and music players. The chapter also outlines key operations associated with linked lists, emphasizing their dynamic nature and efficient memory usage.

Uploaded by

amanthpanchal
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)
39 views5 pages

Week 5

Chapter 5 introduces linked lists, highlighting the differences between linear (arrays) and nonlinear (pointer) data structures, including their advantages and disadvantages. It explains the structure of linked lists, types (singly, doubly, and circular), and their applications in real-world scenarios such as image viewers and music players. The chapter also outlines key operations associated with linked lists, emphasizing their dynamic nature and efficient memory usage.

Uploaded by

amanthpanchal
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/ 5

CHAPTER 5

INTRODUCTION TO LINKED LIST

● Linear(arrays) vs nonlinear (pointer) structures – Run time and space requirements, when to use
what?
● Introduction to linked list, Examples: Image viewer, music player list etc. (to be used to explain concept
of list), applications.

Linear(arrays) vs nonlinear (pointer) structures

Arrays

An array is a sequential list of data. Being sequential means that each element is stored right
after the previous one in memory.

Figure : A sample 1-D array consisting of 11 elements.

Advantages:

• Simple and easy to use


• Faster access to elements

Disadvantages:

• Fixed size
• one block allocation
• complex position based insertion

Pointer

In Python, you don't manipulate pointers directly, unlike in some other languages, such as C or
Pascal.

Consider this assignment in the Python interactive shell:


>>> x = 2337

We would normally say that x is a variable which is holding value 2337 but this is not strictly
true, however.

GOVERNMENT POLYTECHNIC, KARWAR 1


The variable x is rather a reference to integer object. Compiler will create object of the integer
type somewhere in memory and returns the memory location . This is what gets stored in x as
shown in figure . Python hides this complexity from us.

Pointer structures are lists of items that can be spread out in memory. This is because each
item contains one or more links to other items in the structure.

What type of links these are dependent on the type of structure we have. If we are dealing with
linked lists, then we will have links to the next items in the structure. In the case of a tree, we
have parent-child links as well as sibling links.

Benefits:
• They don't require sequential storage space.
• They can start small and grow arbitrarily as you add more nodes to the structure.

Difference between Linear and Non-linear Data Structures:

S.NO Linear Data Structure Non-linear Data Structure


1. In a linear data structure, data elements In a non-linear data structure, data
are arranged in a linear order where elements are attached in hierarchically
each and every element is attached to its manner.
previous and next adjacent.
2. In linear data structure, single level is Whereas in non-linear data structure,
involved. multiple levels are involved.
3. Its implementation is easy in comparison While its implementation is complex in
to non-linear data structure. comparison to linear data structure.
4. In linear data structure, data elements While in non-linear data structure, data
can be traversed in a single run only. elements can’t be traversed in a single run
only.
5. In a linear data structure, memory is not While in a non-linear data structure,
utilized in an efficient way. memory is utilized in an efficient way.
6. Its examples are: array, stack, queue, While its examples are: trees and graphs.
linked list, etc.

GOVERNMENT POLYTECHNIC, KARWAR 2


7. Applications of linear data structures are Applications of non-linear data structures
mainly in application software are in Artificial Intelligence and image
development. processing.
8. The time complexity of linear data The time complexity of non-linear data
structure increases with the increase in structure often remains same with the
the input size. increase in the input size.

Introduction to linked list


A linked list is a data structure used for storing collection of data. A linked list has following
properties:
• Successive elements are connected by pointers
• The last element points to NULL
• can grow or shrink in size during execution of programming can be made just as long
as required ( until system memory exhausts)
• Does not waste memory space (but takes some extra memory for pointers)
A Linked list is made up of nodes, where a node is made up of two parts:
1. Data Part: Holds the data
2. Address Part: Holds the address of the next node.

Types of Linked List


Singly Linked List:
• It is the simplest type of linked list in which every node contains some data and a
pointer to the next node of the same data type.
• A single linked list allows traversal of data only in one way.

GOVERNMENT POLYTECHNIC, KARWAR 3


Doubly Linked List:
• A doubly linked list or a two-way linked list which contains a pointer to the next as well
as the previous node in the list.
• Therefore, it contains three parts are data, a pointer to the next node, and a pointer to
the previous node.
• This would enable us to traverse the list in the backward direction as well. Below is the
image for the same:

Circular Linked List:


• A circular linked list is that in which the last node contains the pointer to the first node of
the list.
• While traversing a circular linked list, we can begin at any node and traverse the list in
any direction forward and backward until we reach the same node we started.
• Below is the image for the same:

GOVERNMENT POLYTECHNIC, KARWAR 4


Linked Lists ADT
The following operations make linked lists an ADT:
• Insert:Insert an element into an list
• Delete: removes and specified position element from the list
• Count: count the number of elements in list
• Traverse: Display the all the elements in a list.
• Find nth node from the end of list

Applications of linked list in real world :

1. Image viewer – Previous and next images are linked, hence can be accessed by next and
previous button.

2. Previous and next page in web browser – We can access previous and next url searched
in web browser by pressing back and next button since, they are linked as linked list.

3. Music Player – Songs in music player are linked to previous and next song. you can play
songs either from starting or ending of the list.

GOVERNMENT POLYTECHNIC, KARWAR 5

You might also like