SlideShare ist ein Scribd-Unternehmen logo
1 von 19
UNIT 1- LINEAR DATA
STRUCTURES
ARRAY BASED
IMPLEMENTATION
Introduction
• An Array is a collection of memory locations.
• The memory locations cannot be split from
each other, so if there is some empty space, it
just goes waste.
• Arrays cannot be interchanged.
• A array is a collection of variables of same
type.
• Some points to be noted about an array:
1. It is a continuous chunk of memory with equally
sized blocks.
2. The subscript always begins with ‘0’ and goes until
‘n-1’ which is also continuous.
3.Any memory location can be directly accessed using
its subscript.
4. Static arrays have issues, such as memory wastage
and memory leak, and also have constraints over the
size. These are overcome by using dynamic arrays.
5. Since it is a continuous chunk of memory, it has
internal issues such as fragmentation and memory
leaks.
Why do we study Arrays?
• The array structure looks very similar to Python's list
structure.
• But there are two major differences between the array and
the list.
1. array has a limited number of operations whereas Lists
provides a large number of operations for working with the
contents of the list.
2. lists can grow and shrink during execution as elements are
added or removed while the size of an array cannot be
changed after it has been created.
• The array is best suited for problems requiring a sequence
in which the maximum number of elements are known up
front, whereas the list is the better choicewhen the size of
the sequence needs to change after it has been created.
Array Abstract Data Type
• Definition: A one-dimensional array is a
collection of contiguous elements in which
individual elements are identified by a unique
integer subscript starting with zero. Once an
array is created, its size cannot be changed.
• Array( size ): Creates a one-dimensional array consisting of
size elements with each element initially set to None. size
must be greater than zero.
• length (): Returns the length or number of elements in the
array.
• getitem ( index ): Returns the value stored in the array at
element position index. The index argument must be within
the valid range. Accessed using the subscript operator.
• setitem ( index, value ): Modifies the contents of the array
element at position index to contain value. The index must
be within the valid range. Accessed using the subscript
operator.
• clearing( value ): Clears the array by setting every element
to value.
• iterator (): Creates and returns an iterator that can be used
to traverse the elements of the array.
Basic operations of Arrays
Array( size ):
Creates a one-dimensional array consisting of size elements with each
element initially set to None. size must be greater than zero.
length (): Returns the length or number of elements in the array.
getitem ( index )
Returns the value stored in the array at element position index. The
index argument must be within the valid range. Accessed using the
subscript operator.
setitem ( index, value )
Modifies the contents of the array element at position index to contain
value. The index must be within the valid range. Accessed using the
subscript operator.
clearing( value ) Clears the array by setting every element to value.
iterator ()
Creates and returns an iterator that can be used to traverse the elements
of the array.
The ctypes Module
• Many of the data types and classes available in Python are actually
implemented using appropriate types from the C language.
• While Python does not provide the array structure as part of the
language itself, it now includes the ctypes module as part of the
Python Standard Library.
• The ctypes module provides the capability to create hardware-
supported arrays just like the ones used to implement Python's
string, list, tuple, and dictionary collection types.
• But the ctypes module is not meant for everyday use in Python
programs.
• Thus, the technique provided by the module for creating an array
should not typically be used directly within a Python program.
• But we can use it within our Array class to provide the functionality
defined by the Array ADT.
Concept of Arrays
Syntax of Arrays
Creating an Array in Python
• In Python, arrays are different from lists; lists can have array
items of data types, whereas arrays can only have items of the
same data type.
• Python has a separate module for handling arrays called array,
which you need to import before you start working on them.
Ways to create Arrays
• You can declare an array in Python while initializing it using
the following syntax.
• Identifier: specify a name like
usually, you do for variables
• Module: Python has a special
module for creating arrays,
called "array" – you must
import it before using it
• Method: the array module has
a method for initializing the
array. It takes two arguments,
typecode, and elements.
• Type Code: specify the data
type using the typecodes
available.
• Elements: specify the array
elements within the square
brackets, for example
[130,450,103]
Accessing an Array value
Array Operations - Insertion
Array Operations- Deletion
Array Operations - Searching
Array Operations- Update
Array Operations - Traverse

Weitere ähnliche Inhalte

Was ist angesagt?

Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structureVardhil Patel
 
Unit 1 polynomial manipulation
Unit 1   polynomial manipulationUnit 1   polynomial manipulation
Unit 1 polynomial manipulationLavanyaJ28
 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in javaTalha mahmood
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVASAGARDAVE29
 
VCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxskilljiolms
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure NUPOORAWSARMOL
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesManishPrajapati78
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueFarhanum Aziera
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.CIIT Atd.
 
List Data Structure
List Data StructureList Data Structure
List Data StructureZidny Nafan
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm KristinaBorooah
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptxskilljiolms
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets Hitesh-Java
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | EdurekaEdureka!
 

Was ist angesagt? (20)

Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Unit 1 polynomial manipulation
Unit 1   polynomial manipulationUnit 1   polynomial manipulation
Unit 1 polynomial manipulation
 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in java
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 
Graph representation
Graph representationGraph representation
Graph representation
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
VCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptx
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
 
Linked list
Linked listLinked list
Linked list
 
Data_structure using C-Adi.pdf
Data_structure using C-Adi.pdfData_structure using C-Adi.pdf
Data_structure using C-Adi.pdf
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
 

Ähnlich wie Unit 1 array based implementation

Ähnlich wie Unit 1 array based implementation (20)

Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxQ-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptx
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
 
Week 11.pptx
Week 11.pptxWeek 11.pptx
Week 11.pptx
 
Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptx
 
Lesson 11 one dimensional array
Lesson 11 one dimensional arrayLesson 11 one dimensional array
Lesson 11 one dimensional array
 
java.pdf
java.pdfjava.pdf
java.pdf
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
linked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentslinked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate students
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Collections
CollectionsCollections
Collections
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
Java util
Java utilJava util
Java util
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
ArrayList class and useful methods.pptx
ArrayList class and useful methods.pptxArrayList class and useful methods.pptx
ArrayList class and useful methods.pptx
 

Mehr von LavanyaJ28

Cs1301 syllabus
Cs1301  syllabusCs1301  syllabus
Cs1301 syllabusLavanyaJ28
 
Ds important questions
Ds important questionsDs important questions
Ds important questionsLavanyaJ28
 
2 marks- DS using python
2 marks- DS using python2 marks- DS using python
2 marks- DS using pythonLavanyaJ28
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sortingLavanyaJ28
 
Heap types & Trees
Heap types & TreesHeap types & Trees
Heap types & TreesLavanyaJ28
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures LavanyaJ28
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures LavanyaJ28
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack LavanyaJ28
 
Stack and queue
Stack and queueStack and queue
Stack and queueLavanyaJ28
 
Unit 1 linked list
Unit 1 linked listUnit 1 linked list
Unit 1 linked listLavanyaJ28
 
Unit 1 Basic concepts to DS
Unit 1 Basic concepts to DSUnit 1 Basic concepts to DS
Unit 1 Basic concepts to DSLavanyaJ28
 
Unit 1 abstract data types
Unit 1 abstract data typesUnit 1 abstract data types
Unit 1 abstract data typesLavanyaJ28
 

Mehr von LavanyaJ28 (15)

Cs1301 syllabus
Cs1301  syllabusCs1301  syllabus
Cs1301 syllabus
 
Ds important questions
Ds important questionsDs important questions
Ds important questions
 
2 marks- DS using python
2 marks- DS using python2 marks- DS using python
2 marks- DS using python
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
Hashing
HashingHashing
Hashing
 
Graphs
GraphsGraphs
Graphs
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
Heap types & Trees
Heap types & TreesHeap types & Trees
Heap types & Trees
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Unit 1 linked list
Unit 1 linked listUnit 1 linked list
Unit 1 linked list
 
Unit 1 Basic concepts to DS
Unit 1 Basic concepts to DSUnit 1 Basic concepts to DS
Unit 1 Basic concepts to DS
 
Unit 1 abstract data types
Unit 1 abstract data typesUnit 1 abstract data types
Unit 1 abstract data types
 

Kürzlich hochgeladen

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 

Kürzlich hochgeladen (20)

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 

Unit 1 array based implementation

  • 1. UNIT 1- LINEAR DATA STRUCTURES ARRAY BASED IMPLEMENTATION
  • 2. Introduction • An Array is a collection of memory locations. • The memory locations cannot be split from each other, so if there is some empty space, it just goes waste. • Arrays cannot be interchanged. • A array is a collection of variables of same type.
  • 3. • Some points to be noted about an array: 1. It is a continuous chunk of memory with equally sized blocks. 2. The subscript always begins with ‘0’ and goes until ‘n-1’ which is also continuous. 3.Any memory location can be directly accessed using its subscript. 4. Static arrays have issues, such as memory wastage and memory leak, and also have constraints over the size. These are overcome by using dynamic arrays. 5. Since it is a continuous chunk of memory, it has internal issues such as fragmentation and memory leaks.
  • 4. Why do we study Arrays? • The array structure looks very similar to Python's list structure. • But there are two major differences between the array and the list. 1. array has a limited number of operations whereas Lists provides a large number of operations for working with the contents of the list. 2. lists can grow and shrink during execution as elements are added or removed while the size of an array cannot be changed after it has been created. • The array is best suited for problems requiring a sequence in which the maximum number of elements are known up front, whereas the list is the better choicewhen the size of the sequence needs to change after it has been created.
  • 5. Array Abstract Data Type • Definition: A one-dimensional array is a collection of contiguous elements in which individual elements are identified by a unique integer subscript starting with zero. Once an array is created, its size cannot be changed.
  • 6. • Array( size ): Creates a one-dimensional array consisting of size elements with each element initially set to None. size must be greater than zero. • length (): Returns the length or number of elements in the array. • getitem ( index ): Returns the value stored in the array at element position index. The index argument must be within the valid range. Accessed using the subscript operator. • setitem ( index, value ): Modifies the contents of the array element at position index to contain value. The index must be within the valid range. Accessed using the subscript operator. • clearing( value ): Clears the array by setting every element to value. • iterator (): Creates and returns an iterator that can be used to traverse the elements of the array.
  • 7. Basic operations of Arrays Array( size ): Creates a one-dimensional array consisting of size elements with each element initially set to None. size must be greater than zero. length (): Returns the length or number of elements in the array. getitem ( index ) Returns the value stored in the array at element position index. The index argument must be within the valid range. Accessed using the subscript operator. setitem ( index, value ) Modifies the contents of the array element at position index to contain value. The index must be within the valid range. Accessed using the subscript operator. clearing( value ) Clears the array by setting every element to value. iterator () Creates and returns an iterator that can be used to traverse the elements of the array.
  • 8. The ctypes Module • Many of the data types and classes available in Python are actually implemented using appropriate types from the C language. • While Python does not provide the array structure as part of the language itself, it now includes the ctypes module as part of the Python Standard Library. • The ctypes module provides the capability to create hardware- supported arrays just like the ones used to implement Python's string, list, tuple, and dictionary collection types. • But the ctypes module is not meant for everyday use in Python programs. • Thus, the technique provided by the module for creating an array should not typically be used directly within a Python program. • But we can use it within our Array class to provide the functionality defined by the Array ADT.
  • 11. Creating an Array in Python • In Python, arrays are different from lists; lists can have array items of data types, whereas arrays can only have items of the same data type. • Python has a separate module for handling arrays called array, which you need to import before you start working on them.
  • 12. Ways to create Arrays • You can declare an array in Python while initializing it using the following syntax.
  • 13. • Identifier: specify a name like usually, you do for variables • Module: Python has a special module for creating arrays, called "array" – you must import it before using it • Method: the array module has a method for initializing the array. It takes two arguments, typecode, and elements. • Type Code: specify the data type using the typecodes available. • Elements: specify the array elements within the square brackets, for example [130,450,103]
  • 15. Array Operations - Insertion
  • 17. Array Operations - Searching
  • 19. Array Operations - Traverse