General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Sorting algorithms Sieve of Eratosthenes
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
EC-111 Algorithms & Computing Lecture #7 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
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.
General Computer Science for Engineers CISC 106 Midterm 2 Review James Atlas Computer and Information Sciences 11/06/2009.
Lecture 6 : Dynamic Hashing Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Standard Algorithms. Many algorithms appear over and over again, in program after program. These are called standard algorithms You are required to know.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.
General Computer Science for Engineers CISC 106 Lecture 22 Dr. John Cavazos Computer and Information Sciences 04/13/2009.
General Computer Science for Engineers CISC 106 Lecture 20 Dr. John Cavazos Computer and Information Sciences 04/08/2009.
General Computer Science for Engineers CISC 106 Final Exam Review Dr. John Cavazos Computer and Information Sciences 05/18/2009.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
1 Lecture Today’s topic Arrays Reading for this Lecture: –Chaper 11.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
General Computer Science for Engineers CISC 106 Lecture 25 Dr. John Cavazos Computer and Information Sciences 04/20/2009.
General Computer Science for Engineers CISC 106 Lecture 13 Roger Craig Computer and Information Sciences 3/13/2009.
General Computer Science for Engineers CISC 106 Lecture 34 Dr. John Cavazos Computer and Information Sciences 05/13/2009.
General Computer Science for Engineers CISC 106 Lecture 33 Dr. John Cavazos Computer and Information Sciences 05/11/2009.
General Computer Science for Engineers CISC 106 Lecture 09 James Atlas Computer and Information Sciences 9/25/2009.
General Computer Science for Engineers CISC 106 Lecture 05 Dr. John Cavazos Computer and Information Sciences 2/20/2009.
General Computer Science for Engineers CISC 106 Lecture 23 Dr. John Cavazos Computer and Information Sciences 4/15/2009.
General Computer Science for Engineers CISC 106 Lecture 18 Dr. John Cavazos Computer and Information Sciences 3/27/2009.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
COMP 1001: Introduction to Computers for Arts and Social Sciences Programming in Scratch Monday, May 16, 2011.
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 06/29/2009.
Lecture 12. Searching Algorithms and its analysis 1.
Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.
L. Grewe.  An array ◦ stores several elements of the same type ◦ can be thought of as a list of elements: int a[8]
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
I Power Int 2 Computing Software Development High Level Language Constructs.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 2.
Introduction to: Programming CS105 Lecture: Yang Mu.
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.
Chapter 9 slide 1 Introduction to Search Algorithms Search: locate an item in a list (array, vector, table, etc.) of information Two algorithms (methods):
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
General Computer Science for Engineers CISC 106 Lecture 2^4 Roger Craig Computer and Information Sciences 03/23/2009.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Computing and the Web Algorithmic Thinking. Overview n Understanding a specific process n Developing an algorithm n Applying the algorithm to computer.
General Computer Science for Engineers CISC 106 Lecture 15 Dr. John Cavazos Computer and Information Sciences 03/16/2009.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
Arrays Chapter 12. Overview Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays.
Chapter 5: ARRAYS ARRAYS. Why Do We Need Arrays? Java Programming: From Problem Analysis to Program Design, 4e 2  We want to write a Java program that.
General Computer Science for Engineers CISC 106 Lecture 06 James Atlas Computer and Information Sciences 06/24/2009.
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
General Computer Science for Engineers CISC 106 Lecture 27 Dr. John Cavazos Computer and Information Sciences 04/27/2009.
General Computer Science for Engineers CISC 106 Lecture 09 Dr. John Cavazos Computer and Information Sciences 03/04/2009.
GC211Data Structure Lecture2 Sara Alhajjam.
Section 2.6: Searching and Sorting
[Array, Array, Array, Array]
3.1 Algorithms (and real programming examples).
CISC181 Introduction to Computer Science Dr
Chapter 8 Arrays Objectives
[Array, Array, Array, Array]
Computer Science Core Concepts
CISC181 Introduction to Computer Science Dr
Chapter 8 Arrays Objectives
Revision of C++.
General Computer Science for Engineers CISC 106 Lecture 15
General Computer Science for Engineers CISC 106 Lecture 11
COMPUTING.
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009

Lecture Overview While loops Arrays Linear Search

WHILE Loops > i = 0; > while (i < 5) ‏ ← condition that gets tested i i = i+1; ← increment loop variable end

In class assignment Code a while loop so that prints only even numbers up to and including 10

Arrays A = [ ] A

Arrays Change even positions to have 2

Arrays Easy way A(2) = 2 A(4) = 2 What happens if have 100 elements!

Using a While loop for this. >> x = 1; >> while ( x <= length (a) ) if (mod (x,2) == 0) a(x) = 2; end x = x + 1; end

Finding a number in an array Write pseudo code first!. What are the data structures needed?. Do I need a loop? What kind would work best?. Write algorithm in English.

Pseudo code - Store numbers in array - Initialize array index to 1 - Initialize number found boolean variable - while number not found or array length not exceeded - if current array position has num - set number found - end - If number found report!

Finding a number in an array >> x = 1; >> numberFound = false; >> while (numberFound == false) if (a(x) == 3.14) numberFound = true; end What else is missing?