1. 2  Introduction  Array Operations  Number of Elements in an array One-dimensional array Two dimensional array Multi-dimensional arrays Representation.

Slides:



Advertisements
Similar presentations
Tables and Information Retrieval
Advertisements

EC-211 DATA STRUCTURES LECTURE 2. EXISTING DATA STRUCTURES IN C/C++ ARRAYS – A 1-D array is a finite, ordered set of homogeneous elements – E.g. int a[100]
Introduction to arrays
Matrices CSE, POSTECH.
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Introduction to Graphs
Multidimensional Arrays in Java Vidhu S. Kapadia.
CS Data Structures Chapter 2 Arrays and Structures.
Arrays. 2 The array data structure An array is an indexed sequence of components Typically, the array occupies sequential storage locations The length.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Arrays. The array data structure An array is an indexed sequence of components –Typically, the array occupies sequential storage locations –The length.
Arrays. 2 The array data structure An array is an indexed sequence of components Typically, the array occupies sequential storage locations The length.
Introduction to Programming with C++ Fourth Edition
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
Chapter 8 Arrays and Strings
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
1 Week 12 Arrays, vectors, matrices and cubes. Introduction to Scientific & Engineering Computing 2 Array subscript expressions n Each subscript in an.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
COSC 1P03 Introduction to Data Structures 1.1 COSC 1P03  Audience  planning to major in COSC (prereq. 1P02 60%)  Lectures (AS202, AS217), labs (J301),
Chapter 2 ARRAYS.
Data Strcutures.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
1 Data Structures CSCI 132, Spring 2014 Lecture 32 Tables I.
Data Structures and Algorithms Lecture 3 Instructor: Quratulain Date: 8 th September, 2009.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
Working with Arrays in MATLAB
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C arrays ❏ To be able to pass arrays and array elements to functions.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
R EPRESENTING H IGHER D IMENSIONAL A RRAYS INTO A G ENERALIZED T WO - DIMENSIONAL A RRAY Authors K.M. Azharul Hasan Md Abu Hanif Shaikh Dept. of Computer.
CHP-4 QUEUE. 1.INTRODUCTION  A queue is a linear list in which elements can be added at one end and elements can be removed only at other end.  That.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Lab 3. Why Compressed Row Storage –A sparse matrix has a lot of elements of value zero. –Using a two dimensional array to store a sparse matrix wastes.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Data Structure and Algorithm: CIT231 Lecture 3: Arrays and ADT DeSiaMore DeSiaMorewww.desiamore.com/ifm1.
INTRODUCTION OF ARRAY. Topics To Be Discussed………………………. Introduction Types of array One Dimensional Array Internal representation of one-dimensional array.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such.
Arrays (Chapter 5)‏ Definition Applications One-Dimensional –Declaration –Initialization –Use Multidimensional.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
Arrays. C++ Style Data Structures: Arrays(1) An ordered set (sequence) with a fixed number of elements, all of the same type, where the basic operation.
1. Traversing a linear array Here A is a linear array with lower bound LB and upper bound UB. This algorithm traverses A applying an operation PROCESS.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
1 ARRAYS AND STRUCTURES. 2 Arrays Array: a set of index and value data structure For each index, there is a value associated with that index. representation.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Arrays. 1D Array Representation In C++ 1-dimensional array x = [a, b, c, d] map into contiguous memory locations Memory abcd start location(x[i]) = start.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture3.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
CHP - 9 File Structures.
Arrays.
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2002 Bin Sort, Radix.
CSCI N207 Data Analysis Using Spreadsheet
Arrays.
Arrays Week 2.
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2001 Bin Sort, Radix.
C++ Array 1.
Working with Arrays in MATLAB
Presentation transcript:

1

2  Introduction  Array Operations  Number of Elements in an array One-dimensional array Two dimensional array Multi-dimensional arrays Representation of Arrays in Memory One-dimensional array Two-dimensional arrays Three dimensional arrays N-dimensional array  Applications Sparse matrix Ordered lists ADT for arrays Outline

3  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.  Engineering applications usually involve large chunk of data (of common type)  Arrays provide easy and efficient concept for data storage or management  Arrays are usually processed through loops (processing is very common)  Arrays are accessed by indicating an address or index

4  Arrays could be of one-dimension, two dimension, three-dimension or in general multi-dimension. ◦ A[1:5] ◦ A[1:5, 1:3] ◦ A[1:3,2:4,5:6,…,a:n]  N dimension array: ◦ A[a 0 :b 0,a 1 :b 1,…,a n-1 :b n-1 ]

5  An array when viewed as a data structure supports only two operations: ◦ storage of values (i.e.) writing into an array (STORE (a, i, e) ) ◦ r etrieval of values (i.e.) reading from an array ( RETRIEVE (a, i) )

6  Or (array’s size), is essential “memory locations”  A[l : u] where l is the lower bound and u is the upper bound of the index range, the number of elements is given by (u – l + 1).  The size of one dimension array:  Upper bound – lower bound + 1  A[l1 : u1, l2:u2] has a size of (u1-l1+1) (u2-l2+1) elements

7

8  Calculate the size of the following arrays: ◦ A[1:10] ◦ A[-1:2] ◦ A[2:5,2:8] ◦ A[3:4,3:5,1:5]

9  The arrays are stored in memory in one of the two ways ◦ row major order or lexicographic order ◦ column major order.

10 One dimensional array

11  Given the address of the first element is (100), find ◦ In A[1:17] the address of A[7] ◦ In [-2:23] the address of A[16]  (106, 118)

12 Two dimensional array

13  Find : ◦ A[1:10,1:5] the address of A[8,3] ◦ A[-2:4,-6:10] the address of A[3,-5]  (257,306)

14 Three dimensional array

15  A[1:5,1:2,1:3] A[2,1,3]  A[-2:4,-6:10,1:3] A[-1,-4,2] ◦ (118,168)

16 N Dimensional arrays Let be an N-dimensional array. The address calculation for the retrieval of various elements are as given below:

17 Sparse Matrix  A matrix is a mathematical object which finds its applications in various scientific problems. A matrix is an arrangement of m X n elements arranged as m rows and n columns. The Sparse matrix is a matrix with zeros as the dominating elements. There is no precise definition for a sparse matrix. In other words, the “sparseness” is relatively defined  A matrix consumes a lot of space in memory. Thus, a 1000 X 1000 matrix needs 1 million storage locations in memory. Imagine the situation when the matrix is sparse! To store a handful of non-zero elements, voluminous memory is allotted and there by wasted!

18  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 A 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 3-tuples(that is 3 columns), the zeroth row viz. B[0,1], B[0,2] and B[0,3] record the number of non- zero elements of the original sparse matrix A.

19  One of the simplest and 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. Ordered lists

20  Given the following for the array RES. Find the address of RES[17]. ◦ Base address 520 ◦ Index of range 1:20 ◦ Array typeReal ◦ Size of memory location 4 bytes  For the following array B compute: ◦ The dimension of B ◦ The space occupied by B in the memory ◦ The address of B[7,2] ◦ Array B Column index 0:5 ◦ Base address 1003 ◦ Size of the memory location 4 bytes ◦ Row index 0:15

21 ADT for Arrays Data objects: A set of elements of the same type stored in a sequence Operations:  Store value VAL in the i th element of the array ARRAY ARRAY[i] = VAL  Retrieve the value in the i th element of array ARRAY as VAL = ARRAY[i]