Arrays and Array Visualization

Slides:



Advertisements
Similar presentations
Parameters Alice.
Advertisements

Parameters Section 8-8 Web Design. Objectives The student will: Understand what a parameter is Understand how to use a parameter in Alice Understand how.
Arrays and Array Visualization
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Recursion Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we know is that repetition.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Arrays and Array Visualization Alice. What is an array? An array is a collection of objects or information that is organized in a specific order. The.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
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.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
Variables and Inheritance Part 1
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Parameters Alice. A beetle band Our task is to create an animation for a bug band as an advertisement for their next concert.
Parameters Alice. Overview The need for more flexible methods Passing a parameter to a method Demos Using the Alice interface to write code for a parameter.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Stack. ADS2 Lecture 1010 The Stack ADT (GoTa §5.1) The Stack ADT stores arbitrary objects Insertions and deletions follow the last-in.
CompSci 4 Chap 10 November 4, 2010 Prof. Susan Rodger.
CompSci 4 Chap 10 Nov 22, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Arrays Chapter 7.
Document that explains the chosen concept to the animator
Week 2 - Wednesday CS 121.
Stack and Heap Memory Stack resident variables include:
Parameters Section 8-8 Web Design.
Chapter 3: Variables, Functions, Math, and Strings
Recursion Alice.
Chapter 8 Arrays Objectives
Recursion Alice.
Parameters Alice.
Lists Alice.
Repetition: Definite Loops
Lists Alice.
Creating an Animation Program
List Search Alice.
Chapter 8 Arrays Objectives
CS005 Introduction to Programming
Java Programming Arrays
Parameters and World-level methods
Arrays
CS2011 Introduction to Programming I Arrays (I)
Programming: Simple Control Structures
Lists Alice.
Chapter 5: Probabilistic Analysis and Randomized Algorithms
Repetition: Definite Loops
Variables and Inheritance Part 1
Functions Alice.
Lists Alice.
JavaScript: Arrays.
Chapter 8 Arrays Objectives
Data Structures & Algorithms
EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3.
Chapter 5: Probabilistic Analysis and Randomized Algorithms
List Search Alice.
Parameters Alice.
Functions Alice.
Class-level Methods and Inheritance
Functions Alice.
Functions Alice.
Class-level Methods and Inheritance Part 2
Introduction to Computer Science
Selamat Datang di “Programming Essentials in Python”
Presentation transcript:

Arrays and Array Visualization Alice

What is an array? An array is a collection of objects or information that is organized in a specific order. The individual components (elements) of an array are of the same type (object, number, color, …).

Analogy An analogy of an array is a music CD. A CD contains a collection of songs, listed in the order recorded. A CD player allows you to play any specific song by selecting its number, or play all the songs in sequence.

Arrays in Alice In Alice, an array is a data structure used to organize objects or information of the same type (object, number, color, etc.) Just as you cannot actually "see" the digital bits of the songs recorded on a CD, you cannot actually "see" the digital information in an array. In other words, an array is not visible.

Array Visualization We will use a built-in 3D model that has been specifically designed to help you "see" how an array works. The elements of this special array visualization are visual Alice objects

Initial World As an example, we will create a visualization of an array of bugs. First, we add five bugs to a new world. This is not yet an array – just five bug objects!

Initialize array Now add an arrayVisualization object to the world. A dialog box pops up to allow you to add each bug to the array.

Completed array Each bug added to the array is automatically moved to its location in the array. The locations are numbered 0, 1, 2, 3, 4 (see the digits in the blue squares). The location number is the index.

elements An arrayVisualization object has a built-in class-level variable, named elements, that keeps track of which objects are in the array and where each is located. The order of the objects in the elements variable matches the order of the objects in the array.

Demo: Access Ch10Lec2Array-V1 Concepts illustrated in this example An index is used to order the elements in an array. To access (get at) an individual element in the array, create an instruction that uses the index to select the element. An element can be randomly selected from the array. The maximum value should be the number of elements in the array. Be sure to select the integer only option for the random number function.

Permutation Changing the order of elements in an ordered group is a math operation known as creating a permutation. To demonstrate how to perform a permutation, let's write a swap method that exchanges the positions of two elements in an array.

Storyboard Two number parameters are needed, indexOne and indexTwo, to specify the indexes of the two objects to be swapped. A temporary location will be used to hold one object while the other object changes location. swap Parameters: indexOne, indexTwo (of type number) Do in order relocate element at indexOne to a temporary location relocate element at indexOne to indexTwo relocate element from temporary location to indexOne

Temporary location An objectVisualization object is added to the world to be used as a temporary holding pen.

Demo: swap Ch10Lec2Array-V2 Concepts illustrated in this example In Alice, a let instruction is used to relocate an element in an array. A temporary holding space, as can be seen in this visualization, is not part of the array. Active Learning: Demo with index arguments 1 and 2. Students run with different sets of index arguments.

Walking through an array In addition to the ability to access an individual element of an array, it is also possible to "walk through" an array, accessing each element of the array in order.

Demo: Index variable Ch10Lec2Array-V3 Concepts illustrated in this example To walk through an array, use the complicated form of the Loop instruction. An index variable is a counter for the Loop. When a Loop is used with an array, the Loop's index variable can be used to access successive elements in the array.

Assignment Read Chapter 10 Section 2, Arrays

Lab Chapter 10 Lecture 2 Lab