Copyright © 1998-2013 Curt Hill Multiple Dimension Arrays Extending Java Arrays.

Slides:



Advertisements
Similar presentations
1 Arrays, Strings and Collections [1] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Introduction to C Programming
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
CS0007: Introduction to Computer Programming Arrays: Higher Dimensional Arrays.
Arrays.
1 Arrays in JavaScript Name of array (Note that all elements of this array have the same name, c ) Position number of the element within array c c[6] c[0]
CIS 130 Numeric Arrays Chapter 10. What is an array? Collection of data storage locations –stored adjacently in memory All the pieces of data share a.
Digital Images in Java The structure of code and concept
Maths for Computer Graphics
ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
Multidimensional Arrays in Java Vidhu S. Kapadia.
Lecture # 9 Matrix Representation of Symmetry Groups
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
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
Chapter 8 Multidimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
Multi-Dimensional Arrays in Java "If debugging is the process of removing software bugs, then programming must be the process of putting them in." -- Edsger.
Java Unit 9: Arrays Declaring and Processing Arrays.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Copyright © 2012 Pearson Education, Inc. Chapter 8 Two Dimensional Arrays.
Chapter 8 Arrays and Strings
Arrays Chapter 7. 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores : Inspecting.
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Lecture Set 9 Arrays, Collections and Repetition Part C - Random Numbers Rectangular and Jagged arrays.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
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.
Defining a 2d Array A 2d array implements a MATRIX. Example: #define NUMROWS 5 #define NUMCOLS 10 int arr[NUMROWS][NUMCOLS];
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
Slide Copyright © 2009 Pearson Education, Inc. 7.3 Matrices.
Copyright Curt Hill Arrays in C/C++ More on usage.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
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 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays in Classes and Methods l Programming.
CSC Programming for Science Lecture 28: Multi-dimensional Arrays.
Arrays.
1 Arrays of Arrays Quick review … arrays Arrays of arrays ≡ multidimensional array Example: times table Representation in memory Ragged arrays Example:
CS 180 Recitation 7 Arrays. Used to store similar values or objects. An array is an indexed collection of data values of the same type. Arrays are the.
Arrays.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Copyright © Curt Hill Further Picture Manipulation Considering position.
Multidimensional Arrays Computer and Programming.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
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.
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.
Table of Contents Matrices - Definition and Notation A matrix is a rectangular array of numbers. Consider the following matrix: Matrix B has 3 rows and.
ARRAYS Multidimensional realities Image courtesy of
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
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.
Arrays Chapter 7.
Chapter 6: Using Arrays.
Two-Dimensional Arrays
Computer Programming BCT 1113
Multiple Dimension Arrays
EKT150 : Computer Programming
Arrays in Java What, why and how Copyright Curt Hill.
Other displays Saving Arrays Using fors to process
MSIS 655 Advanced Business Applications Programming
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Arrays Chapter 7.
Multidimensional array
Matrix A matrix is a rectangular arrangement of numbers in rows and columns Each number in a matrix is called an Element. The dimensions of a matrix are.
Chapter 6 - Arrays Outline Multiple-Subscripted Arrays.
Presentation transcript:

Copyright © Curt Hill Multiple Dimension Arrays Extending Java Arrays

Copyright © Curt Hill What is a multiple dimension array? An array of arrays An array with multiple brackets One dimension is a column or list Two dimensions is a table or rectangle Three dimensions is rectangular solid Four dimensions is hard to visualize

Copyright © Curt Hill Multidimensional arrays Declaration and allocation: double d [ ] [ ]; i=8; j=4; d = new double [i][j]; for(m=0;m<i;m++) for(n=0;n<j;n++) d[m][n] = m*100+n;

Copyright © Curt Hill Organization In the above: d is a handle to a table – a two dimensioned array of doubles d[1] is a handle to a row of doubles d[1][1] is a double

Pictures We have almost used multiple dimension arrays in Pictures The getPixel method is a wrapper for the two dimensioned array of pixels When we do: getPixel(x,y); that is similar to pixels[x][y] –Presuming an array of pixels exists in the picture Copyright © Curt Hill

More than 2 No real restrictions on the number of dimensions, other than memory consumption –int ar[][][][][] = new int [4][7][11][3][5]; –Requires 4*7*11*3*5 = 4620 integers –This is bytes of storage The size is the product of dimensions times size of individual

Copyright © Curt Hill A Matrix A common mathematical concept is a matrix It is a rectangular grid of values Most common usage is for manipulating simultaneous linear equations However, we will be interested in manipulating the pixels of a picture

Previously We have manipulated pictures with a one dimensional array of pixels This if fine for changing each pixel in some specified way It ignores lines boundaries and other important information It would be impossible to do many interesting manipulations Copyright © Curt Hill

What sort of manipulations? Mirroring the image Finding points of high contrast Altering the size These we are familiar with by now Copyright © Curt Hill

Another View Pictures and most applications of two dimensional arrays are rectangular Most programming languages may only handle multiple dimensioned arrays as rectangles Java is not most programming languages

Copyright © Curt Hill Non-Rectangularity A two dimension array is an array of arrays There may be rows of unequal length int ar [] [] = new int[3][]; ar[0] = new int[5]; ar[1] = new int[2]; ar[2] = new int[12];

Copyright © Curt Hill Discussion Since a multiple dimension array is an array of arrays we may either specify one or more sizes in the new The command: int [][] ar = new int[K] [ ]; allocates K rows, but leaves the length of each row unspecified Later use: ar[i] = new int [10]; to specify the row size

Copyright © Curt Hill Lengths The length property may be applied to the entire array –The number of rows –ar.length It may be applied to each row as well –ar[i].length –The length of this row

Copyright © Curt Hill Number of Elements If the array is allocated with: new type[I][K] the number of elements is just I*K The number of elements is somewhat harder to compute in general: count = 0; for(int i = 0;i<ar.length;i++) count += ar[i].length;

Copyright © Curt Hill Initialization Brace notation may be used as well int ar[] [] = {{0,1,2,3}, {100,101}, {200,201,202,203,204,205}}; First dimension is size 3 First row is size 4 Second row is size 2 Last row is size 6

Finally A picture’s pixels are naturally considered a two dimension array –The getPixel(int,int) method is a method call that looks like subscripting Most other applications of two dimensional arrays fall into the areas of mathematics, science or engineering Copyright © Curt Hill