Algorithms: The recipe for computation

Similar documents
Algorithmic Thinking: Loops and Conditionals

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

CSE 201 Java Programming I. Smart Coding School website:

Important Dates. Please refer to the 2017 Fall Product Program large white envelope. These dates are permanent, and cannot be changed.

The diagram below is only partially complete. Use the terms in the word list to complete the empty boxes. Make dinner

COMPUTATIONAL THINKING

UNIT 3A Algorithmic Thinking Principles of Computing, Carnegie Mellon University GUNA

A Unicorn Named Sparkle Word Search. A New Friend for Sparkle Coloring Sheet. A Unicorn Named Sparkle s First Christmas Coloring Sheet

Introduction Jan. 22, Ch 1

Lesson 166 (Pages 27-29)

USER S GUIDE. Model 8300

Graded Project. HTML Coding

Two figures that have the exact same shape, but not necessarily the exact same size, are called similar

Building Java Programs

Introduction to Computer Programming concepts using StarLogo TNG

INSIDE THIS ISSUE. SDS Holiday Hours

Building Java Programs

Building Java Programs

SUNY PAYROLL SELF-SERVICE INSTRUCTIONS

clicker question Comments Using comments Topic 3 static Methods and Structured Programming

Scenario-Based Testing added to an Existing Development Program

Vittles Documentation

Food Storage Newsletter #9 - FREE monthly newsletter - September, 1999

Topic 7 parameters. Based on slides from Marty Stepp and Stuart Reges from

Parent Guide to 5 th Grade

Discrete Mathematics. Kruskal, order, sorting, induction

Creative Ceramics and Glass 10. Cake Plate Item # D53 10 Dx2 H. Teabag Holder Item # D /8 Hx4 W. Tumbler Item # D70 4 ¼ Hx2 ½ D

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

MAT Program Design. College of Engineering Engineering Education Innovation Center

Adding Integers with the Same Sign

Parallelism I. John Cavazos. Dept of Computer & Information Sciences University of Delaware

Recap: Structure of a Java program CS 112 Introduction to Programming. A Foundation for Programming Why Introduce Static Methods?

CS 112 Introduction to Programming

Algorithms: The recipe for computation

Building Java Programs

NYS Payroll Online Self Service. November 2017

CSc 110, Autumn 2016 Lecture 6: Parameters. Adapted from slides by Marty Stepp and Stuart Reges

Algorithms II Can t stop, won t stop

CSE 142, Summer 2015

MASSACHUSETTS VOCATIONAL TECHNICAL TEACHER TESTING PROGRAM SCOPE OF TEST CODE #11 - CULINARY ARTS WRITTEN EXAM QUESTIONS TIME ALLOWED: 3 HOURS

Algorithms are the threads that tie together most of the subfields of computer science.

Symmetry Students complete symmetric figures that are partially given and create their own symmetric figures.

DRAFT Montana Individual Income Tax Table (TO BE UPDATED) If Your Taxable This Is. But Not More And Subtract. Income Is More Your Tax Than

5 th Grade Hinojosa Math Vocabulary Words

2.8 An application of Dynamic Programming to machine renewal

Lecture 1: Introduction

3.3 Division of Fractions and of Mixed Numbers

Algorithms Overview (1A) Young Won Lim 3/29/18

Building Java Programs

Algorithms (7A) Young Won Lim 4/18/17

(2 1) What does evaluate to? What does evaluate to? What does evaluate to?

Revision on fractions and decimals

Building Java Programs

1. Scan & Search In the main search screen there will be a second button below the search button, Scan and Search.

Senior Sense. Inside this issue: Specialist visits are just that special. University of Georgia Family & Consumer Sciences. Seeing A Specialist

Grade 7 Math LESSON 14: MORE PROBLEMS INVOLVING REAL NUMBERS TEACHING GUIDE

1.1, 1.2 Notes. 1.1: Mathematics and Problem Solving

Brevard County 4-H Fair 2018 Exhibits Rule Book

Introduction to Programming in C Department of Computer Science and Engineering\ Lecture No. #02 Introduction: GCD

MATHEMATICS A FAMILY GUIDE FOR STUDENT SUCCESS 18

CSE 142, Summer 2014

WELCOME TO CS 24! Enrollment status: 105/105, Read the syllabus. Know what s required. Know how to get help. Problem Solving with Computers-II

shaping covering with chocolate Macro Cookbook for Microsoft Word sweet, sweet success! testing Jack Lyon

Lesson 10: Interpreting Graphs of Proportional Relationships

Static Methods & Decomposition

Algorithm Design: GCD

Math 7 Notes Unit Three: Applying Rational Numbers

My Diwali Book Author: Rakhee Iyer Illustrators: Gayathri Manikandan, Priya Kuriyan, Taposhi

A checklist for the new 990 requirements:

Topic 3 static Methods and Structured Programming

Lecture Set #14: Algorithms and Design

Announcements Tues., Aug and 2. to call them ( ) ! For next time, read Learning Computing with Robots, chs.

Algorithms: The recipe for computation

EECS1012. Net-centric Introduction to Computing. Lecture 7 Computational Thinking. Fall 2018, EECS York University. M.S. Brown and Amir H.

Procedural decomposition using static methods

1. Part A: a. Create ORACLE SQL Statements with appropriate PK and FKs for each table

The cuisine package. Ben Cohen. 2000/08/01, v0.5


Math 085 Final Exam Review

MATHEMATICS FOR ELEMENTARY TEACHERS I FINAL EXAM REVIEW

1 Elementary number theory

Algorithms, Part 1 of 3. Problem Solving. Algorithms

Building Big Macs. Opening Explanation. Exploring. Student Hand-out

Algorithms, Part 1 of 3

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Course Learning Outcomes for Unit I. Reading Assignment. Unit Lesson. UNIT I STUDY GUIDE Number Theory and the Real Number System

Learning Log Title: CHAPTER 3: ARITHMETIC PROPERTIES. Date: Lesson: Chapter 3: Arithmetic Properties

CIS 110: Introduction to Computer Programming. Lecture 2 Decomposition and Static Methods ( 1.4)

Example 1 Use a model to write the product of

The Further Mathematics Support Programme

Algorithms ~ Introduction to Algorithms. R K Shyamasundar

Welcome to Python! If you re the type of person who wants to know

Algorithmic Problem Solving. Penny Rheingans University of Maryland Baltimore County

Computerized Payroll Accounting User s Guide

Chapter 1: An Introduction to Computer Science. Invitation to Computer Science, C++ Version, 6-th Edition

2014 Montana Individual Income Tax Return Form 2. Mailing Address City State Zip+4

Plumbers & Steamfitters Local Union 342

CHAPTER 1: INTEGERS. Image from CHAPTER 1 CONTENTS

Gateway Regional School District VERTICAL ARTICULATION OF MATHEMATICS STANDARDS Grades K-4

MAS115: R programming Lecture 2: Pseudocode Lab Class and Technical Material: Matrices, Factors, Data frames, Lists

Transcription:

Algorithms: The recipe for computation 2A What is an algorithm? 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 1 Algorithms An algorithm is a precise rule (or set of rules) specifying how to solve some problem. (thefreedictionary.com) Mohammed al-khowarizmi (äl-khōwärēz mē) Arab mathematician of the court of Mamun in Baghdad the word algorithm is said to have been derived from his name. Much of the mathematical knowledge of medieval Europe was derived from Latin translations of his works. (encyclopedia.com) The study of algorithms is one of the key foundations of computer science. 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 2 1

The first algorithm: GCD The greatest common divisor of two numbers is the largest positive integer that divides them both. Greatest Common Divisor (GCD) by the Greek mathematician Euclid between 400 and 300 B.C. Algorithm to find the GCD of x and y: 1. Input x 2. Input y 3. If y is not 0, do the following (otherwise jump to step 4): a. Set x' equal to y b. Set y' equal to x modulo y c. Set x = x' and y = y' d. Loop back to step 3. 4. Output x as the GCD 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 3 The first algorithm (cont'd) 1. Input x 2. Input y 3. If y is not 0, do the following (otherwise jump to step 4): a. Set x' equal to y b. Set y' equal to x modulo y c. Set x = x' and y = y' d. Loop back to Step 3 4. Output x as the GCD Example: What is the GCD of 42 and 18? 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 4 2

The first algorithm (cont'd) 1. Input x 2. Input y 3. If y is not 0, do the following (otherwise jump to step 4): a. Set x' equal to y b. Set y' equal to x modulo y c. Set x = x' and y = y' d. Loop back to Step 3 4. Output x as the GCD Example: What is the GCD of 15 and 105? 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 5 A recipe is an algorithm ½ cup of butter or margarine 1 teaspoon of vanilla extract 1 cup of sugar ½ cup of unsweetened cocoa 2 eggs ½ cup of flour 1. If butter or margarine is not melted, melt in a bowl in microwave for 30 seconds at high power. 2. Blend melted butter or margarine and sugar until the mixture has a creamy consistency. 3. Add eggs & vanilla, and stir the mixture 60 times. 4. Add cocoa and flour. 5. Mix until well blended. 6. Pour into greased round glass cake pan. 7. Microwave for 8 to 9 minutes on 50% power. Brownies will be done when they are slightly moist on top and pull away from the side of the pan. Serves: 4 -- adapted from yumyum.com 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 6 3

The tax code is an algorithm 1. Write your total wages from your W-2 statements on Line 1. 2. Add up all the interest amounts from your 1099-INT forms and put the total on Line 2. 3. Gather all your 1099-G statement from the state agency that paid you unemployment compensation. Put the figure from the 1099-G on Line 3. a. If you received Alaska Permanent Fund dividends only, put the figure reported to you by the State of Alaska on Line 3. b. If you have both unemployment and Alaskan dividends, add the two figures together and put the total on Line 3. 4. Add lines 1, 2 and 3 to determine your Adjusted Gross Income (AGI) and write this on Line 4. 5. Determine your personal exemptions for Line 5. a. If you are being claimed as a dependent, check the "Yes" box on Line 5. Otherwise, check the "No" box on Line 5. b. If you are unmarried, or you are married and you are not filing a joint return, put the figure $7,950 on Line 5. Otherwise, put the figure $15,900 on Line 5. 6. Subtract Line 5 from Line 4 and write this total in Line 6. This is your taxable income. etc. - Adapted from the US Tax Code Form 1040EZ 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 7 Knitting is an algorithm 1. Hold needle with stitches in left hand; insert point of right needle in first stitch, from front to back, just as in casting on. 2. With right index finger, bring yarn from ball under and over point of right needle. 3. Draw yarn through stitch with right needle point. 4. This step now differs from casting on: Slip loop on left needle off, so new stitch is entirely on right needle. 5. This completes one knit stitch. Repeat Steps 1 through 4 in each stitch still on left needle. When the last stitch is worked, one row of knitting is completed and you can move to Step 6. 6. Now measure your work. It should be about 7" wide. If it is too wide, start over and cast on fewer stitches; if it is too narrow, start over and cast on more stitches. - Adapted from learntoknit.com 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 8 4

An algorithm is like a function F(x) = y INPUT ALGORITHM OUTPUT 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 9 What does an algorithm need? Input specification Recipes: ingredients, cooking utensils, Tax Code: wages, interest, tax withheld, Knitting: size of garment, length of yarn, needles Input specification for computational algorithms: How much data is required? What kind of data is required? In what form will this data be received by the algorithm? 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 10 5

What does an algorithm need? An algorithm requires clear and precisely stated steps that express how to perform the operations to yield the desired results. Algorithms assume a basic set of primitive operations that are assumed to be understood by the executor of the algorithm. Recipes: beat, stir, blend, bake, Tax code: deduct, look up, check box, Knitting: casting on, slip loop, draw yarn through,... Computational: add, set, modulo, output, 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 11 What does an algorithm need? Output specification Recipes: number of servings, how to serve Tax Code: tax due or tax refund, where to pay Knitting: final garment shape Output specification for computational algorithms: What results are required? How should these results be reported? What happens if no results can be computed due to an error in the input? What do we output to indicate this? 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 12 6

What makes a good algorithm? A good algorithm should produce the correct outputs for any set of legal inputs. A good algorithm should execute efficiently with the fewest number of steps as possible. A good algorithm should be designed in such a way that others will be able to understand it and modify it to specify solutions to additional problems. 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 13 Making a Peanut Butter & Jelly Sandwich Input: loaf of bread, jar of peanut butter, jar of jelly, 2 knives, plate 1. Pick up one slice of bread. 2. Put peanut butter on the bread. 3. Pick up another slice of bread. 4. Get jelly out of the jar. 5. Spread the jelly on second slice of bread. 6. Put the two slices of bread together to make your sandwich. Output? 15-105 Principles of Computation, Carnegie Mellon University - CORTINA 14 7