Algorithms, Part 1 of 3. Problem Solving. Algorithms

Similar documents
Algorithms, Part 1 of 3

Technical Section. Lab 4 while loops and for loops. A. while Loops or for loops

CSI32 Object-Oriented Programming

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

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

Syntax Analysis. Chapter 4

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.

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

Standard Version of Starting Out with C++, 4th Edition. Chapter 19 Recursion. Copyright 2003 Scott/Jones Publishing

CSCE 110: Programming I

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

Administration Computers Software Algorithms Programming Languages

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

CSIS 104 Introduction to Computer Science

1 Elementary number theory

Algorithm Design: GCD

The Beauty and Joy of Computing 1 Lab Exercise 4: Starting a simple math tutor program and more interaction

Chapter 1 An Introduction to Computer Science. INVITATION TO Computer Science 1

Assertions & Verification Example Exam Questions

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter Lab 8 - Structures

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

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

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

CS 440 Theory of Algorithms /

Computer Science 217

Euclid's Algorithm. MA/CSSE 473 Day 06. Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

Control Statements. if for while

6.001 Notes: Section 6.1

Beyond Base 10: Non-decimal Based Number Systems

Friday Four Square! Today at 4:15PM, Outside Gates

Math Introduction to Advanced Mathematics

Pioneering Compiler Design

COE428 Lecture Notes Week 1 (Week of January 9, 2017)

Spring 2018 PhD Qualifying Exam in Languages

FYCS/SEM I/Add.CT/CSII/

Introduction. Compiler Design CSE Overview. 2 Syntax-Directed Translation. 3 Phases of Translation

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

CMPS Programming Languages. Dr. Chengwei Lei CEECS California State University, Bakersfield

Compiler Optimisation

Assertions & Verification & Example Loop Invariants Example Exam Questions

Admin ENCRYPTION. Admin. Encryption 10/29/15. Assignment 6. 4 more assignments: Midterm next Thursday. What is it and why do we need it?

CSE P 501 Exam 12/1/11

CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK

MIDTERM EXAMINATION. CSE 130: Principles of Programming Languages. Professor Goguen. February 16, points total

Syntax. A. Bellaachia Page: 1

Iteration. Chapter 7. Prof. Mauro Gaspari: Mauro Gaspari - University of Bologna -

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

Encoding and Encrypting Information

EECS 6083 Intro to Parsing Context Free Grammars

Principles of Programming Languages COMP251: Syntax and Grammars

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Harvard-MIT Division of Health Sciences and Technology HST.952: Computing for Biomedical Scientists HST 952. Computing for Biomedical Scientists

Add Binary Numbers What is the largest decimal number you can represent using 3 bits?

Beyond Base 10: Non-decimal Based Number Systems

IST 4 Information and Logic. Claude Shannon April 30,

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

COP 4516: Math for Programming Contest Notes

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

Syntax. In Text: Chapter 3

A Small Permutation Group Engine by: Gregory Kip. COMS W4115 Programming Languages and Translators Prof. Stephen Edwards

Names and Functions. Chapter 2

Homework #2. If (your ID number s last two digits % 6) = 0: 6, 12, 18

Lecture 1. Introduction

3.5 Practical Issues PRACTICAL ISSUES Error Recovery

Genome Sciences 373 Genome Informa1cs. Quiz Sec1on #1 March 31, 2015

Syntax Analysis Check syntax and construct abstract syntax tree

INFS 214: Introduction to Computing

Describing and Implementing Algorithms

Introduction to Syntax Analysis. Compiler Design Syntax Analysis s.l. dr. ing. Ciprian-Bogdan Chirila

What is recursion? Recursion. How can a function call itself? Recursive message() modified. contains a reference to itself. Week 7. Gaddis:

CS 202: Introduction to Computation Fall 2010: Exam #1

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

CS187 - Science Gateway Seminar for CS and Math

Syntactic Analysis. The Big Picture Again. Grammar. ICS312 Machine-Level and Systems Programming

Lecture 15: Iteration and Recursion

The Further Mathematics Support Programme

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1

Creating a new data type

Computer Software: Introduction

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Chapter 1: Building Blocks of Programming

Scan Scheduling Specification and Analysis

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

COMPSCI 230 Discrete Math Prime Numbers January 24, / 15

Introduction to Parsing

Consider a description of arithmetic. It includes two equations that define the structural types of digit and operator:

Algorithm Discovery and Design. Why are Algorithms Important? Representing Algorithms. Chapter 2 Topics: What language to use?

Lexical Analysis. Finite Automata

Properties and Definitions

Introduction to Lexical Analysis

Conditionals !

Modesto Junior College Course Outline of Record CMPSC 241

At 5% print coverage (A4 or Letter size). The actual number of printed pages will vary depending on the average type of print job and paper.

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT III. 2 Marks PROBLEM SOLVING AND OFFICE AUTOMATION

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Winter /15/ Hal Perkins & UW CSE C-1

UCT Algorithm Circle: Number Theory

Lecture 7 Number Theory Euiseong Seo

Transcription:

Algorithms, Part 1 of 3 Topics Definition of an Algorithm Algorithm Examples Syntax versus Semantics Reading Sections 3.1-3.3 Problem Solving Problem solving is the process of transforming the description of a problem into the solution of that problem. We use our knowledge of the problem domain. We rely on our ability to select and use appropriate problem-solving strategies, techniques, and tools. Algorithms An algorithm is a step by step solution to a problem. Why bother writing an algorithm? For your own use in the future. You won t have to rethink the problem. So others can use it, even if they know very little about the principles behind how the solution was derived. 1

Examples of Algorithms Washing machine instructions Instructions for a ready-to-assemble piece of furniture A classic: finding the greatest common divisor (GCD) using Euclid s Algorithm Washing Machine Instructions Separate clothes into white clothes and colored clothes. Add 1 cup of powdered laundry detergent to tub. For white clothes: Set water temperature knob to HOT. Place white laundry in tub. For colored clothes: Set water temperature knob to COLD. Place colored laundry in tub. Close lid and press the start button. Observations About the Washing Machine Instructions There are a finite number of steps. We are capable of doing each of the instructions. When we have followed all of the steps, the washing machine will wash the clothes and then will stop. 2

Refinement of Algorithm Definition Our old definition: An algorithm is a step by step solution to a problem. Adding our observations: An algorithm is a finite set of executable instructions that directs a terminating activity. Instructions for a Ready-to-Assemble Piece of Furniture "Align the marks on side A with the grooves on Part F. How could these instructions be hard to follow? Which side is A? A & B look alike -- both line up with Part F! This instruction is ambiguous. Final Version of the Algorithm Definition Our old definition: An algorithm is a finite set of executable instructions that directs a terminating activity. Final version: An algorithm is a finite set of unambiguous, executable instructions that directs a terminating activity. 3

History of Algorithms The study of algorithms began as a subject in mathematics. The search for algorithms was a significant activity of early mathematicians. Goal: To find a single set of instructions that can be used to solve any problem of a particular type (a general solution). Euclid s Algorithm Problem: Find the largest positive integer that divides evenly into two given positive integers (i.e., the greatest common divisor). Algorithm: 1 Assign M and N the values of the larger and smaller of the two positive integers, respectively. 2 Divide M by N and call the remainder R. 3 If R is not 0, then assign M the value of N, assign N the value of R, and return to Step 2. Otherwise, the greatest common divisor is the value currently assigned to N. Finding the GCD of 24 and 9 M N R 24 9 6 9 6 3 6 3 0 So, 3 is the GCD of 24 and 9. 4

Euclid s Algorithm (con t) Do we need to know the theory that Euclid used to come up with this algorithm in order to use it? What intelligence is required to find the GCD using this algorithm? The Idea Behind Algorithms Once an algorithm behind a task has been discovered We don't need to understand the principles. The task is reduced to following the instructions. The intelligence is "encoded into the algorithm." Algorithm Representation Syntax and Semantics Syntax refers to the representation itself. Semantics refers to the concept represented (i.e., the logic). 5

Contrasting Syntax and Semantics In the English language, we have both syntax and semantics. Syntax is the grammar of the language. Semantics is the meaning. Given the following sentence, I walked to the corner grocery store. Is this sentence syntactically correct? Is it semantically correct? Contrasting Syntax and Semantics Given the following sentence, I talked to the funny grocery store. Is this sentence syntactically correct? Is it semantically correct? How about I grocery store walked corner the to. Contrasting Syntax and Semantics Conclusion: An English sentence may be syntactically correct, yet semantically incorrect. This is also true of algorithms. And it is also true of computer code. 6