Linear Containers Some containers are called linear because their content (items) are stored in a single row (line). Which of the following are linear?

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

Some containers are called linear because their content (items) are stored in a single row (line). Which of the following are linear?  the rungs of a.
Arrays Chapter 6. Outline Array Basics Arrays in Classes and Methods Sorting Arrays Multidimensional Arrays.
Chapter 9 Arrays. 2 Knowledge Goals Understand the difference between atomic and composite data types Understand the difference between unstructured and.
Lecture 05 - Arrays. Introduction useful and powerful aggregate data structure Arrays allow us to store arbitrary sized sequences of primitive values.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 10 *Arrays with more than one dimension *Java Collections API.
Chapter 9 Introduction to Arrays
Chapter 10 2D Arrays Collection Classes. Topics Arrays with more than one dimension Java Collections API ArrayList Map.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
French Territory of St. Pierre CSE 114 – Computer Science I Arrays.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
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.
JAVA 0. HAFTA Algorithms FOURTH EDITION Robert Sedgewick and Kevin Wayne Princeton University.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
ARRAYS Multidimensional realities Image courtesy of
Arrays. Arrays are objects that help us organize large amounts of information.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Arrays Chapter 7.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Lesson 8: Introduction To Arrays
Sections 10.1 – 10.4 Introduction to Arrays
Objects as a programming concept
Chapter 8 Multidimensional Arrays
Computer Programming BCT 1113
Chapter 8 Multidimensional Arrays
© 2016 Pearson Education, Ltd. All rights reserved.
JavaScript: Functions.
Java Review: Reference Types
Two-Dimensional Arrays
Designing for Inheritance
Advanced Programming Behnam Hatami Fall 2017.
Chapter 8 Multidimensional Arrays
Starting JavaProgramming
Multiple Choice -answer the easiest question 1st
7 Arrays.
Can store many of the same kind of data together
Chapter 8 Multidimensional Arrays
Topic 26 Two Dimensional Arrays
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Chapter 7 Multidimensional Arrays
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
Chapter 8 Multidimensional Arrays
Can store many of the same kind of data together
Chapter 8 Multidimensional Arrays
Chapter 7 Part 2 Edited by JJ Shepherd
CSE 214 – Computer Science I More on Linked Lists
Multidimensional Arrays
Chapter 8 Multidimensional Arrays
Can store many of the same kind of data together
7 Arrays.
Chapter 8 Multidimensional Arrays
Introduction to Data Structure
Dr Tripty Singh Arrays.
CIS 199 Final Review.
Chapter 7 Multidimensional Arrays
Chapter 7 Multidimensional Arrays
Review for Midterm 3.
Chapter 8 Multidimensional Arrays
Arrays.
Presentation transcript:

Linear Containers Some containers are called linear because their content (items) are stored in a single row (line). Which of the following are linear?  the rungs of a ladder  the links in a chain  the bricks in the wall of a building  the employees in a company’s organizational chart  the items in an array

Single Dimensional Arrays The one-dimensional array (vector) is a basic data structure (container) in many programming languages. Java Array Review Write a declaration of a private instance variable, called weights, that is an array of five double items. Write a declaration of a local variable, called names, that is an array of ten Strings. Write an instruction to triple the value of the third cell of weights. Write a loop to output the complete content of names. Show all code needed to declare and assign a local variable, called threeSets, that is an array of the following three sets of String (each bounded by cardinality of five). { “dog”, “cat” } { } { “big”, “little” }

Sequential or Direct Access? Processing items from a container in linear order is called sequential access. Example int[ ] powersOfTwo; powersOfTwo = new int[10]; powersOfTwo[0] = 1; for (int k = 1; k != powersOfTwo.length; k++) { powersOfTwo[k] = powersOfTwo[k-1] * 2; } The Collection for loop can also be used to process sequentially. Arrays can also be processed via direct access by referring to a particular item without first processing the other items preceding it. Example System.out.println( “The fifth power of 2 is “ + powersOfTwo[5] ); Note: Some linear containers support direct access. Some non-linear containers support sequential access.

Are Arrays Primitive or Reference? In Java arrays fit somewhere in between a true reference object and a primitive. String[ ] twoWordCities = {“New York”, “Los Angeles”, “La Crosse”}; Is array behavior more like a reference or a primitive for each of the following?  instantiation (Is new generally required or never used?)  assignment (Does “=“ mean to copy a binding or a value?)  parameter passage (Does passing twoWordCities allow a method to alter the array content or not?)  equals (Does equals work like ==, testing identity?)  conformance (Does every array conform to Object?)  Can you override equals() and toString() for your arrays?  Inheritance (Is ... extends String[] ... possible?)

The Need for More Dimensions One Dimensional Array [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Show a Java declaration for each. Two Dimensional Array [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Show an instantiation for each. Show an expression for each red cell. Three Dimensional Array [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]

Example: More Dimensions Consider the following objects.  A grocery cart of purchases (a vector of purchases).  A check-out lane (vector of grocery carts).  A grocery store (vector of check-out lanes)  A grocery chain (vector of grocery stores) Do all grocery stores contain the same number of check-out lanes? Are all check-out lanes the same length? (see next slide)

Slices A multi-dimensional array is really a one-dimensional array of arrays (slices). [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Show an expression for one slice of a 2-dimensional array. Show a Java declaration and instantiation code for a single check-out lane with three carts consisting of space for 8, 6 and 2 purchases. When the length of different parts of an array differ, the array is called _______.

Abstraction & Multiple Dimensions Non-linear information, such as a multi-dimensional table, can be perceived in many ways. Example: (Consider the following text.) The look of sadness overwhelmed the faces of the strong. Young children wept. World leaders spoke of a great societal loss. Twas the day after the last Far Side. Different abstract views: 1) a collection of five lines 2) a collection of four English sentences. 3) a 2-dimensional square grid of symbols 4) a 1-dimensional vector of lines

Implementation Decisions Consider different data structures for representing the following. The look of sadness overwhelmed the faces of the strong. Young children wept. World leaders spoke of a great societal loss. Twas the day after the last Far Side. Option #1: Square 2D array of char  Show a declaration for an object to store this data structure.  Show the code to instantiate the array and assign it the content above.  Show the code to output the 14th character of the second line.

Implementation Decisions Consider different data structures for representing the following. The look of sadness overwhelmed the faces of the strong. Young children wept. World leaders spoke of a great societal loss. Twas the day after the last Far Side. Option #2: One-dimensional array of char (a linear view)  Show a declaration for an object to store this data structure.  Show the code to instantiate the array and assign it the content above.  Show the code to output the 14th character of the second line.

Implementation Decisions Consider different data structures for representing the following. The look of sadness overwhelmed the faces of the strong. Young children wept. World leaders spoke of a great societal loss. Twas the day after the last Far Side. Option #3: One-dimensional array of String (a ragged view)  Show a declaration for an object to store this data structure.  Show the code to instantiate the array and assign it the content above.  Show the code to output the 14th character of the second line.

Loops for Processing Arrays The look of sadness overwhelmed the faces of the strong. Young children wept. World leaders spoke of a great societal loss. Twas the day after the last Far Side. Write the code to output the text for the 2D array of char. How does your code change if printing by column?