Array.  ARRAYS ALLOW US TO STORE ELEMENTS OF SINGLE DATA TYPE CONTAGUISLY IN MEMORY  EACH ELEMENT IS ASSOCIATED WITH AN INDEX OR LOCATION  WE CAN ACCESS.

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

Selection Sort. Selection Sort Algorithm (ascending) 1.Find smallest element (of remaining elements). 2.Swap smallest element with current element (starting.
CS 141 Computer Programming 1 1 Arrays. Outline  Introduction  Arrays  Declaring Arrays  Examples Using Arrays  Sorting Arrays  Multiple-Subscripted.
Cosc 2150 Arrays in assembly code. Variables and addresses Uncompiled ld [a], %r1 addcc %r1, 2, %r3 ARC has three addressing modes —immediate, direct,
Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number.
Variables i)Numeric Variable ii)String Variable
Session 3 Algorithm. Algorithm Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm Example Check.
Basic Algorithms on Arrays. Learning Objectives Arrays are useful for storing data in a linear structure We learn how to process data stored in an array.
Lecture 05 - Arrays. Introduction useful and powerful aggregate data structure Arrays allow us to store arbitrary sized sequences of primitive values.
Multidimensional Arrays in Java Vidhu S. Kapadia.
Java: How to Program Arrays and ArrayLists Summary Yingcai Xiao.
Arrays CS Feb Announcements Exam 1 Grades on Blackboard Project 2 scores: end of Class Project 4, due date:20 th Feb –Snakes & Ladders Game.
1 Dynamic Memory Allocation Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series.
Array Must declare a variable to reference the array double [] mylist; // cannot double list[20]; Or double mylist[]; The declaration doesn’t allocate.
Lecture 16 Arrays: Part 2 COMP1681 / SE15 Introduction to Programming.
One Dimensional Arrays. Declaring references to array objects How would you declare a variable somearray that is an array of ints? int[] somearray;
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
Searching and Sorting, Template Functions, and Vectors ITK 169 Fall 2003.
COMP102 Lab 081 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Lecture 5: Arrays A way to organize data MIT AITI April 9th, 2005.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Page 1 Quiz by Joseph Lindo. Page 2 Program Analysis by providing the output of a program snippet Some are true or false Some have choices.
1 nd Semester Module7 Arrays Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about 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.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Types in Java 8 Primitive Types –byte, short, int, long –float, double –boolean –Char Also some Object types: e.g. “String” But only single items. What.
Arrays and Strings. Why? Consider a class of 30 students, each has a score for hw1  Do we want to have 30 variables with different names?  Would it.
Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY.
CS1010E Programming Methodology Tutorial 6 Arrays and Search C14,A15,D11,C08,C11,A02.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
Arrays and ArrayLists. int numbers[] = new int[10]; numbers Other ways to declare the same array 1) int[] numbers = new.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
Arrays. Collections We would like to be able to keep lots of information at once Example: Keep all the students in the class Grade each one without writing.
Array and ArrayList ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items in an.
Get Longest Run Index (FR) public int getLongestRunIndex(int []values) { int maxRunStart = -1, maxRunLength = 1; int runStart = 0, runLength = 1; for(int.
 MergeSort is a sorting algorithm which is more on the advanced end.  It is very fast, but unfortunately uses up a lot of memory due to the recursions.
Arrays and ArrayLists Topic 6. One Dimensional Arrays Homogeneous – all of the same type Contiguous – all elements are stored sequentially in memory For.
1 Insertion sort [ ] i=1 j=1 i=2 j=2 insert i=3 at j=1 [ ] i=3 j=1 insert i=4 at j=0 [
C# E1 CSC 298 Arrays in C#. C# E2 1D arrays  A collection of objects of the same type  array of integers of size 10 int[] a = new int[10];  The size.
Simple algorithms on an array - compute sum and min.
1 Arrays and Methods Java always passes arguments by value – that is a copy of the value is made in the called method and this is modified in the method.
11 PART 2 ARRAYS. 22 PROCESSING ARRAY ELEMENTS Reassigning Array Reference Variables The third statement in the segment below copies the address stored.
Final Review Author: Thanachat Thanomkulabut Edited by Supaporn Erjongmanee Final Review 22 September 2011.
CSE 251 Dr. Charles B. Owen Programming in C1 Intro to Arrays Storing List of Data.
P OINTERS A pointer is an address All data is stored in memory in some location that is indexed with an address Can refer to variables by name or by memory.
Arrays and Indexers Programming in C# Arrays and Indexers CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
MICROPROCESSOR PROGRAMMING & INTERFACING Tutorial 3 Module 4.
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
Array and String.
CSI 3125, Preliminaries, page 1 Arrays. CSI 3125, Preliminaries, page 2 Arrays Group of related typed variables that referred to a common name Each data.
CS162 - Topic #12 Lecture: –Arrays with Structured Elements defining and using arrays of arrays remember pointer arithmetic Programming Project –Any questions?
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
“Unboxing” means taking an Integer object and assigning its value to a primitive int. This is done using the.intValue( ) method. Example; Integer z = new.
3/21/2016IT 2751 Tow kinds of Lists Array What can be done? What can be easily done? student 1 student 2 student 3 student 4 Linked List student 2 student.
ARRAY AND LOOPS REVIEW Mr. Crone. What will the code below print? int[] arry = {2, 5, 2, 1, 3}; for(int i = 0; i < 5; i ++) System.out.print(arry[i]);
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
1 Agenda Arrays: Definition Memory Examples Passing arrays to functions Multi dimensional arrays.
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
Basic arrays, binary search, selection sort by amelia bateman
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Java Arrays and ArrayLists COMP T1 #5
Two Dimensional Array Mr. Jacobs.
Arrays November 8, 2017.
Binary Search class binarysearch {
Presentation transcript:

Array

 ARRAYS ALLOW US TO STORE ELEMENTS OF SINGLE DATA TYPE CONTAGUISLY IN MEMORY  EACH ELEMENT IS ASSOCIATED WITH AN INDEX OR LOCATION  WE CAN ACCESS ANY ELEMENT BY INDEXING INTO THE ARRAY

Array Type[]Array name= new Array Type[size] int[] array1 = new int[4]; double[] array2 = new double[4]; String[] array3 = new String[4];

int[] a1 = new int[4]; double[] a2 = new double[4]; String[] a3 = new String[4]; a1[1]=4; a2[1]=4; a3[1]="4";

int[] a1 = new int[4]; double[] a2 = new double[4]; String[] a3 = new String[4]; a1[2]=(int)5.6; a2[2]=5.6; a3[2]="5.6";

Array Type[]Array name ={n1,n2,n3,….}; int[] array1 = {1,2,3,4}; double[] array2 = {1,2,4.2,6.3,4.12}; String[] array3 = {“ab”,”cd”,”ef”,”gh”};

int[] a4 = {5,8,9,2,6,1}; for(int i=0;i<a4.length;i++) { System.out.print(a4[i]+" ");

int[] a4 = {5,8,9,2,6,1}; for(int i=0;i<a4.length;i+=2) { System.out.print(a4[i]+" ");

int[] a4 = {5,8,9,2,6,1}; for(int i=1;i<a4.length;i+=2) { System.out.print(a4[i]+" ");

int[] a4 = {5,8,9,2,6,1}; for(int i=0;i<a4.length;i++) { if (a4[i]%2==0){ System.out.print(a4[i]+" "); }

int[] a4 = {5,8,9,2,6,1}; int total = 0; for (int i=0; i<a4.length; i++) { total += a4[i]; } System.out.print(total);

Array Type[]Array name ={n1,n2,n3,….}; int[] array1 = {1,2,3,4,8};

Array Type[]Array name ={n1,n2,n3,….}; double[] array1 = {1,2,4.2,6.3,4.12,8};

Array Type[]Array name ={n1,n2,n3,….}; String[] array1 = {“ab”,”cd”,”ef”,”gh”,”sw”};

for(int i = 0; i < size; i++) array1[i] = i + 5; Int size = 5; int[] array1 = new int[size];

You want to initialize all of the elements of a double array a to the same value equal to 1.5. What could you write? Assume that the array has been correctly initialized. A. for(int i=1; i<a.length; i++) a[i] = 1.5; B. for(int i=0; i<=a.length; i++) a[i] = 1.5; C. for(int i=0; i<a.length; i++) a[i] = 1.5; D. for(int i=0; i<a.length+1; i++) a[i] = 1.5; E. for(int i=0; i<a.length-1; i++) a[i] = 1.5;

Refer to the following code that finds the smallest value in an array. int min = /* some value */ int index; while (index < arr.length) { if(arr[index] < min) min = arr[index]; index++; } System.out.println(min); Which replacement(s) for /* some value */will always result in correct execution of the code. I Integer.Min_Value II Integer.Max._Value III arr[0] (A)I only (B) II only (C)III only (D)I and III only (E) II and III only

A matrix(two-dimensional array) is declared as int [][] mat = new int[2][2]; Consider the following code: 10for (int r = 0; r < mat.length; r++) 11 for(int c = 0; c < mat[r].length; c++) 12 if(r == c) 13 mat[r][c] = Math.abs(mat[r][c]);