Nested Loops, Arrays CSE 120 Winter 2018

Slides:



Advertisements
Similar presentations
RAPTOR Syntax and Semantics By Lt Col Schorsch
Advertisements

An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
ITEC113 Algorithms and Programming Techniques
Loops – While, Do, For Repetition Statements Introduction to Arrays
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
CS0007: Introduction to Computer Programming Introduction to Arrays.
Chapter 2 - Algorithms and Design
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Lecture 4 Control Structures MIT – AITI What are Control Structures? Control structures are a way to alter the natural sequence of execution in.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Arrays An array is a data object that can hold multiple objects, all of the same type. We can think of an array as a storage box which has multiple compartments.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Arrays Chapter 7.
Nested Loops & Arrays CSE 120 Spring 2017
CSC 211 Java I for loops and arrays.
Expressions & Control Flow CSE 120 Spring 2017
Chapter 4 – C Program Control
Basic Input and Output CSE 120 Spring 2017
Computer Programming BCT 1113
Two-Dimension Arrays Computer Programming 2.
© 2016 Pearson Education, Ltd. All rights reserved.
Processing Introduction CSE 120 Spring 2017
Memory, Data, & Addressing II CSE 351 Autumn 2017
Java Coding 3 – part2 David Davenport Computer Eng. Dept.,
Developing an App CSE 120 Spring 2017
Functions in Processing CSE 120 Spring 2017
Algorithmic Complexity I CSE 120 Spring 2017
Algorithmic Complexity CSE 120 Winter 2018
Mid-Quarter Review CSE 120 Winter 2018
Functions in Processing CSE 120 Winter 2018
Puzzle App II CSE 120 Winter 2018
Basic Input and Output CSE 120 Winter 2018
Variables & Datatypes CSE 120 Winter 2018
CSC 142 Computer Science II
Processing and Drawing CSE 120 Winter 2018
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
Expressions & Control Flow CSE 120 Winter 2018
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Outline Altering flow of control Boolean expressions
Arrays Skill Area 315 Part A
Variables & Datatypes CSE 120 Spring 2017
Lightbot and Functions CSE 120 Winter 2018
Strings, Puzzle App I CSE 120 Winter 2018
int [] scores = new int [10];
Arrays .
Memory, Data, & Addressing II CSE 351 Summer 2018
Algorithms CSE 120 Winter 2018 Instructor: Teaching Assistants:
python.reset() Also moving to a more reasonable room (CSE 403)
Memory, Data, & Addressing II CSE 351 Autumn 2018
Lecture 10: Arrays AP Computer Science Principles
Arrays.
Basic Input and Output CSE 120 Winter 2019
Variables & Datatypes CSE 120 Winter 2019
Loops and Arrays in JavaScript
INC 161 , CPE 100 Computer Programming
Arrays in Java.
Arrays CSE 120 Winter 2019 Instructor: Teaching Assistants:
Suggested self-checks: Section 7.11 #1-11
Data Structures & Algorithms
Loops & Nested Loops CSE 120 Winter 2019
Chapter 4 - Program Control
CIS 110: Introduction to Computer Programming
Buttons & Boards CSE 120 Winter 2019
How do you do the following?
Expressions & Conditionals CSE 120 Winter 2019
Week 7 - Monday CS 121.
Presentation transcript:

Nested Loops, Arrays CSE 120 Winter 2018 Instructor: Teaching Assistants: Justin Hsia Anupam Gupta, Cheng Ni, Eugene Oh, Sam Wolfson, Sophie Tian, Teagan Horkan MiDAS Unemployment System: Algorithm Alchemy Created Lead, Not Gold “34,000 plus individuals wrongfully accused of unemployment fraud… by Michigan Integrated Data Automated System (MiDAS). A review found that MiDAS adjudicated– by algorithm alone–40,195 cases of fraud, with 85 percent resulting in incorrect fraud determinations. “As algorithms take on even more decisions in the criminal justice system, in corporate and government hiring, in approving credit and the like, it is imperative that those affected can understand and challenge how these decisions are being made.” https://spectrum.ieee.org/riskfactor/computing/software/ michigans-midas-unemployment-system-algorithm-alchemy- that-created-lead-not-gold Furthermore, MiDAS was apparently basing some of its findings on missing or corrupt data. In effect, MiDAS was built upon the assumption that anyone claiming unemployment insurance was trying to defraud the UIA, and it was up to claimants to prove otherwise.

Administrivia Assignments: Midterm in class on Monday, 2/5 Portfolio Update 1 due tonight (1/31) Creativity Assignment (2/2) Midterm in class on Monday, 2/5 1 sheet of notes (2-sided, letter, handwritten) Fill-in-the-blank(s), short answer questions, maybe simple drawing Living Computers Museum “field trip” upcoming

Outline For-Loop Review Nested Loops Arrays Arrays and Loops

For-Loop Review Loops control a sequence of repetitions Do the same thing (or similar things) over and over again Examples: What is changing?

Example: Line Gradient

Exercise: Circle Loop Consecutive concentric circles differ in diameter by 10: size(400, 400); noFill(); for(int d = 450; ________; ________ ) { ellipse( ______, ______, _____, _____ ); }

Example: Looping with User Interaction? Draw lines from left side of screen to the horizontal position of the mouse

Example: Draw Lines to mouseX

Outline For-Loop Review Nested Loops Arrays Arrays and Loops

Nested Loops Generally a for-loop has a single loop variable that changes with each iteration What if you need/want more things to change? Can nest loops – i.e. put a loop inside of another loop

Example: Rectangle Grid

Outline For-Loop Review Nested Loops Arrays Arrays and Loops

Arrays “Structures” that store many values of the same datatype Can think of as a group of related variables Arrays store large amounts of data that you can access using a single name Accessing arrays with loops is very convenient

Arrays Terminology “Structures” that store many values of the same datatype Element: a single value in the array Index: a number that specifies the location of a particular element of the array Start from 0 Length: total number of elements in the array Example: Index: 1 2 3 4 Value: 12 49 -2 5 17 length of 5 “element 0” “element 4”

Arrays in Processing Declaration: type[] name Creation: new type[num] e.g. int[] is array of integers, color[] is array of colors Creation: new type[num] e.g. int[] intArr = new int[5]; Default value for all elements is “zero-equivalent” (0, 0.0, false, black) Remember that actual indices are from 0 to num-1 Initialization: {elem0, elem1, …, elemN}; e.g. int[] intArr = {12, 49, -2, 5, 17};

Arrays in Processing Use element: name[index] Get length: name.length In expression, uses value of that index of the array In assignment, modifies value of that index of the array Get length: name.length Example: int[] intArr = {12, 49, -2, 5, 17}; println(intArr[0]); // prints 12 to console intArr[2] = intArr.length; // changes -2 to 5 Index: 1 2 3 4 Value: 12 49 -2 5 17

Arrays Worksheet Attach buckets to velcro when array is created Creation of array automatically initializes it Access array using notation ar_name[index] Indices are numbered starting from 0 Use just like you would a variable When WRITING, replace ball in bucket When READING, take ball of same color (leave current one in bucket) 1 2 3 4

Example: TMNT

Example: Index of Smallest Number Algorithm: Keep track of the index of the smallest number seen so far Start with index 0 Check each element 1-by-1; if number is smaller, then update the smallest index