Standard Algorithms Find the highest number. ! Your name and today’s date ! Find the maximum Dim numbers(20) As Integer.

Slides:



Advertisements
Similar presentations
Topic Reviews For Unit ET156 – Introduction to C Programming Topic Reviews For Unit
Advertisements

Chapter 5: Control Structures II (Repetition)
Chapter 4 - Control Statements
Combining Like Terms. Only combine terms that are exactly the same!! Whats the same mean? –If numbers have a variable, then you can combine only ones.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
Outline lecture Revise arrays Entering into an array
Introduction to arrays Array One dimenstional array.
DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment.
Module 10: Virtual Memory
E.g.9 For to do loop for i:=1 to 10 do writeln(i); While do loop i:=1;
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
What Does This Program Do?
Complexity Analysis (Part II)
L6:CSC © Dr. Basheer M. Nasef Lecture #6 By Dr. Basheer M. Nasef.
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
MATLAB Examples. CS 1112 MATLAB Examples Find the number of positive numbers in a vector x = input( 'Enter a vector: ' ); count = 0; for ii = 1:length(x),
Int 2 Multimedia Revision. Digitised Sound Analogue sound recorded from person, or real instruments.
Designing Algorithms Csci 107 Lecture 4. Outline Last time Computing 1+2+…+n Adding 2 n-digit numbers Today: More algorithms Sequential search Variations.
Standard Algorithms. 4 Standard Algorithms Input Validation Finding the Maximum / Minimum Counting Occurrences Linear Search.
Standard Algorithms. Many algorithms appear over and over again, in program after program. These are called standard algorithms You are required to know.
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
Efficiency of Algorithms
1 11/27/06CS150 Introduction to Computer Science 1 Searching Arrays.
Designing Algorithms February 2nd. Administrativia Lab assignments will be due every Monday Lab access –Searles 128: daily until 4pm unless class in progress.
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
Designing Algorithms Csci 107 Lecture 3. Administrativia Lab access –Searles 128: daily until 4pm unless class in progress –Searles 117: 6-10pm, Sat-Sun.
Designing Algorithms Csci 107 Lecture 4.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Java vs. You.
Searching and Sorting Arrays
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Part 2. Searching Arrays Looking for a specific element in an array E.g., whether a certain score (85) is in a list of scores Linear search Binary search.
Higher Grade Computing Studies 4. Standard Algorithms Higher Computing Software Development S. McCrossan 1 Linear Search This algorithm allows the programmer.
Starting Out with C++, 3 rd Edition 1 Searching an Arrays.
Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.
 2006 Pearson Education, Inc. All rights reserved Searching and Sorting.
+ ARRAYS - SEARCHING - SORTING Dr. Soha S. Zaghloul updated by Rasha M. AL_Eidan 2015.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
30/10/ Iteration Loops Do While (condition is true) … Loop.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
04/11/ Arrays 1D Arrays Defining, Declaring & Processing.
Count and add list of numbers From user input and from file.
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
September 26, 2011 Sorting and Searching Lists. Agenda Review quiz #3 Team assignment #1 due tonight  One per team Arcade game Searching  Linear  Binary.
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
Homework #1: C++ Basics, Flow of Control, and Function Basics By J. H. Wang Mar. 13, 2012.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.
Programming Fundamentals I Java Programming Spring 2009 Instructor: Xuan Tung Hoang TA: Tran Minh Trung Lab 03.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
 Software Development Life Cycle  Software Development Tools  High Level Programming:  Structures  Algorithms  Iteration  Pseudocode  Order of.
Controlling Program Flow with Decision Structures.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Data Structures Arrays and Lists Part 2 More List Operations.
Selection Using IF THEN ELSE CASE Introducing Loops.
Marr CollegeHigher Software DevelopmentSlide 1 Higher Computing Software Development Topic 4: Standard Algorithms.
while Repetition Structure
Lecture – 2 on Data structures
Write code to prompt for 5 grades, read them in, print “Thank you”, then reprint the 5 grades and their average. cout >
Standard Algorithms Higher Computing.
Department Array in Visual Basic
Standard Algorithms Input validation Finding the minimum
Do While (condition is true) … Loop
24 Searching and Sorting.
Python Basics with Jupyter Notebook
Incremental Programming
Presentation transcript:

Standard Algorithms Find the highest number

! Your name and today’s date ! Find the maximum Dim numbers(20) As Integer

Generate Numbers (uses a fixed loop) Algorithm !fill array with random numbers For counter = 1 To 20 numbers(counter) = a random number Print numbers(counter) Next counter

Generate Numbers (in True Basic) SUB generate(numbers()) !FILL array with random numbers Randomize FOR counter = 1 To 20 LET numbers(counter) = Int((50 * Rnd) + 1) PRINT numbers(counter) NEXT counter END SUB

Find The Highest Number Algorithm 1.Set index to 1 2.Set largest to first number in list 3.Start Do loop 4. If numbers(index) > largest Then 5. largest = numbers(index) 6. End If 7. add 1 to index 8.Loop Until end of list 9.Print "The highest number is " ; largest

Find The Highest Number in True Basic Sub Highest(numbers()) !FIND MAXIMUM Let index = 1 Let largest = numbers(index) Do If numbers(index) > largest Then let largest = numbers(index) End If let index = index + 1 Loop Until index > 20 PRINT "The highest number is " ; largest End Sub

Find The Lowest Number Algorithm 1.Set index to 1 2. LET smallest = first number in list 3.Start Do loop 4. If first number in list < smallest Then 5. LET smallest = first number in list 6. End If 7. add 1 to index 8.Loop Until end of list 9.Print smallest number

Find The Lowest Number in True Basic Sub Lowest(numbers()) !FIND MINIMUM LET index = 1 LET smallest = numbers(index) Do If numbers(index) < smallest Then LET smallest = numbers(index) End If LET index = index + 1 Loop Until index > 20 PRINT"The lowest number is “; smallest End Sub

Linear Search Algorithm 1.Get number_to_look_for from User 2.Use WHILE loop to validate input 3.Set found to 0 4.Set index to 1 5.Start Do loop 6. If number_to_look_for = numbers(index) Then 7. set found to 1 8. End If 9. add 1 to index 10.Loop Until found Or end of list reached

Linear Search Algorithm continued 12. If found Then 13. suitable message Else 14. not found message

Linear Search in True Basic Sub Search(numbers()) !LINEAR SEARCH Input prompt “What number do you wish to look for “: number_to_look_for DO WHILE number_to_look_for 50 Input prompt “number not valid – it must be between 1 and 50 “: number_to_look_for Loop LET found = 0!number has not yet been found LET index = 1! to start at first number in list continue

Linear Search in True Basic continued Do If number_to_look_for = numbers(index) Then LET found = 1 ! number found End If index = index + 1 ! go to next number in list Loop Until found = 1 Or index > 20 If found = 1 Then Print number_to_look_for ; " is in the list" Else Print number_to_look_for ; " is NOT in the list" End If End Sub

Counting Occurrences Algorithm Set occurrences to 0 Set index to1 Get number from user and validate Start Loop If numbers(index) = number_to_find Then add 1 to occurrences End If add 1 to index Loop till end of list Print relevant message

Counting Occurrences in True Basic Sub count_occurences(numbers()) Let occurrences = 0 Let index = 1 Input prompt "Please enter the number you wish to find“: number_to_find

Counting Occurrences in True Basic (cont) Do While number_to_find 50 Input prompt “Invalid data - Please enter a number between 1 and 50 “: number_to_find Loop Do If numbers(index) = number_to_find Then occurrences = occurrences + 1 End If index = index + 1 Loop Until index > 20 Print "The number of times that " ; number_to_find ; " appeared on the list is " ; occurrences End Sub