Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

For use of IST410 Students only Arrays-1 Arrays. For use of IST410 Students only Arrays-2 Objectives l Declaring arrays l Instantiating arrays l Using.
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.
Computer programming 1 Multidimensional Arrays, and STL containers: vectors and maps.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
1 CS 201 Array Debzani Deb. 2 Having trouble linking math.h? Link with the following option gcc –lm –o test test.o.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Introduction to Programming with C++ Fourth Edition
C++ for Engineers and Scientists Third Edition
Chapter 8 Arrays and Strings
Chapter 9 Introduction to Arrays
Programming Logic and Design Fourth Edition, Comprehensive
 2007 Pearson Education, Inc. All rights reserved C Arrays.
CS1061 C Programmuing Lecture 12 Arrays A. O’Riordan, 2004.
Chapter 8 Multidimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
Chapter 9: Advanced Array Concepts
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
Copyright © 2012 Pearson Education, Inc. Chapter 8 Two Dimensional Arrays.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
C Static Arrays Pepper. What is an array? Memory locations – same type – next to each other (contiguous) – Same name – Indexed by position number of type.
 2006 Pearson Education, Inc. All rights reserved Arrays.
A.Abhari CPS1251 Multidimensional Arrays Multidimensional array is the array with two or more dimensions. For example: char box [3] [3] defines a two-dimensional.
Chapter 8 Arrays and Strings
Chapter 6 Arrays Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
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 
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.
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.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
C++ for Engineers and Scientists Second Edition Chapter 11 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.
Copyright © Curt Hill Multiple Dimension Arrays Extending Java Arrays.
Chapter 8 Arrays Instructor: Kun-Mao Chao ( 台大資工 趙坤茂 )
1 Arrays and Vectors Chapter 7 Arrays and Vectors Chapter 7.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
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.
Arrays as Function Arguments Array can be used as a function argument. E.g., #include int sum(int b[], int n) { int i, res; res = 0; for(i = 0; i < n;
 2007 Pearson Education, Inc. All rights reserved C Arrays.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
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.
An Object-Oriented Approach to Programming Logic and Design Chapter 8 Advanced Array Concepts.
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
Multidimensional Arrays Vectors of Vectors When One Is Not Enough.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
ADVANCED POINTERS. Overview Review on pointers and arrays Common troubles with pointers Multidimensional arrays Pointers as function arguments Functions.
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.
Arrays (Chapter 5)‏ Definition Applications One-Dimensional –Declaration –Initialization –Use Multidimensional.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
ARRAYS Multidimensional realities Image courtesy of
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
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.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
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.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
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.
Computer Programming BCT 1113
Array, Strings and Vectors
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
7 Arrays.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Multidimensional array
Arrays Imran Rashid CTO at ManiWeber Technologies.
Presentation transcript:

Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array to a function. Multi-dimensional array. Vectors. Examples.

Concept of Array An array is sequence of objects which have same types. Array is a very common data structure in nature and in computer programming languages. The Objects are called elements of the array and they are indexed by their order in the sequence.

Memory Index An array is stored in consecutive memory cells. Array name is used to determine the base address of the array (cell 0). Index starts from 0.

Array Declaration [ ]; Note: Indices are from 0 to -1; E.g: int a[20]; double b[10]; char str[17];

Initializing an Array E.g: int a[5]={1,5,8,2,4}; double b[3]={1.2,3.4,5.15}; char a[5]={"S","E","O","U","L"}; Note: C++ does not check whether an index gets over the boundary of an array.

Processing an Array The basic Loop: for (i=0;i<n;i++) { ; } To access an element in an array, use its index: [ ] a[5], b[i], c[i+5], d[i+j]

Passing an Array to Functions You need to tell the function two things: Address of the first element of the array (name of the array, or pointer to the first element (study later)). The number of elements in the array. int sum(int [],int); int a[24]; …. b= sum(a,24) Note: the array is passed by reference to functions!

Multi-Dimensional Arrays Each element of an array could be an ARRAY. In that case, we have two-dimensional array (a table). It can be extended to more general multi-dimensional cases. In reality, you hardly use array of dimension more than 3.

Memory Index A 2-dimensional array is stored in consecutive memory cells as a table. Array name is used to determine the base address of the array (cell 0,0). Indices of row and column start from 0.

Array Declaration [ ][ ]; Note: Indices are from 0 to -1; E.g: int a[3][4]; double b[10][10]; char str[17][5];

Initializing an Array E.g: int a[2][3]={{1,5,8},{2,4,7}}; Note: C++ does not check whether an index gets over the boundary of an array.

Processing an Array The basic Loop: for (i=0;i<n;i++) for(j=0; j<m; j++) { ; } To access an element in an array, use its indices: [ ][ ] a[5][6], b[i][2], c[i+5][j-5], d[i+j][7]

Passing an Array to Functions You need to tell the function two things: Address of the first element of the array (name of the array, or pointer to the first element (study later)). The sizes of row and column of the array. int sum(int [][26],int); int a[24][26]; …. b= sum(a,24) Note: the array is passed by reference to functions!

Vector Template in C++ Disadvantages of Array: C-based -> obsolete. No out-of-bound checking. Have to remember its maximal size (bounds). Not convenient for copy and comparison. Solution? - Vector Template provided by C++. Similar to JAVA based array. More Flexible. More Universal. Safer then C-based array.

Vector Declaration //using vetor #include E.g: vector a(10); vector b(5); vector c(6);

Vector Processing Get the size of a vector: a.size(); Access an element of a vector: –a.at(5) –a[5] An attempt to access an element of out bound will result in error.

Passing a Vector to Functions You only need to tell the function: Name and type of the vector InputVector(vector a)

Operator Overloading for Vectors You could manipulate vectors at primitive data types in a very natural way with operators like ==,=,!=: E.g: if (a==b) { } …… b=c; More on vector class: us/library/9xd04bzs(VS.80).aspx

Examples Examples: - Sorting an array using Bubble sort. - Sorting an array using Selection sort. - Linear search of a sorted array. - Binary Search of a sorted array. - Insert a member in to an sorted array that maintain the sorted order of the array. - Check if an array of numbers is increasing in values. - Find the longest run (subsequence) of increasing values in an numeric array.

Examples Examples: - Count a frequencies of a value x in an array. - Find the most frequent (mode) value in an array. - Delete all duplications of values within an array. - Compute the trace (sum of diagonal numbers) and Transpose a numeric matrix. - Compute the product of two numeric matrices. - Compute the Minimax and its location (row, column) of a numerical matrix, where Minimax is the member that is minimal in its row and maximal in its column.

Further Readings Textbook 1: Chapter 6. Workbook 1: Chapter 5.