Standard Algorithms Higher Computing.

Slides:



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

Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Standard Algorithms. 4 Standard Algorithms Input Validation Finding the Maximum / Minimum Counting Occurrences Linear Search.
Objectives In this chapter, you will learn about:
Standard Algorithms. Many algorithms appear over and over again, in program after program. These are called standard algorithms You are required to know.
Efficiency of Algorithms
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.
Designing Algorithms Csci 107 Lecture 3. Administrativia Lab access –Searles 128: daily until 4pm unless class in progress –Searles 117: 6-10pm, Sat-Sun.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Higher Grade Computing Studies 4. Standard Algorithms Higher Computing Software Development S. McCrossan 1 Linear Search This algorithm allows the programmer.
Chapter 7 Array processing. Objectives To introduce arrays and the uses of arrays To develop pseudocode algorithms for common operations on arrays To.
Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.
Array Processing.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
CSC 211 Data Structures Lecture 13
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
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.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
Algorithms and Pseudocode
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Selection Using IF THEN ELSE CASE Introducing Loops.
Algorithms and Pseudocode CS Principles Lesson Developed for CS4 Alabama Project Jim Morse.
Marr CollegeHigher Software DevelopmentSlide 1 Higher Computing Software Development Topic 4: Standard Algorithms.
CIS 115 All Exercises Devry University (Devry) FOR MORE CLASSES VISIT CIS 115 All Exercises Devry University.
CIS 115 AID Teaching Effectively/cis115aid.com FOR MORE CLASSES VISIT
Component 1.6.
CIS 115 Slingshot Academy / cis115.com
16 Searching and Sorting.
3.1 Fundamentals of algorithms
A451 Theory – 7 Programming 7A, B - Algorithms.
Outline lecture Revise arrays Entering into an array
while Repetition Structure
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Control Structures II Chapter 3
Topics Introduction to Repetition Structures
Lecture – 2 on Data structures
Chapter 5: Control Structure
Algorithm Analysis CSE 2011 Winter September 2018.
Topics Introduction to Repetition Structures
Starter Write a program that asks the user if it is raining today.
CIS 115 Possible Is Everything/snaptutorial.com
CIS115 Education for Service-- snaptutorial.com
CIS 115Competitive Success/tutorialrank.com
CIS 115 Teaching Effectively-- snaptutorial.com
Siti Nurbaya Ismail Senior Lecturer
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Standard Algorithms Input validation Finding the minimum
Introduction to pseudocode
Iteration: Beyond the Basic PERFORM
Loops CIS 40 – Introduction to Programming in Python
Algorithm Discovery and Design
Algorithm and Ambiguity
24 Searching and Sorting.
M150: Data, Computing and Information
Using the Target Variable Inside the Loop
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
CHAPTER 4 Iterative Structure.
Programming Logic and Design Fifth Edition, Comprehensive
Topics Introduction to Repetition Structures
Unit 2: Computational Thinking, Algorithms & Programming
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Arrays & Loops.
Presentation transcript:

Standard Algorithms Higher Computing

Standard Algorithms Standard Algorithms Many algorithms appear over and over again, in program after program. These are called standard algorithms You are required to know about 5 of these algorithms: Input Validation Linear search Counting occurences Finding the maximum value Finding the minimum value

Standard Algorithms What is Input Validation Input validation checks user input to see if it’s within a valid number range. If it’s outside the valid range the algorithm asks for the number again until it falls within the acceptable range.

Standard Algorithms Input Validation Pseudocode 1 Get and store value 2 Loop WHILE data is out with range 3 Display error message 4 Prompt user to re-enter value 5 End loop

Standard Algorithms What is Linear Search? Linear search is the simplest search method to implement and understand. Starting with an array holding 8 numbers with a pointer indicating the first item, the user inputs a search key. Scanning then takes place from left to right until the search key is found, if it exists in the list.

Standard Algorithms Linear Search (The search item is 76) Each item is checked to see if it 76, until 76 is found or the last item is checked.

Standard Algorithms Linear Search Pseudocode Set found to false Get search value Start at first element on the list Do while (not end of list) AND (found is false) If current element = search value Then Set found = true Display found message Else Move to next element in the list End If Loop If found = false Then Display not found message

Standard Algorithms What is Counting Occurrences Programs often have to count occurrences. Examples include counting the number of: students who achieved particular marks in an exam rainfall measurements greater than a particular level words equal to a given search value in a text file. The basic mechanism is simple: 1. a counter is set to 0 2. a list is searched for the occurrence of the search value 3. every time the search value occurs, the counter is incremented

Standard Algorithms Counting Occurrences Algorithm Set counter = 0 Get search value Set pointer to start of the list Do If search item = list(position) Then Add 1 to counter End If Move to next position Until end of list Display number of occurrences

Standard Algorithms Maximum And Minimum Algorithms Computers are often used to find maximum and minimum values in a list. For example, a spreadsheet containing running times for videos might make use of a maximum algorithm to identify the video with the longest running time, or a minimum algorithm to identify the shortest running time. To find a maximum, we set up a variable which will hold the value of the largest item that has been found so far, usually the first element. If an element in the array exceeds this working maximum, we give the working maximum that value.

Standard Algorithms Maximum Pseudocode Set maximum value to first item in this list Set current position to 1 Do If list(position) > maximum Then set maximum equal to list(position) End If Move to next position Until end of list Display maximum value

Standard Algorithms Minimum Pseudocode Set minimum value to first item in ths list Set current position to 1 Do If list(position) < minimum Then set minimum equal to list(position) End If Move to next position Until end of list Display minimum value

Standard Algorithm Exam Questions Lane Time (secs) 1 40.23 2 41.05 3 42.88 4 39.89 5 40.55 6 40.01 7 39.87 An international athletics competition between eight countries has a number of events. The winning times are stored in a list in order of lane number like the one on the right. The stadium needs a program to help process the results. Q1.The program must find the fastest time for a race. Use pseudocode to design an algorithm to find the fastest time (4 marks) Q2. It is suggested that algorithm should find the lane number of the fastest time instead of the fastest time. Explain how this could be achieved. (1 mark)

Exam Marking Scheme In summary, 1 mark for each of the following: Set fastest to first time in list For rest of array items If array(current)<fastest then Set fastest to array(current) End if End loop In summary, 1 mark for each of the following: Setting initial value Loop (with end) for traversal of array Comparison of current element with maximum value (with end if) Assignment of new maximum value

Standard Algorithm Exam Questions NoTow is a company that runs a city centre car park. The company requires a piece of software that will calculate the number of cars on a particular day that spent more than three hours in the car park. The number of whole minutes each car is parked is stored in a list as shown on the right. . 124 210 105 193 157 Q3. Use pseudocode to design an algorithm to carry out this calculation (4 marks)

Exam Marking Scheme Set over3 = 0 1 mark for initialising For each car that day If duration >180 then Add one to over3 End if End loop 1 mark for initialising 1 mark loop with termination 1 mark for if..endif with correct condition 1 mark for keeping running total Note: End of if/loop may be implicit in clearly indented algorithm The value is in minutes so the condition is > 180