SlideShare a Scribd company logo
CLASS- XII
PCT-2 UNIT - 1 CHAPTER - 9
Prepared By -
Swati Patil
BE, MCA,PGDHRM
Contact -
8618134279 (Queries only through SMS)
prippython12.blogspot.com
Data structures
Data Structures is a collection of data values,
relationships among them, and the functions or
operations that can be applied to the data.
Data Structures are a way to organize information in
computer’s memory.
Circular
Queue
Double
Ended
Queue
Simple
Queue
graph
Python offers many Built-in Linear Data structures like List, Tuple, Dictionaries, Sets.
Operations on Data structures-
The basic operations that are performed on data structures are as follow:
1. Insertion 4. Traversal- fetching all data elements one by one
2. Deletion 5. Sorting
3. Searching 6. Merging- Combining elements of 2 or more similar data structures to form new
Date Type Data Structure
It defines set of values for input-output
operations.
It is physical implementation of Storing, accessing, manipulating
data stored in a data structure.
For example,
one can not put decimal point in an integer
or two strings can’t be multiplied.
For example,
Data stored in Stack can be accessed and retrieved from one end
only(LIFO).
Data stored in Queue can be accessed and retrieved from two
ends(FIFO)..
Linear DS Non-Linear DS
These are single level DS. These are multilevel DS.
Examples-Stack, Wueue,LinkesList (implemented by
List)
Example- Tree Graphs
Linear Data Structures( Homogeneous )
Elements of Linear Data structures form a sequence. Arrays are one of the simplest
data structures, and operations are easy to perform like Insertion, Deletion,Searching,
Traversal,Sorting etc.
Let us Revise and Implement Linear List Data Structure based on what you have learnt
in XI.
Searching in LL - a> LInear Search b> Binary Search
Insertion in LL - a> LL is unordered b> LL is ordered (traditional & bisect methods)
Deletion from LL - a> LL is unordered b> LL is ordered (traditional & bisect methods)
Traversal in LL
Length / Size of a Linear list(Arrays) calculated as:
Size of LL= UB - LB +1 (UB- Upper Bound, LB- Lower Bound)
Linear Search
1. Input List, L
2. Input ITEM to search
3. Initialize pos=-1
4. Repeat step 5 until ITEM found or counter
reaches to end of the list.
5. If L[i] == ITEM then
pos=i
Goto step 6
1. If pos == -1
Print “ ITEM not found”
Else
Print “ ITEM found “
1. END
# Program
L=eval(input(“Enter elements:”)
ITEM= int(input(“Enter ITEM to search:”)
pos=-1
for i in range(len(L)):
if L[i] == ITEM :
pos=i
break
if( pos == -1):
print(ITEM, “Not found”)
else:
print(ITEM, “ found at position”,
pos)
Binary Search
1. Input List, L
2. Input ITEM to search
3. Initialize pos=-1
4. Initialize beg=0 and last=sizeof(L)
5. Repeat step 6 through 9 until beg >last
6. mid=(beg+last) / 2
7. if L[mid] == ITEM then
pos=i
Goto step 10
1. if L[mid] >ITEM then
last=mid-1
1. if L[mid] < ITEM then
beg=mid+1
1. If pos==-1 then
print “ ITEM not found”
else
print “ ITEM found “
1. END
# Program
L=eval(input(“Enter elements:”)
ITEM= int(input(“Enter ITEM to search:”)
pos=-1
beg=0
last=len(L)
while beg<=last :
mid=(beg+last)/2
if L[mid] == ITEM :
pos=i
break
if L[mid] > ITEM :
last=mid-1
if L[mid] <ITEM :
beg=mid+1
if pos==-1 :
print(ITEM,”Not Found”)
else:
print(ITEM,”Found at
position”,pos)
Insertion in Linear List
# Insertion of new element in unsorted array.
(new element gets inserted at the end of the array)
1. Insert unordered elements in a list, L
2. Read an element to insert into list, ITEM
3. Insert ITEM at end of the list
4. Print list with inserted ITEM
5. END
# Program
L=eval(input(“Enter elements:”))
ITEM=int(input(“Enter an element to insert in list:”))
L.append(ITEM)
print(L)
Insertion in Linear List
# Insertion of new element in sorted array. Using Traditional method, shifting digits of array.
(new element gets inserted at the appropriate position without altering the order)
# Using Traditional Method program
def Findpos(A,ITEM):
if (A[0]>ITEM) :
return 0
else:
pos=-1
for i in range(len(A)):
if(A[i]<=ITEM and ITEM<A[i+1]):
pos=i+1
break
if (pos== -1 and i <=len(A)-1):
pos=len(A)
return pos
def Shift(A,pos):
A.append(None)
size=len(A)
i=size-1
while i>= pos:
A[i]=A[i-1]
i=i-1
L=eval(input(“Enter elements:”))
L.sort()
ITEM=int(input(“Enter element to insert:”))
pos=Findpos(L,ITEM)
Shift(L,pos)
L[pos]=ITEM
print(“The list after inserting”,ITEM,”is”,L)
Insertion in Linear List Traversal of a List
# Insertion of new element in sorted array.
Using Bisect Module
(new element gets inserted at the appropriate
position without altering the order)
n=int(input(“Enter size of LIst:”))
L=[None] * n
for i in range(len(n)):
L[i]=int(input(“Enter element”+str(i)+”:”))
print(“Traversing the List:”)
for i in range(len(n)):
print(L[i],end=’ ‘)
# Using bisect Module’s insort() function
L=eval(input(“Enter elements:”))
print(“The list in sorted order:”,L.sort())
ITEM=int(input(“Enter element to insert:”))
pos=bisect.bisect(L,ITEM)
bisect.insort(L,ITEM)
print(“The list after inserting”,ITEM,”at
position”,pos,”is”,L)
Deletion in Sorted Linear List
def bsearch(L,ITEM):
beg=0 last=len(L)
while beg<=last :
mid=(beg+last)/2
if L[mid] == ITEM :
return mid
if L[mid] > ITEM :
last=mid-1
if L[mid] <ITEM :
beg=mid+1
else: return False
L=eval(input(“Enter elements:”))
print(“The list in sorted order:”,L.sort())
ITEM=int(input(“Enter element to delete:”))
pos=bsearch(L,ITEM)
if pos:
del L[pos]
print(“The list after deleting”,ITEM,”is”, L)
else: print(“Element not present in list”)
# direct remove element
L=eval(input(“Enter elements:”))
print(“The list in sorted order:”,L.sort())
ITEM=int(input(“Enter element to delete:”))
L.remove(ITEM)
print(“The list after deleting”,ITEM,”is”, L)
Nested / 2 Dimensional List
(A list that has one more lists as its elements is nested list)
Properties of Regular nested / 2D lists:
1. All elements of 2D list have same shape(i.e same length & width)
2. Length of 2D is no of Rows in it (i.e len(list) )
3. Length of single Row gives the No of Columns (i.e len(list[n]) )
# Traversing a 2D list
print(“ 2D List is= n [ ”)
for i in range(r):
print(‘t [‘,end=’ ‘)
for j in range(c):
print(L[i][j],end=’ ‘)
print(‘]’)
print(‘]’)
#Creating 2D
L=[ ]
r,c=map(int(input(“Enter no of Rows & Columns”))
for i in range(r):
row=[]
for j in range(c):
ele=int(input(“element”+str(i)+’,’+str(j)+’:’))
row.append(ele)
L.append(row)
print(“ 2D List is:”,L)
Ragged List
Properties of Ragged 2D list:
1. All elements of 2D list have different shape(i.e different lengths )
2. Length of 2D is no of Rows in it (i.e len(list) )
3. Length of single Row gives the No of Columns (i.e len(list[n]) )
0
1
2
“Red”
15
7.3
0
1
5000
0 4
1 5
2 6
0 14
1 15
2 16
3 17
4 18
L=[“Red”,15,7.3] L2D=[ [4,5,6] , [14,15,16,17,18] ]
L2D
30500
5000
40000
List slicing:
L2D[1: ] =[14,15,16,17,18]
L2D[1: ] [2: ]=[16,17,18]
L2D[0: ] [ :2] =[4,5]
L2D[0: ] [ :1 ]=
L2D[0: ] [ : ]=
L2D[ :2 ]=
L2D[1: ] [2:4]=
Consider the following code and show how internally the memory is assigned to
these
List1=[2,3] List2= [3,4,5] List3= [List1, List2]
Assume that the numbers 1..10 are stored in the memory addresses 16000 onwards,
each consuming 16 bytes of memory.
1 2 3 64 5 7 8 9
10
16000 16016 16032 16048 16064 16080 16096 16112 16128 16144
0 16016
1 16032
0 16032
1 16048
2 16064
0 50000
1 20000
List1
50000
List2
20000
List3
30000
Ad

More Related Content

What's hot (20)

Algorithm and Programming (Searching)
Algorithm and Programming (Searching)Algorithm and Programming (Searching)
Algorithm and Programming (Searching)
Adam Mukharil Bachtiar
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
swajahatr
 
Chap10
Chap10Chap10
Chap10
Terry Yoast
 
Data structures using c
Data structures using cData structures using c
Data structures using c
Prof. Dr. K. Adisesha
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
smruti sarangi
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Data structures
Data structuresData structures
Data structures
Sneha Chopra
 
Chapter 17 Tuples
Chapter 17 TuplesChapter 17 Tuples
Chapter 17 Tuples
Praveen M Jigajinni
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
smruti sarangi
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
Poojith Chowdhary
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi
 
Data Structures & Algorithm design using C
Data Structures & Algorithm design using C Data Structures & Algorithm design using C
Data Structures & Algorithm design using C
Emertxe Information Technologies Pvt Ltd
 
Introduction to Data Structure : Pointer
Introduction to Data Structure : PointerIntroduction to Data Structure : Pointer
Introduction to Data Structure : Pointer
S P Sajjan
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Hoang Nguyen
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
Zidny Nafan
 
Data structures Basics
Data structures BasicsData structures Basics
Data structures Basics
DurgaDeviCbit
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
Qundeel
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
swajahatr
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
smruti sarangi
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
smruti sarangi
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
Poojith Chowdhary
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to Data Structure : Pointer
Introduction to Data Structure : PointerIntroduction to Data Structure : Pointer
Introduction to Data Structure : Pointer
S P Sajjan
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Hoang Nguyen
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
Zidny Nafan
 
Data structures Basics
Data structures BasicsData structures Basics
Data structures Basics
DurgaDeviCbit
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
Qundeel
 

Similar to Data structures: linear lists (20)

PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuufPYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
DeepakRattan3
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
Praveen M Jigajinni
 
Python _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functionsPython _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functions
VidhyaB10
 
data structures with algorithms vtu 2023 notes.pptx
data structures with algorithms  vtu 2023 notes.pptxdata structures with algorithms  vtu 2023 notes.pptx
data structures with algorithms vtu 2023 notes.pptx
hemanthkumar40680
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin
 
Data -structures for class 12 , easy ppt
Data -structures for class 12 , easy pptData -structures for class 12 , easy ppt
Data -structures for class 12 , easy ppt
anikedheikhamsingh
 
List in Python Using Back Developers in Using More Use.
List in Python Using Back Developers in Using More Use.List in Python Using Back Developers in Using More Use.
List in Python Using Back Developers in Using More Use.
SravaniSravani53
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
Nivegeetha
 
Python lists &amp; sets
Python lists &amp; setsPython lists &amp; sets
Python lists &amp; sets
Aswini Dharmaraj
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
Sakith1
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
MCCMOTOR
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
Guru Nanak Technical Institutions
 
Brief Explanation On List and Dictionaries of Python
Brief Explanation On List and Dictionaries of PythonBrief Explanation On List and Dictionaries of Python
Brief Explanation On List and Dictionaries of Python
nikhita4775
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
NehaSpillai1
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
NehaSpillai1
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
Rafal Edward
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
Youssef Elsalhawy
 
List and Dictionary in python
List and Dictionary in pythonList and Dictionary in python
List and Dictionary in python
Sangita Panchal
 
PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuufPYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
DeepakRattan3
 
Python _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functionsPython _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functions
VidhyaB10
 
data structures with algorithms vtu 2023 notes.pptx
data structures with algorithms  vtu 2023 notes.pptxdata structures with algorithms  vtu 2023 notes.pptx
data structures with algorithms vtu 2023 notes.pptx
hemanthkumar40680
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin
 
Data -structures for class 12 , easy ppt
Data -structures for class 12 , easy pptData -structures for class 12 , easy ppt
Data -structures for class 12 , easy ppt
anikedheikhamsingh
 
List in Python Using Back Developers in Using More Use.
List in Python Using Back Developers in Using More Use.List in Python Using Back Developers in Using More Use.
List in Python Using Back Developers in Using More Use.
SravaniSravani53
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
Sakith1
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
MCCMOTOR
 
Brief Explanation On List and Dictionaries of Python
Brief Explanation On List and Dictionaries of PythonBrief Explanation On List and Dictionaries of Python
Brief Explanation On List and Dictionaries of Python
nikhita4775
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
NehaSpillai1
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
NehaSpillai1
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
Rafal Edward
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
List and Dictionary in python
List and Dictionary in pythonList and Dictionary in python
List and Dictionary in python
Sangita Panchal
 
Ad

More from ToniyaP1 (6)

Numpy
NumpyNumpy
Numpy
ToniyaP1
 
Python library
Python libraryPython library
Python library
ToniyaP1
 
Python algorithm efficency
Python algorithm efficencyPython algorithm efficency
Python algorithm efficency
ToniyaP1
 
Python data file handling
Python data file handlingPython data file handling
Python data file handling
ToniyaP1
 
Python functions
Python functionsPython functions
Python functions
ToniyaP1
 
Python recursion
Python recursionPython recursion
Python recursion
ToniyaP1
 
Python library
Python libraryPython library
Python library
ToniyaP1
 
Python algorithm efficency
Python algorithm efficencyPython algorithm efficency
Python algorithm efficency
ToniyaP1
 
Python data file handling
Python data file handlingPython data file handling
Python data file handling
ToniyaP1
 
Python functions
Python functionsPython functions
Python functions
ToniyaP1
 
Python recursion
Python recursionPython recursion
Python recursion
ToniyaP1
 
Ad

Recently uploaded (20)

antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 

Data structures: linear lists

  • 1. CLASS- XII PCT-2 UNIT - 1 CHAPTER - 9 Prepared By - Swati Patil BE, MCA,PGDHRM Contact - 8618134279 (Queries only through SMS) prippython12.blogspot.com
  • 2. Data structures Data Structures is a collection of data values, relationships among them, and the functions or operations that can be applied to the data. Data Structures are a way to organize information in computer’s memory. Circular Queue Double Ended Queue Simple Queue graph
  • 3. Python offers many Built-in Linear Data structures like List, Tuple, Dictionaries, Sets. Operations on Data structures- The basic operations that are performed on data structures are as follow: 1. Insertion 4. Traversal- fetching all data elements one by one 2. Deletion 5. Sorting 3. Searching 6. Merging- Combining elements of 2 or more similar data structures to form new Date Type Data Structure It defines set of values for input-output operations. It is physical implementation of Storing, accessing, manipulating data stored in a data structure. For example, one can not put decimal point in an integer or two strings can’t be multiplied. For example, Data stored in Stack can be accessed and retrieved from one end only(LIFO). Data stored in Queue can be accessed and retrieved from two ends(FIFO).. Linear DS Non-Linear DS These are single level DS. These are multilevel DS. Examples-Stack, Wueue,LinkesList (implemented by List) Example- Tree Graphs
  • 4. Linear Data Structures( Homogeneous ) Elements of Linear Data structures form a sequence. Arrays are one of the simplest data structures, and operations are easy to perform like Insertion, Deletion,Searching, Traversal,Sorting etc. Let us Revise and Implement Linear List Data Structure based on what you have learnt in XI. Searching in LL - a> LInear Search b> Binary Search Insertion in LL - a> LL is unordered b> LL is ordered (traditional & bisect methods) Deletion from LL - a> LL is unordered b> LL is ordered (traditional & bisect methods) Traversal in LL Length / Size of a Linear list(Arrays) calculated as: Size of LL= UB - LB +1 (UB- Upper Bound, LB- Lower Bound)
  • 5. Linear Search 1. Input List, L 2. Input ITEM to search 3. Initialize pos=-1 4. Repeat step 5 until ITEM found or counter reaches to end of the list. 5. If L[i] == ITEM then pos=i Goto step 6 1. If pos == -1 Print “ ITEM not found” Else Print “ ITEM found “ 1. END # Program L=eval(input(“Enter elements:”) ITEM= int(input(“Enter ITEM to search:”) pos=-1 for i in range(len(L)): if L[i] == ITEM : pos=i break if( pos == -1): print(ITEM, “Not found”) else: print(ITEM, “ found at position”, pos)
  • 6. Binary Search 1. Input List, L 2. Input ITEM to search 3. Initialize pos=-1 4. Initialize beg=0 and last=sizeof(L) 5. Repeat step 6 through 9 until beg >last 6. mid=(beg+last) / 2 7. if L[mid] == ITEM then pos=i Goto step 10 1. if L[mid] >ITEM then last=mid-1 1. if L[mid] < ITEM then beg=mid+1 1. If pos==-1 then print “ ITEM not found” else print “ ITEM found “ 1. END # Program L=eval(input(“Enter elements:”) ITEM= int(input(“Enter ITEM to search:”) pos=-1 beg=0 last=len(L) while beg<=last : mid=(beg+last)/2 if L[mid] == ITEM : pos=i break if L[mid] > ITEM : last=mid-1 if L[mid] <ITEM : beg=mid+1 if pos==-1 : print(ITEM,”Not Found”) else: print(ITEM,”Found at position”,pos)
  • 7. Insertion in Linear List # Insertion of new element in unsorted array. (new element gets inserted at the end of the array) 1. Insert unordered elements in a list, L 2. Read an element to insert into list, ITEM 3. Insert ITEM at end of the list 4. Print list with inserted ITEM 5. END # Program L=eval(input(“Enter elements:”)) ITEM=int(input(“Enter an element to insert in list:”)) L.append(ITEM) print(L)
  • 8. Insertion in Linear List # Insertion of new element in sorted array. Using Traditional method, shifting digits of array. (new element gets inserted at the appropriate position without altering the order) # Using Traditional Method program def Findpos(A,ITEM): if (A[0]>ITEM) : return 0 else: pos=-1 for i in range(len(A)): if(A[i]<=ITEM and ITEM<A[i+1]): pos=i+1 break if (pos== -1 and i <=len(A)-1): pos=len(A) return pos def Shift(A,pos): A.append(None) size=len(A) i=size-1 while i>= pos: A[i]=A[i-1] i=i-1 L=eval(input(“Enter elements:”)) L.sort() ITEM=int(input(“Enter element to insert:”)) pos=Findpos(L,ITEM) Shift(L,pos) L[pos]=ITEM print(“The list after inserting”,ITEM,”is”,L)
  • 9. Insertion in Linear List Traversal of a List # Insertion of new element in sorted array. Using Bisect Module (new element gets inserted at the appropriate position without altering the order) n=int(input(“Enter size of LIst:”)) L=[None] * n for i in range(len(n)): L[i]=int(input(“Enter element”+str(i)+”:”)) print(“Traversing the List:”) for i in range(len(n)): print(L[i],end=’ ‘) # Using bisect Module’s insort() function L=eval(input(“Enter elements:”)) print(“The list in sorted order:”,L.sort()) ITEM=int(input(“Enter element to insert:”)) pos=bisect.bisect(L,ITEM) bisect.insort(L,ITEM) print(“The list after inserting”,ITEM,”at position”,pos,”is”,L)
  • 10. Deletion in Sorted Linear List def bsearch(L,ITEM): beg=0 last=len(L) while beg<=last : mid=(beg+last)/2 if L[mid] == ITEM : return mid if L[mid] > ITEM : last=mid-1 if L[mid] <ITEM : beg=mid+1 else: return False L=eval(input(“Enter elements:”)) print(“The list in sorted order:”,L.sort()) ITEM=int(input(“Enter element to delete:”)) pos=bsearch(L,ITEM) if pos: del L[pos] print(“The list after deleting”,ITEM,”is”, L) else: print(“Element not present in list”) # direct remove element L=eval(input(“Enter elements:”)) print(“The list in sorted order:”,L.sort()) ITEM=int(input(“Enter element to delete:”)) L.remove(ITEM) print(“The list after deleting”,ITEM,”is”, L)
  • 11. Nested / 2 Dimensional List (A list that has one more lists as its elements is nested list) Properties of Regular nested / 2D lists: 1. All elements of 2D list have same shape(i.e same length & width) 2. Length of 2D is no of Rows in it (i.e len(list) ) 3. Length of single Row gives the No of Columns (i.e len(list[n]) ) # Traversing a 2D list print(“ 2D List is= n [ ”) for i in range(r): print(‘t [‘,end=’ ‘) for j in range(c): print(L[i][j],end=’ ‘) print(‘]’) print(‘]’) #Creating 2D L=[ ] r,c=map(int(input(“Enter no of Rows & Columns”)) for i in range(r): row=[] for j in range(c): ele=int(input(“element”+str(i)+’,’+str(j)+’:’)) row.append(ele) L.append(row) print(“ 2D List is:”,L)
  • 12. Ragged List Properties of Ragged 2D list: 1. All elements of 2D list have different shape(i.e different lengths ) 2. Length of 2D is no of Rows in it (i.e len(list) ) 3. Length of single Row gives the No of Columns (i.e len(list[n]) ) 0 1 2 “Red” 15 7.3 0 1 5000 0 4 1 5 2 6 0 14 1 15 2 16 3 17 4 18 L=[“Red”,15,7.3] L2D=[ [4,5,6] , [14,15,16,17,18] ] L2D 30500 5000 40000 List slicing: L2D[1: ] =[14,15,16,17,18] L2D[1: ] [2: ]=[16,17,18] L2D[0: ] [ :2] =[4,5] L2D[0: ] [ :1 ]= L2D[0: ] [ : ]= L2D[ :2 ]= L2D[1: ] [2:4]=
  • 13. Consider the following code and show how internally the memory is assigned to these List1=[2,3] List2= [3,4,5] List3= [List1, List2] Assume that the numbers 1..10 are stored in the memory addresses 16000 onwards, each consuming 16 bytes of memory. 1 2 3 64 5 7 8 9 10 16000 16016 16032 16048 16064 16080 16096 16112 16128 16144 0 16016 1 16032 0 16032 1 16048 2 16064 0 50000 1 20000 List1 50000 List2 20000 List3 30000
  翻译: