22
Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE Course: Data Structures Unit-3: Linked Organization . Prepared By: Mr. Vipin K. Wani Assistant Professor School of Computer Sciences & Engineering

Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Prepared By: Mr. Vipin K. Wani SOCSE, SandipUniversity, Nashik

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

Class: SE

Course: Data Structures

Unit-3: Linked Organization

.

Prepared By:

Mr. Vipin K. WaniAssistant Professor

School of Computer Sciences & Engineering

Page 2: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Introduction to Linked Organization

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

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

Page 3: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Introduction to Linked List

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

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

Page 4: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Introduction to Linked List

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

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

Page 5: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Introduction to Linked List

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

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].

Page 6: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Introduction to Linked List

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

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.

Page 7: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Introduction to Linked List

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

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.

Fig: Node Structure of SLL.

Data Next

5 7 9Head

Null

Page 8: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Introduction to Linked List

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

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.

Fig: Node Structure of SLL.

Data NextPrevious

10 20 30 NullNull

Head

Page 9: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Introduction to Linked List

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

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

Fig: Node Structure of SLL.

Data Next

5 7 9Head

Page 10: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Operations on Linked List

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

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.

Page 11: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Operations on Linked List

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

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.

Page 12: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Operations on Linked List

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

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.

Page 13: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Applications of Linked List

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

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.

Page 14: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Applications of Linked List

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

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 9Head

Null

Page 15: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Applications of Linked List

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

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.

1

2 3

4 5

Page 16: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Applications of Linked List

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

3. Implementation of Stack and queue:

It can be used to create Linked Stack and Linked queue.

5

7

9Top

5 7 9Front

19

rear

Page 17: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Applications of Linked List

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

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.

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.

Data/ Link nextflag

Page 18: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Applications of Linked List

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

4. Representation of List or Set:

Example 1: (a, b, c, (d, e, (f), g))

a0Head

b0 c0 NULL1

d0 e0 1 g0

f0

NULL

NULL

Page 19: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Applications of Linked List

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

4. Representation of List or Set:

Example 2: (a, c, (b, d), e, g, (f, h), i))

Page 20: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Applications of Linked List

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

4. Representation of Polynomial Eq. 3x2yz+ 5xy

0 Variable

1 Link

1. Coeff is present

2. Link is present

Variable/Link nextflag

Coeff/ Link Expoflag next

Page 21: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

Applications of Linked List

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

4. Representation of Polynomial Eq. 3x2yz+ 5xy

X0 2 2 2 1

Y0 2 1

Z0 1 13

Y0 1 15

NULL

NULL

NULL

NULL

Page 22: Program: BTech (BAO/CSF/CTIS/IoT/AIML/CSE) Class: SE · 2020. 10. 29. · Introduction to Linked List Prepared By: Mr. Vipin K. Wani SOCSE, Sandip University, Nashik 7 1. Simple Linked

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

Download ppts from: wanivipin.wordpress.com