0% found this document useful (0 votes)
13 views22 pages

Ds Unit 3

Uploaded by

Ganesh Ekambe
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)
13 views22 pages

Ds Unit 3

Uploaded by

Ganesh Ekambe
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/ 22

.

Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE)


Class: SE

Prepared By: Course: Data Structures


Unit-3: Linked Organization
Mr. Vipin K. Wani
Assistant Professor

School of Computer Sciences & Engineering


Prepared By: Mr. Vipin K. Wani SOCSE, Sandip
University, Nashik
Introduction to Linked Organization

 A Linked Organization is one in which the elements of the list are logically next to each other, but
physically, they may not be adjacent.
 linked representation” or “linked organization "should be used, i.e. unlike an array, where elements
are stored sequentially in memory, items in a list may be located anywhere in memory.
 To access elements in the correct order, we store the address or location of the next element, with
each element of the list

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 2


Introduction to Linked List
 a linked list is a linear collection of data elements whose order is not given by their
physical placement in memory. Instead, each element points to the next. It is a data
structure consisting of a collection of nodes which together represent a sequence.
 Node is a memory block with two partition one for data and second for storing
address of next node/element.

Data next

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 3


Introduction to Linked List
Link − Each link of a linked list can store a data called an element.
Next − Each link of a linked list contains a link to the next link called Next.
LinkedList − A Linked List contains the connec on link to the first link called First.

Data next

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 4


Introduction to Linked List
Why Linked List?
Arrays can be used to store linear data of similar types, but arrays have the following limitations.
 The size of the arrays is fixed: So we must know the upper limit on the number of elements in
advance. Also, generally, the allocated memory is equal to the upper limit irrespective of the usage.
 Inserting a new element in an array of elements is expensive because the room has to be created for
the new elements and to create room existing elements have to be shifted.
 For example, in a system, if we maintain a sorted list of IDs in an array id[].
 id[] = [1000, 1010, 1050, 2000, 2040].

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 5


Introduction to Linked List
Types of Linked List
Following are the various types of linked list.
Simple Linked List − Item navigation is forward only.
Doubly Linked List − Items can be navigated forward and backward.
Circular Linked List − Last item contains link of the irst element as next and the irst element has a
link to the last element as previous.

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 6


Introduction to Linked List
1. Simple Linked List (SLL)− a linked list is a linear collection of data elements whose order is not given
by their physical placement in memory. In SLL every node is connected to only one element which is
next element. Item navigation is forward only.

Data Next

Fig: Node Structure of SLL.

5 7 9 Null
Head

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7


Introduction to Linked List
2. Doubly Linked List (DLL) − a linked list is a linear collection of data elements whose order is not
given by their physical placement in memory. In DLL every node is connected to two elements, preivios
as well as next element. Item navigation is forward and reverse direction.

Previous Data Next

Fig: Node Structure of SLL.

Null 10 20 30 Null
Head

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 8


Introduction to Linked List
3. Circular Linked List (CLL)− a linked list is a linear collection of data elements whose order is not
given by their physical placement in memory. In CLL last node is connected with first node, so no any
null link exist in CLL. Item navigation is forward only. It can be implemented as
1. Singly Circular Linked List
2. Doubly Circular Linked List

Data Next

Fig: Node Structure of SLL.

5 7 9
Head

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 9


Operations on Linked List
Basic Operations: Following are the basic operations supported by a list.

1. Insertion − Adds an element in the linked list.


2. Deletion − Deletes an element at the beginning of the list.
3. Display − Displays the complete list.
4. Search − Searches an element using the given key.

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 10


Operations on Linked List
1. Insertion − Adds an element in the linked list. Element insertion can be done either
a. at Start of the linked list.
b. at end of the linked list.
c. at middle of the linked list.

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 11


Operations on Linked List
2. Deletion − Deletes an element from the linked list. Deletion can be done either
a. at Start of the linked list.
b. at end of the linked list.
c. at middle of the linked list.

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 12


Applications of Linked List
Followings are the important applications of linked List:
1. Storing of any data
2. Implementation of trees and graph
3. Implementation of stack & Queue
4. Representation of List or Set.
5. Representation of polynomial equations.

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 13


Applications of Linked List
1. Storing of any data:
 It can be used to store any type of data for real time applications.
 It can store similar or different form of data elements.
 As well it can store any number of data element at run time.

5 7 9 Null
Head

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 14


Applications of Linked List
2. Implementation of trees and graph:
 It can be used to create trees, binary trees and all types of trees.
 It can be used to create all types of graphs.

2 3

4 5

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 15


Applications of Linked List
3. Implementation of Stack and queue:
 It can be used to create Linked Stack and Linked queue.

Top 9

7 5 7 9 19
Front rear
5

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 16


Applications of Linked List
4. Representation of List or Set:
 Linked list can be used to represent the elements of list or set.
 Where list is a collection of similar type of information.
 For representing list/set using linked list we require special kind of node with structure as follow.

Data/
flag next
Link
 Flag can have either any of the following values:
1. Flag 0 indicates: Node Containing Data
2. Flag 1 indicates: Node Containing Link
 Middle portion of node may have either data or down link to sub list.
 Next part will point to next element in list.

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 17


Applications of Linked List
4. Representation of List or Set:
 Example 1: (a, b, c, (d, e, (f), g))

0 a 0 b 0 c 1 NULL
Head

0 d 0 e 1 0 g NULL

0 f NULL

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 18


Applications of Linked List
4. Representation of List or Set:
 Example 2: (a, c, (b, d), e, g, (f, h), i))

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 19


Applications of Linked List
4. Representation of Polynomial Eq. 3x2yz+ 5xy

Variable
flag next
/Link

0 Variable
1 Link

Coeff/
flag Expo next
Link

1. Coeff is present
2. Link is present

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 20


Applications of Linked List
4. Representation of Polynomial Eq. 3x2yz+ 5xy

0 X 2 2 2 1 NULL

0 Y 2 1 0 Y 1 5 1 NULL
NULL

0 Z 1 3 1 NULL

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 21


Download ppts from: wanivipin.wordpress.com

Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 22

You might also like