Professional Documents
Culture Documents
@ McGraw-Hill Education
Copyrighted Material -Additional resource material supplied with the book Data Structures and Algorithms : Concepts, Techniques and Applications authored by G.A.V. Pai and published by
Tata McGraw Hill. This resource material is for Instructor's use only.
Arrays
(Chapter 3)
PROPRIETARY MATERIAL. 2008 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.
Outline of Chapter 3
1. Introduction
Definition
Array Operations
Number of Elements in an array
One-dimensional array
Two dimensional array
Multi-dimensional arrays
2. Representation of Arrays in Memory
One-dimensional array
Two-dimensional arrays
N-dimensional array
3. Applications
Sparse matrix
Ordered lists
1. Introduction
Definition of Array
An array is an ADT whose objects are
sequence of elements of the same type and
the two operations performed on it are
store and retrieve.
Data
values
of type:
int
10 9
Ref: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
Array Dimensions
Arrays could be of
one-dimension,
two dimension,
three-dimension or
in general multidimension.
This is reflected by
the number of
index ranges
Examples:
Grades[i] - 1-dim
Table[i] [j] - 2-dim
Bus[i] [j] [k] - 3-dim
1-dim array
2-dim array
(STORE
(a, i, e))
retrieval
of values (i.e.) reading from an array
For (i=0;
i<10;
i++)
10
Exercises
1.
11
12
l=0
u=9
13
14
2. Representation of Arrays
in Memory
15
Column-major
Row-major
16
17
18
19
N Dimensional arrays
Let be an N-dimensional array. The address calculation for the
retrieval of various elements are as given below:
20
3. Applications
21
A Matrix is :
22
23
Sparse matrix
To save valuable storage space,
we resort to a 3-tuple representation viz., (i, j, value) to
represent each non-zero element of the sparse matrix.
In other words,
a sparse matrix is represented by another matrix B[0:t,
1:3] with t+1 rows and 3 columns.
Here t refers to the number of non-zero elements in the
sparse matrix.
While rows 1 to t record the details pertaining to the non-zero
elements as triple(that is 3 columns), the zeroth row viz.
B[0,1]=no of rows of the original sparse matrix A ,
B[0,2]=no of columns of the original sparse matrix A
and B[0,3] record the number of non-zero elements.
24
Sparse matrix
This 6X6 matrix can
be represented by
3X3 matrix
T3[1:6,1:6]
10
Col
Value
Row
25
useful data
objects in computer science is an ordered
list or linear list.
An ordered list can be either empty
or non empty.
In the latter case, the elements of the
list are known as atoms, chosen from a
set D.
The ordered lists provide a variety of
operations such as retrieval, insertion,
deletion, update etc.
The most common way to represent an
ordered list is by using a one-dimensional
array.
Such a representation is termed
sequential mapping through better forms
of representation have been presented in
the literature.
26
Example:
Week[1:7]=(sun,mon,tue,sat, , , )
Insert (wed)-> week[1:7]=(sun,mon,tue,wed,sat, , )
Delete (sat) -> week[1:7]=(sun,mon,tue,wed, , , )
27
28
29
30
31
Reviews
32
On Arrays:
http://www.ibm.com/developerworks/library/
j-arrays/index.html
On Java Collections:
http://docs.oracle.com/javase/1.3/docs/guide/
collections/reference.html
33
@ McGraw-Hill Education
Copyrighted Material -Additional resource material supplied with the book Data Structures and Algorithms : Concepts, Techniques and Applications authored by G.A.V. Pai and published by
Tata McGraw Hill. This resource material is for Instructor's use only.
End of
Arrays
(Chapter 3)
PROPRIETARY MATERIAL. 2008 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.