SlideShare a Scribd company logo
LECTURE 2: DATA STRUCTURES
An array is a data structure consisting of a group of
elements that are accessed by indexing.
An array is a situation where a set of data items are
conveniently arranged into a sequence & referred to by
a single identifier.
 Each data item of an array is known as an element &
the elements are referenced by a common name
known as the array name
An array is a collection of objects of the same data
type, allocated contiguously in memory. Individual
objects in an array, called elements, are accessed by
their position in the array.
AN ARRAY
The position is given by an index, which is also
called a subscript.
An array facilitates the coding of repetitive
tasks by allowing the statements executed on
each element to be put into a loop that iterates
through each element in the array.
An array, also known as a vector or list (for
one-dimensional arrays) or a matrix (for two-
dimensional arrays)
ARRAYS
An Array is a variable.
It can hold a series of values, essentially, a list of
values.
An array provides the logical convenience of being
able to reference all its values by using the single
array name.
As a variable, an array is an area in memory,
random access memory (RAM) reserved under a
name, and referred to by name, into which values
can be assigned.
ARRAYS
An array is a structure that holds multiple
values of the same type.
 An array - known as a vector or list (for one-
dimensional arrays) or a matrix (for two-
dimensional arrays)
It is one of the simplest data structures.
Examples
E.g. Cartoons = (Popeye, Scooby Doo, Tom &
Jerry)
Data Structures = (Stacks, Queues, List)
Individual data items are referred to by stating
their position e.g. Cartoons [1] is Popeye
An array is a structure containing one or more
subdivisions each of which may contain data
TYPES OF ARRAYS
One Dimensional Array
Two Dimensional Array
a) One Dimensional Array
Within the array, subscripts are used to
indicate the individual elements, written as
integers within square brackets.
195.00 491.82 299.95 320.00
Thus credit [1] would be the first deposit in the
checking account; credit [2] would be the
second deposit and so on.
Credit Array:
[195.00] [491.82] [299.95] [320.00]
Debit Array:
14.79 52.25 44.7516.13
One Dimensional Array
The above diagrams shows a credit and
Debit Array in which
Credit [1] = 195.00, Credit [2] = 491.82
Credit [3] = 299.95
Similarly, Debit [1] =14.79, Debit [2] =52.25,
Debit [3] =16.13, Debit [4] =44.75, Debit [5]
= 114.21
One Dimensional Array
They have a single subscript and are called
one-dimensional arrays; often thought of
as lists.
In mathematics such arrays are often called
vectors.
A one dimensional array is therefore an
array having only one subscript & the
individual elements are of the same type.
EXAMPLE 2
To store the salaries of up to 50 employees in a
firm we can use an array called salary in which
salary [1], salary [2] … salary [50] are real
variables that will store the salaries of the first
employee, the second employee…up to the 50th
employee.
The array contains real elements and the
subscripts run over the integer sub range
[1………50].
b) Two Dimensional Array
A two dimensional array is a generalization of a
linear list, for example an m x n matrix.
The rows and column list essentially account
for two dimensional structure of a matrix.
An array contains a sequence of elements all of
the same element type.
 The element type can be any type, even an
array (but not the same array), thus we have an
array of arrays
EXAMPLE
c0 c1 c2 c3
r0 0 1 2 3
r1 1 2 3 4
r2 2 3 4 5
r3 3 4 5 6
r4 4 5 6 7
EXAMPLE
Here, we have an array with five rows and
four columns.
 It has twenty total elements.
 However we say it has dimension five by
four, not dimension twenty
EXAMPLE
We have a pay array containing 50 rows with 26
real elements on each row. Each row represents an
employee and each column a pay period i.e. ( a
two – dimensional array ).
Pay [1,1]Pay [1,2] Pay [1,3] ……Pay [1, 26]
Pay [2,1]Pay [2,2] Pay [2,3] ……Pay [2, 26]
Pay [3,1]Pay [3,2] Pay [3,3] ……Pay [3, 26]
: : : : :
Pay [50,1]Pay [50,2] Pay[50,3]………………………
Pay [50,26]
c) Parallel Arrays
As an application of one dimensional array, we
begin the construction of a payroll program to
read and display employees’ salaries for a small
business e.g.
Enter employees’ ID numbers and salaries
Employee # 1
ID Number: 11111
Salary: 222.22
Contd...
 Employee # 2
ID Number: 11112
Salary: 333.33

Employee # 3
ID Number: 11113
Salary: 444.44
Etc.
Example
The program will need to store a two – part
record for each employee, containing both the
integer employee number & ID– number salary.
An employee record is therefore
heterogeneous & cannot be stored entirely in
one array.
Instead we will use a pair of arrays, ID & salary
which are said to be parallel arrays, because
their subscripts track together: i.e. salary [I] & ID
[I] together make up the data record for the 1st
employee.
Example
Salary [1] Salary [2] Salary [3]
Example
ID [1] Salary [2] Salary [3]
Question
Class, What are the
Components of an
Array???
COMPONENTS OF AN ARRAY
An array consists of elements, data type,
subscript & the square brackets.
Arrays hold a series of data elements, usually
of the same size & data type.
The series could be of data types such as
integers, strings or even floats.
COMPONENTS OF AN ARRAY
Individual elements are accessed by their
position in the array.
The position is given by an index, which is
also called a subscript.
The index usually uses a consecutive range
of integers
CHARACTERISTICS OF ARRAYS
Homogeneous: They store one type of data
elements.
Cartesian: Arrays allow their access through
an index. This referencing is possible because
arrays have subscripts and elements that
enable access via index
CHARACTERISTICS OF ARRAYS
Subscripts: In Pascal the subscripts are
written as integers within square brackets thus
credit [1] would be the first deposit in the
checking account, credit [2] would be the
second deposit and so on.
Example
[1] = 195.00 and credit [2] = 491.82
Similarly,
Debit [1] = 14.79, debit [2] = 52.25
Credit array 195.00 491.82 299.95 320.27
Debit array 14.79 52.25 16.13 44.75
CHARACTERISTICS OF ARRAYS
We use subscripts to access the individual elements i.e.
in a one-dimensional array, it has only one subscript & is
imagined as a list or vector.
The elements are stored in sequence in memory
beginning with the address of the lowest-subscripted
element.
 A two dimensional array has two subscripts & is
imagined as a table with rows & columns.
Form the basis for several more complex data
structures, e.g. hash tables, stacks and
queues.
Arrays provide a very special way of sorting or
organising data in a computers memory
Arrays serves as parameters in computation
Arrays help reduce length of algorithm
FUNCTIONS OF ARRAYS
OPERATIONS ON ARRAYS
Creating an array: The create function produces a
new, empty array of the appropriate size.
 Assigning the array: Once an array has been
created a value from a field or variable, is then
assigned to an element of the array. The syntax
used is:
Array name {element number}:= value. Array
elements are numbered by their position in the
array, starting at one and going up.
Additionally, every array has zero element number.
OPERATIONS ON ARRAYS
Retrieving : Retrieve operation accepts an
array and an index.
This returns the value associated if the index is
valid, or error if the index is invalid.
Searching : Searching methods are designed
to take advantage of the organization of
information & thereby reduce the amount of
effort to either locate a particular item or to
establish that it is not present in a data set.
OPERATIONS ON ARRAYS
Sorting and Merging: Sorting & merging
provide us with a means of organizing
information to facilitate the retrieval of specific
data.
Field or variable: = array name {element
number}
OPERATIONS ON ARRAYS
Displaying arrays: To display the contents of
array on a form, you simply give an active
object capable of displaying an array
The contents of the array will then automatically
be displayed in that object. The objects that can
display the contents of an array are: Pop-up
Lists/Drop-down Lists, and Combo Boxes.
AN EXAMPLE????
APPLICATION OF ARRAYS
CLASS DISCUSSION
ADVANTAGES OF ARRAYS
Arrays permit efficient random access in
constant time making them most appropriate for
storing a fixed amount of data which will be
accessed in an unpredictable fashion.
 This means that the time taken to access a[i] is
the same for each index.
 Iterating through an array has good locality of
reference, and so is much faster than iterating
through a linked list of the same size, which
tends to jump around in memory.
ADVANTAGES OF ARRAYS
Compact data structures; storing 100 integers
in an array takes only 100 times the space
required to store an integer, takes no additional
storage space.
Arrays simplify algorithms by compressing
repetitive iterations, as they perform
computations on collections of data with
common attribute.
DISADVANTAGES OF ARRAYS
It has a single fixed size
Therefore, there are some indexes which refer
to invalid elements, e.g., the index 17 in an
array of size 5.
This brings range error, since it is difficult to
allow a subscript to reach a value outside its
declared range, as this will make a compiler to
generate an error.
DISADVANTAGES OF ARRAYS
Multidimensional arrays cannot be accessed by
simple indexing & these incur additional
overheads in programming its access.
For a large number of programming languages,
except for Java, the array sizes must be known
at compile time, since once space is allocated it
cannot be extended, as there is no guarantee
that the next block of memory will be free at
some time later in the execution making arrays
static data structures.
REFERENCES
Encyclopedia of Computer Science (3rd
Ed) (1993) Edited
by Ralston, A and Reilly E. D. London: Chapman and Hall
French, C. S. (1996) Computer Science. 5th
ed. London:
Book Power
Megson, G.M. (1992) An Introduction to Systolic Algorithm
Design. Oxford: Clarendon
Salmon, W. I. (1991) Structures and Abstractions: An
introduction to Computer Science with Pascal. Boston.
Irwin Inc.
Society Schools Committee (1998) A glossary of
Computing terms (9th
ed.) England: Longman
Williams, P.M. (2004) Data Structures. Sussex: University
of Sussex Computer Science and Artificial Intelligence.
http:/developer.sun.com
www.answers.com/topic/arrays
Ad

More Related Content

What's hot (20)

Linked list
Linked listLinked list
Linked list
RahulGandhi110
 
Binary tree
Binary  treeBinary  tree
Binary tree
Vanitha Chandru
 
Unit 4-booth algorithm
Unit 4-booth algorithmUnit 4-booth algorithm
Unit 4-booth algorithm
vishal choudhary
 
Parallel algorithms
Parallel algorithms Parallel algorithms
Parallel algorithms
Dr Shashikant Athawale
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
Er. Nawaraj Bhandari
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
chauhankapil
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
chauhankapil
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Array ppt
Array pptArray ppt
Array ppt
Kaushal Mehta
 
Trees
TreesTrees
Trees
Burhan Ahmed
 
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
Vardhil Patel
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Control Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitControl Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unit
abdosaidgkv
 
Auxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptxAuxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptx
Ramakrishna Reddy Bijjam
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
Meherul1234
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
Dr Shashikant Athawale
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
chauhankapil
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
chauhankapil
 
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
Vardhil Patel
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Control Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitControl Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unit
abdosaidgkv
 
Auxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptxAuxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptx
Ramakrishna Reddy Bijjam
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
Meherul1234
 

Viewers also liked (20)

Lecture 2 data structures & algorithms - sorting techniques
Lecture 2  data structures & algorithms - sorting techniquesLecture 2  data structures & algorithms - sorting techniques
Lecture 2 data structures & algorithms - sorting techniques
Dharmendra Prasad
 
Data Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedData Structures- Part9 trees simplified
Data Structures- Part9 trees simplified
Abdullah Al-hazmy
 
Data Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesData Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queues
Abdullah Al-hazmy
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
Abdullah Al-hazmy
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
Nikhil Pandit
 
Data Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithmsData Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithms
Abdullah Al-hazmy
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Lecture 3  data structures & algorithms - sorting techniques - http://techiem...Lecture 3  data structures & algorithms - sorting techniques - http://techiem...
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Dharmendra Prasad
 
Lecture 2c stacks
Lecture 2c stacksLecture 2c stacks
Lecture 2c stacks
Victor Palmar
 
Arrays
ArraysArrays
Arrays
Trupti Agrawal
 
Chap01
Chap01Chap01
Chap01
Terry Yoast
 
9781285852744 ppt ch16
9781285852744 ppt ch169781285852744 ppt ch16
9781285852744 ppt ch16
Terry Yoast
 
9781111530532 ppt ch14
9781111530532 ppt ch149781111530532 ppt ch14
9781111530532 ppt ch14
Terry Yoast
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
Hock Leng PUAH
 
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
Amazon Web Services Korea
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
Raghuveer Guthikonda
 
Applying Design Patterns in Practice
Applying Design Patterns in PracticeApplying Design Patterns in Practice
Applying Design Patterns in Practice
Ganesh Samarthyam
 
AWS ECS Quick Introduction
AWS ECS Quick IntroductionAWS ECS Quick Introduction
AWS ECS Quick Introduction
Vinothini Raju
 
Web Database
Web DatabaseWeb Database
Web Database
idroos7
 
Lecture 2 data structures & algorithms - sorting techniques
Lecture 2  data structures & algorithms - sorting techniquesLecture 2  data structures & algorithms - sorting techniques
Lecture 2 data structures & algorithms - sorting techniques
Dharmendra Prasad
 
Data Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedData Structures- Part9 trees simplified
Data Structures- Part9 trees simplified
Abdullah Al-hazmy
 
Data Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesData Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queues
Abdullah Al-hazmy
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
Abdullah Al-hazmy
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Data Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithmsData Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithms
Abdullah Al-hazmy
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Lecture 3  data structures & algorithms - sorting techniques - http://techiem...Lecture 3  data structures & algorithms - sorting techniques - http://techiem...
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Dharmendra Prasad
 
9781285852744 ppt ch16
9781285852744 ppt ch169781285852744 ppt ch16
9781285852744 ppt ch16
Terry Yoast
 
9781111530532 ppt ch14
9781111530532 ppt ch149781111530532 ppt ch14
9781111530532 ppt ch14
Terry Yoast
 
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
Amazon Web Services Korea
 
Applying Design Patterns in Practice
Applying Design Patterns in PracticeApplying Design Patterns in Practice
Applying Design Patterns in Practice
Ganesh Samarthyam
 
AWS ECS Quick Introduction
AWS ECS Quick IntroductionAWS ECS Quick Introduction
AWS ECS Quick Introduction
Vinothini Raju
 
Web Database
Web DatabaseWeb Database
Web Database
idroos7
 
Ad

Similar to Lecture 2a arrays (20)

DSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notes
swathirajstar
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptxChyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
RobertCarreonBula
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
dplunkett
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
researchgrad82
 
Arrays
ArraysArrays
Arrays
swathi reddy
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
lakshmanarao027MVGRC
 
U2.pptx Advanced Data Structures and Algorithms
U2.pptx Advanced Data Structures and AlgorithmsU2.pptx Advanced Data Structures and Algorithms
U2.pptx Advanced Data Structures and Algorithms
snehalkulkarni78
 
Java arrays (1)
Java arrays (1)Java arrays (1)
Java arrays (1)
Liza Abello
 
Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)
Abbott
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
Abbott
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
LATHA LAKSHMI
 
Arrays in c
Arrays in cArrays in c
Arrays in c
Jeeva Nanthini
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Malikireddy Bramhananda Reddy
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
SivaSankar Gorantla
 
Arrays
ArraysArrays
Arrays
Chirag vasava
 
ppt on arrays in c programming language.pptx
ppt on arrays in c programming language.pptxppt on arrays in c programming language.pptx
ppt on arrays in c programming language.pptx
AmanRai352102
 
Array
ArrayArray
Array
Rokonuzzaman Rony
 
Arrays
ArraysArrays
Arrays
ViniVini48
 
DSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notes
swathirajstar
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptxChyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
RobertCarreonBula
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
dplunkett
 
U2.pptx Advanced Data Structures and Algorithms
U2.pptx Advanced Data Structures and AlgorithmsU2.pptx Advanced Data Structures and Algorithms
U2.pptx Advanced Data Structures and Algorithms
snehalkulkarni78
 
Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)
Abbott
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
Abbott
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
LATHA LAKSHMI
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Malikireddy Bramhananda Reddy
 
ppt on arrays in c programming language.pptx
ppt on arrays in c programming language.pptxppt on arrays in c programming language.pptx
ppt on arrays in c programming language.pptx
AmanRai352102
 
Ad

Lecture 2a arrays

  • 1. LECTURE 2: DATA STRUCTURES An array is a data structure consisting of a group of elements that are accessed by indexing. An array is a situation where a set of data items are conveniently arranged into a sequence & referred to by a single identifier.  Each data item of an array is known as an element & the elements are referenced by a common name known as the array name An array is a collection of objects of the same data type, allocated contiguously in memory. Individual objects in an array, called elements, are accessed by their position in the array.
  • 2. AN ARRAY The position is given by an index, which is also called a subscript. An array facilitates the coding of repetitive tasks by allowing the statements executed on each element to be put into a loop that iterates through each element in the array. An array, also known as a vector or list (for one-dimensional arrays) or a matrix (for two- dimensional arrays)
  • 3. ARRAYS An Array is a variable. It can hold a series of values, essentially, a list of values. An array provides the logical convenience of being able to reference all its values by using the single array name. As a variable, an array is an area in memory, random access memory (RAM) reserved under a name, and referred to by name, into which values can be assigned.
  • 4. ARRAYS An array is a structure that holds multiple values of the same type.  An array - known as a vector or list (for one- dimensional arrays) or a matrix (for two- dimensional arrays) It is one of the simplest data structures.
  • 5. Examples E.g. Cartoons = (Popeye, Scooby Doo, Tom & Jerry) Data Structures = (Stacks, Queues, List) Individual data items are referred to by stating their position e.g. Cartoons [1] is Popeye An array is a structure containing one or more subdivisions each of which may contain data
  • 6. TYPES OF ARRAYS One Dimensional Array Two Dimensional Array
  • 7. a) One Dimensional Array Within the array, subscripts are used to indicate the individual elements, written as integers within square brackets. 195.00 491.82 299.95 320.00 Thus credit [1] would be the first deposit in the checking account; credit [2] would be the second deposit and so on.
  • 10. One Dimensional Array The above diagrams shows a credit and Debit Array in which Credit [1] = 195.00, Credit [2] = 491.82 Credit [3] = 299.95 Similarly, Debit [1] =14.79, Debit [2] =52.25, Debit [3] =16.13, Debit [4] =44.75, Debit [5] = 114.21
  • 11. One Dimensional Array They have a single subscript and are called one-dimensional arrays; often thought of as lists. In mathematics such arrays are often called vectors. A one dimensional array is therefore an array having only one subscript & the individual elements are of the same type.
  • 12. EXAMPLE 2 To store the salaries of up to 50 employees in a firm we can use an array called salary in which salary [1], salary [2] … salary [50] are real variables that will store the salaries of the first employee, the second employee…up to the 50th employee. The array contains real elements and the subscripts run over the integer sub range [1………50].
  • 13. b) Two Dimensional Array A two dimensional array is a generalization of a linear list, for example an m x n matrix. The rows and column list essentially account for two dimensional structure of a matrix. An array contains a sequence of elements all of the same element type.  The element type can be any type, even an array (but not the same array), thus we have an array of arrays
  • 14. EXAMPLE c0 c1 c2 c3 r0 0 1 2 3 r1 1 2 3 4 r2 2 3 4 5 r3 3 4 5 6 r4 4 5 6 7
  • 15. EXAMPLE Here, we have an array with five rows and four columns.  It has twenty total elements.  However we say it has dimension five by four, not dimension twenty
  • 16. EXAMPLE We have a pay array containing 50 rows with 26 real elements on each row. Each row represents an employee and each column a pay period i.e. ( a two – dimensional array ). Pay [1,1]Pay [1,2] Pay [1,3] ……Pay [1, 26] Pay [2,1]Pay [2,2] Pay [2,3] ……Pay [2, 26] Pay [3,1]Pay [3,2] Pay [3,3] ……Pay [3, 26] : : : : : Pay [50,1]Pay [50,2] Pay[50,3]……………………… Pay [50,26]
  • 17. c) Parallel Arrays As an application of one dimensional array, we begin the construction of a payroll program to read and display employees’ salaries for a small business e.g. Enter employees’ ID numbers and salaries Employee # 1 ID Number: 11111 Salary: 222.22
  • 18. Contd...  Employee # 2 ID Number: 11112 Salary: 333.33  Employee # 3 ID Number: 11113 Salary: 444.44 Etc.
  • 19. Example The program will need to store a two – part record for each employee, containing both the integer employee number & ID– number salary. An employee record is therefore heterogeneous & cannot be stored entirely in one array. Instead we will use a pair of arrays, ID & salary which are said to be parallel arrays, because their subscripts track together: i.e. salary [I] & ID [I] together make up the data record for the 1st employee.
  • 20. Example Salary [1] Salary [2] Salary [3]
  • 21. Example ID [1] Salary [2] Salary [3]
  • 22. Question Class, What are the Components of an Array???
  • 23. COMPONENTS OF AN ARRAY An array consists of elements, data type, subscript & the square brackets. Arrays hold a series of data elements, usually of the same size & data type. The series could be of data types such as integers, strings or even floats.
  • 24. COMPONENTS OF AN ARRAY Individual elements are accessed by their position in the array. The position is given by an index, which is also called a subscript. The index usually uses a consecutive range of integers
  • 25. CHARACTERISTICS OF ARRAYS Homogeneous: They store one type of data elements. Cartesian: Arrays allow their access through an index. This referencing is possible because arrays have subscripts and elements that enable access via index
  • 26. CHARACTERISTICS OF ARRAYS Subscripts: In Pascal the subscripts are written as integers within square brackets thus credit [1] would be the first deposit in the checking account, credit [2] would be the second deposit and so on. Example [1] = 195.00 and credit [2] = 491.82 Similarly, Debit [1] = 14.79, debit [2] = 52.25 Credit array 195.00 491.82 299.95 320.27 Debit array 14.79 52.25 16.13 44.75
  • 27. CHARACTERISTICS OF ARRAYS We use subscripts to access the individual elements i.e. in a one-dimensional array, it has only one subscript & is imagined as a list or vector. The elements are stored in sequence in memory beginning with the address of the lowest-subscripted element.  A two dimensional array has two subscripts & is imagined as a table with rows & columns.
  • 28. Form the basis for several more complex data structures, e.g. hash tables, stacks and queues. Arrays provide a very special way of sorting or organising data in a computers memory Arrays serves as parameters in computation Arrays help reduce length of algorithm FUNCTIONS OF ARRAYS
  • 29. OPERATIONS ON ARRAYS Creating an array: The create function produces a new, empty array of the appropriate size.  Assigning the array: Once an array has been created a value from a field or variable, is then assigned to an element of the array. The syntax used is: Array name {element number}:= value. Array elements are numbered by their position in the array, starting at one and going up. Additionally, every array has zero element number.
  • 30. OPERATIONS ON ARRAYS Retrieving : Retrieve operation accepts an array and an index. This returns the value associated if the index is valid, or error if the index is invalid. Searching : Searching methods are designed to take advantage of the organization of information & thereby reduce the amount of effort to either locate a particular item or to establish that it is not present in a data set.
  • 31. OPERATIONS ON ARRAYS Sorting and Merging: Sorting & merging provide us with a means of organizing information to facilitate the retrieval of specific data. Field or variable: = array name {element number}
  • 32. OPERATIONS ON ARRAYS Displaying arrays: To display the contents of array on a form, you simply give an active object capable of displaying an array The contents of the array will then automatically be displayed in that object. The objects that can display the contents of an array are: Pop-up Lists/Drop-down Lists, and Combo Boxes. AN EXAMPLE????
  • 34. ADVANTAGES OF ARRAYS Arrays permit efficient random access in constant time making them most appropriate for storing a fixed amount of data which will be accessed in an unpredictable fashion.  This means that the time taken to access a[i] is the same for each index.  Iterating through an array has good locality of reference, and so is much faster than iterating through a linked list of the same size, which tends to jump around in memory.
  • 35. ADVANTAGES OF ARRAYS Compact data structures; storing 100 integers in an array takes only 100 times the space required to store an integer, takes no additional storage space. Arrays simplify algorithms by compressing repetitive iterations, as they perform computations on collections of data with common attribute.
  • 36. DISADVANTAGES OF ARRAYS It has a single fixed size Therefore, there are some indexes which refer to invalid elements, e.g., the index 17 in an array of size 5. This brings range error, since it is difficult to allow a subscript to reach a value outside its declared range, as this will make a compiler to generate an error.
  • 37. DISADVANTAGES OF ARRAYS Multidimensional arrays cannot be accessed by simple indexing & these incur additional overheads in programming its access. For a large number of programming languages, except for Java, the array sizes must be known at compile time, since once space is allocated it cannot be extended, as there is no guarantee that the next block of memory will be free at some time later in the execution making arrays static data structures.
  • 38. REFERENCES Encyclopedia of Computer Science (3rd Ed) (1993) Edited by Ralston, A and Reilly E. D. London: Chapman and Hall French, C. S. (1996) Computer Science. 5th ed. London: Book Power Megson, G.M. (1992) An Introduction to Systolic Algorithm Design. Oxford: Clarendon Salmon, W. I. (1991) Structures and Abstractions: An introduction to Computer Science with Pascal. Boston. Irwin Inc. Society Schools Committee (1998) A glossary of Computing terms (9th ed.) England: Longman Williams, P.M. (2004) Data Structures. Sussex: University of Sussex Computer Science and Artificial Intelligence. http:/developer.sun.com www.answers.com/topic/arrays
  翻译: