CS235102 Data Structures Chapter 2 Arrays and Structures.

Slides:



Advertisements
Similar presentations
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Advertisements

Senem KUMOVA METİN CS FALL 1 ARRAYS && SORTING && STRINGS CHAPTER 6 cont.
Multidimensional Arrays Arrays with more than one dimension are called multidimensional arrays. Human cannot easily visualize more than three dimension.
Multidimensional arrays Many problems require information be organized as a two- dimensional or multidimensional list Examples –Matrices –Graphical animation.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
1 2-D Arrays Overview l Why do we need Multi-dimensional array l 2-D array declaration l Accessing elements of a 2-D array l Declaration using Initializer.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
1 CS 201 Array Debzani Deb. 2 Having trouble linking math.h? Link with the following option gcc –lm –o test test.o.
C# Programming: From Problem Analysis to Program Design1 Advanced Collections C# Programming: From Problem Analysis to Program Design 3 rd Edition 8.
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
Chapter 8 Multidimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
Chapter 2 Arrays and Structures  The array as an abstract data type  Structures and Unions  The polynomial Abstract Data Type  The Sparse Matrix Abstract.
Data Strcutures.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
Arrays. An array is a group of like-typed variables that are referred to by a common name. Arrays of any type can be created and may have one or more.
Arrays & Vectors Week 5. The simplest form of the multidimensional array is the two-dimensional array. A two- dimensional array is, in essence, a list.
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 overview This chapter focuses on Array declaration and use Bounds checking and capacity Arrays storing object references Variable length parameter.
Working with Arrays in MATLAB
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
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.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley More About Array Processing 8.2 There Are Many Uses of Arrays and Many Programming.
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.
CSCI 130 More on Arrays. Multi-dimensional Arrays Multi - Dimensional arrays: –have more than one subscript –can be directly initialized –can be initialized.
An Object-Oriented Approach to Programming Logic and Design Chapter 8 Advanced Array Concepts.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
1. 2  Introduction  Array Operations  Number of Elements in an array One-dimensional array Two dimensional array Multi-dimensional arrays Representation.
ECE 103 Engineering Programming Chapter 23 Multi-Dimensional Arrays Herbert G. Mayer, PSU CS Status 6/24/2014 Initial content copied verbatim from ECE.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Opening Input/Output Files ifstream infile; ofstream outfile; char inFileName[40]; char outFileName[40]; coutinFileName;
Two-Dimensional Arrays. Two-dimensional arrays variables store the contents of tables or matrices. Example: Dim arrTable(1 to 5, 1 to 5) As Integer first.
Multidimensional Arrays Vectors of Vectors When One Is Not Enough.
Using a Pointer as an Array Name C allows us to subscript a pointer as though it were an array name Here's an example: #define N 100 int a[N], i, sum =0,
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
 Introducing Arrays  Declaring Array Variables, Creating Arrays, and Initializing Arrays  Copying Arrays  Multidimensional Arrays  Search and Sorting.
© 2006 Pearson Addison-Wesley. All rights reserved Arrays of Greater Dimension One-dimensional arrays are linear containers. Multi-dimensional Arrays.
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.
ADVANCED POINTERS. Overview Review on pointers and arrays Common troubles with pointers Multidimensional arrays Pointers as function arguments Functions.
Multi-dimensional Array 1 Multi-dimensional array refers to an array with more than one index. It is a logical representation. On physical storage, the.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
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.
CS 201 Tarik Booker California State University, Los Angeles.
Chapter 4 Section 1 Organizing Data into Matrices.
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
◦ A one-dimensional array in C is declared implicitly by appending brackets to the name of a variable int list[5], *plist[5]; ◦ arrays start at index.
1 Multidimensional Arrays Chapter 13 2 The plural of mongoose starts with a "p" Initializing a multidimensional array Processing by.
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.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
Chapter 8 Arrays and the ArrayList Class Multi-Dimensional Arrays.
Two-Dimensional Arrays
Data Structures Unit-2 Engineered for Tomorrow CSE, MVJCE.
Multidimensional Arrays
Data Structures – 2D Lists
Multidimensional array
Multidimensional Arrays
CS2011 Introduction to Programming I Multidimensional Arrays
Presentation transcript:

CS Data Structures Chapter 2 Arrays and Structures

2.5 Representation of multidimensional array (1/5)  The internal representation of multidimensional arrays requires more complex addressing formula.  If an array is declared a[upper 0 ][upper 1 ]…[upper n ], then it is easy to see that the number of elements in the array is: Where  is the product of the upper i ’s. Where  is the product of the upper i ’s.  Example:  If we declare a as a[10][10][10], then we require 10*10*10 = 1000 units of storage to hold the array.

2.5 Representation of multidimensional array (2/5)  Represent multidimensional arrays: row major order and column major order.  Row major order stores multidimensional arrays by rows.  A[upper 0 ][upper 1 ] as upper 0 rows, row 0, row 1, …, row upper0-1, each row containing upper1 elements.

2.5 Representation of multidimensional array (3/5)   Row major order:A[i][j] :  + i*upper 1 + j   Column major order:A[i][j] :  + j*upper 0 + i col 0 col 1 col u1-1 row 0 A[0][0]A[0][1]...A[0][u1-1]  + u 0  +(u 1 -1)* u 0 row 1 A[1][0]A[1][1]...A[1][u1-1]  + u 1... row u0-1 A[u0-1][0]A[u0-1][1]...A[u0-1][u1-1]  +(u 0 -1)*u 1

2.5 Representation of multidimensional array (4/5)  To represent a three-dimensional array, A[upper 0 ][upper 1 ][upper 2 ], we interpret the array as upper 0 two-dimensional arrays of dimension upper 1  upper 2.  To locate a[i][j][k], we first obtain  + i*upper 1 * upper 2 as the address of a[i][0][0] because there are i two dimensional arrays of size upper 1 *upper 2 preceding this element.   + i*upper 1 *upper 2 +j *upper 2 +k as the address of a[i][j][k]. as the address of a[i][j][k].

2.5 Representation of multidimensional array (5/5)  Generalizing on the preceding discussion, we can obtain the addressing formula for any element A[i 0 ][i 1 ]…[i n-1 ] in an n-dimensional array declared as: A[upper 0 ][upper 1 ]…[upper n-1 ]   The address for A[i 0 ][i 1 ]…[i n-1 ] is: