Arrays. Arrays: Introduction So far, we handled only one object in each line of code. When we wanted multiple objects to do something, we wrote multiple.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Microprocessors VLIW Very Long Instruction Word Computing April 18th, 2002.
Chapter 10 Introduction to Arrays
© 2004 Goodrich, Tamassia Hash Tables1  
CS0007: Introduction to Computer Programming Array Algorithms.
Introduction to Arrays Presenter: Mrs. McCallum-Rodney.
Analysis And Algorithms CMSC 201. Search Sometimes, we use the location of a piece of information in a list to store information. If I have the list [4,
 9: Arrays  Why?  What is an Array?  Declaring and Creating an Array  Initializing and Array  Array Operations  Array Examples  Arrays of Objects.
CS 206 Introduction to Computer Science II 04 / 27 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 12 / 09 / 2009 Instructor: Michael Eckmann.
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
CS 206 Introduction to Computer Science II 12 / 05 / 2008 Instructor: Michael Eckmann.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
CS 206 Introduction to Computer Science II 12 / 03 / 2008 Instructor: Michael Eckmann.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Loops We have been using loops since week 2, our void draw(){ } is a loop A few drawbacks of draw() –It is endless –There is only one draw() –It updates.
CS 206 Introduction to Computer Science II 12 / 08 / 2008 Instructor: Michael Eckmann.
CS0007: Introduction to Computer Programming Introduction to Arrays.
Segmentation CS 537 – Introduction to Operating Systems.
1)Never start coding unless you understand the task! 2)Gather requirements first. This means identify the problem and ask questions about it. Now you kind.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
CS 221 Analysis of Algorithms Data Structures Dictionaries, Hash Tables, Ordered Dictionary and Binary Search Trees.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Fall 2001(c)opyright Brent M. Dingle 2001 Arrays Brent M. Dingle Texas A&M University Chapter 9 – Sections 1 and 2 (and some from Mastering Turbo Pascal.
Virtual Memory CS Introduction to Operating Systems.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
Arrays Arrays in C++ An array is a data structure which allows a collective name to be given to a group of elements which all have.
Arrays. Lesson Objectives  To understand what an array is and it’s function  To know how code and array in VB.
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
CS 206 Introduction to Computer Science II 04 / 22 / 2009 Instructor: Michael Eckmann.
Lecture 4 Generic programming Advanced Java Programming 1 dr hab. Szymon Grabowski dr inż. Wojciech Bieniecki
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)
Hash Tables © Rick Mercer.  Outline  Discuss what a hash method does  translates a string key into an integer  Discuss a few strategies for implementing.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Mr. Hudson’s Review Test on Thursday. Topics Arrays Traversing Loops Selections Identifying code throughout a program Type Casting Conversion of numbers.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Week 12 - Friday.  What did we talk about last time?  Finished hunters and prey  Class variables  Constants  Class constants  Started Big Oh notation.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
Intro To Algorithms Searching and Sorting. Searching A common task for a computer is to find a block of data A common task for a computer is to find a.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
CompSci 4 Chap 10 November 4, 2010 Prof. Susan Rodger.
Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.
13 Arrays CE : Fundamental Programming Techniques June 161.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
DATA ANALYSIS AND INTERPRETATION. Getting Data Ready for Analysis Editing Data Open-ended questions Questionnaire data have to be checked for incompleteness.
Sections 10.1 – 10.4 Introduction to Arrays
Indexing Goals: Store large files Support multiple search keys
LEARNING OBJECTIVES O(1), O(N) and O(LogN) access times. Hashing:
اختر أي شخصية واجعلها تطير!
LESSON 13 – INTRO TO ARRAYS
Alorithms4 Bank Owner.
Remembering lists of values lists
CS1110 Today: collections.
Loops and Arrays in JavaScript
Sampling Distribution Models
Programming Logic and Design Fifth Edition, Comprehensive
Presentation transcript:

Arrays

Arrays: Introduction So far, we handled only one object in each line of code. When we wanted multiple objects to do something, we wrote multiple lines in DO TOGETHER structure. What if we have lots of objects? What if we want to do a group dance? With current approach, program will become too lengthy and unmanageable!

Arrays: Introduction Commercial programs use lot of data! We cannot afford to declare individual variables to keep each piece of data in memory! Let us look into a simple example.

Texas Lotto Texas Lottery involves selecting 6 unique numbers from the range of 1 to 50. We can put 50 balls with 50 numbers in a bowl, mix them and take 6 of them – they are guaranteed to be 6 different numbers! What if we want to computerize? Assuming that we know how to generate random number between 1 and 50, we can repeat it 6 times.

Texas Lotto … It works well, but occasionally we may get a selection like 10, 18, 43, 18, 23, 34. Is there a problem? Yes, we cannot have repeating numbers in the selection: 10, 18, 43, 18, 23, 34. It is invalid! Then, how to ensure that the numbers are unique?

Ideas? What should we do after generating each number? Check against the numbers selected so far If current number is a repetition, throw it away and reselect. Selection can be considered as a collection or array of 6 numbers.

General view of an array Typically, array has a name – need to use index # to access a specific item. Stored items can be anything. For example, we can define array of objects too! index 0 index 1 index 2 index 3 index 4 index 5

ok, enough of serious discussion, let us proceed to dance …