Algorithms, Algorithmic Thinking and Structured Code.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

 Control structures  Algorithm & flowchart  If statements  While statements.
Computer Science 101 Overview of Algorithms. Example: Make Pancakes Prepare batter Beat 2 eggs Add 1 tablespoon of brown sugar Add 1 cup of milk Add 2.
What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each.
Program Design and Development
Pseudocode and Algorithms
8/8/ Inequalities. 8/8/ Bumper Cars You must be at least 130cm tall to ride the bumper cars. This can be represented by the inequality.
1 Chapter 1 Measurements 1.4 Significant Figures in Calculations Copyright © 2009 by Pearson Education, Inc.
Adapted from slides by Marie desJardins
© 2007 by S - Squared, Inc. All Rights Reserved.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
An ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time Let's examine the four parts of this.
Introduction to Python
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
Invitation to Computer Science, Java Version, Second Edition.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
By the end of this session you should be able to...
CPSC 171 Introduction to Computer Science Algorithm Discovery and Design.
7 A&F 1.1 OBJECTIVE Use variables & operations to write an expression We LOVE Mathematical Language!!!
Chapter 2: General Problem Solving Concepts
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Basic Control Structures
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
< < < > < > <
ALGORITHMS.
Solving One-Step Equations © 2007 by S - Squared, Inc. All Rights Reserved.
Addition, Subtraction, Multiplication, Division by a whole number, and Division by a decimal.
Arithmetic Operators. Operators In Programming Most computer programming languages use the following symbols for their operators: +  add -  subtract.
Session 4: Atomic Language. Take Turing Machine Look back to 1 st session’s work on hardware, RISC and CISC register- based machines. Also look forward.
One Step Equations and Inequalities Review
3.4 Algorithms for Multiplication and Division Remember to Silence Your Cell Phone and Put It In Your Bag!
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
2.2 Solving Two- Step Equations. Solving Two Steps Equations 1. Use the Addition or Subtraction Property of Equality to get the term with a variable on.
Unit 1 Lessons 2&3 Solving Equations by Adding, Subtracting, Multiplying, or Dividing Standards: CC.9-12.A.REI.1, CC.9-12.A.REI.3, CC.9-12.A.CED.1 EQ:
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
Algorithms and Algorithmic Thinking. Instructions on making a Jam Sandwich.
Write, Interpret and Use Mathematical Expression and Equations.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
0.1 Solving One-Step Equations. To solve an equation means to find all values of the variable that make the equation true. Isolate the variable to one.
Program design Program Design Process has 2 phases:
Students will use inverse operations to solve one-step equations.
Students will use inverse operations to solve one-step equations.
Students will use inverse operations to solve one-step equations.
ALGORITHMS AND FLOWCHARTS
ONE STEP EQUATIONS.
ONE STEP EQUATIONS.
Solving 1-Step Integer Equations
ALGORITHMS AND FLOWCHARTS
Students will use inverse operations to solve one-step equations.
Students will use inverse operations to solve one-step equations.
Inequalities 12/3/2018.
6.5 Inequalities 12/3/2018.
Algorithm Discovery and Design
ALGORITHMS AND FLOWCHARTS
EQ: How do I solve an equation in one variable?
1.3 Solving Linear Equations
Introduction to Algorithms and Programming
Algorithm and Ambiguity
Introduction to Algorithms - 1
Computer Science Core Concepts
Students will use inverse operations to solve one-step equations.
Ch. 1.3 Solving Linear Equations
Multiply and divide Expressions
ONE STEP EQUATIONS WHAT?!?!.
ONE STEP EQUATIONS.
Students will use inverse operations to solve one-step equations.
Implementing Variables in Your Programs
ONE STEP EQUATIONS.
COMPUTING.
Presentation transcript:

Algorithms, Algorithmic Thinking and Structured Code

Tell me how to make a Jam Sandwich

Tell me how to draw this tree (write the instructions in Simple English)

Tell me how to count the money in my right pocket (write the instructions in Simple English)

Origins of Algorithms Edsger Wybe Dijkstra

Spaghetti Code mov eax,3 mov ebx,3 L1: decjmpreg eax,L2 decjmpreg ebx,L3 jmp L1 L2: eax = 0 decjmpreg ebx, L4 jmp L5 L3: ebx = 0 inc eax decjmpreg eax, L4 jmp L5 L4: mov eax,0 hlt L5: mov eax,1 hlt

“Peeling Potatoes for a Family Supper” We observe the cook doing this “He gets the potato basket from the cellar, gets the pan from the cupboard, peels the potatoes returns the basket to the cellar” Sequence

“Go to the other side of the road” “Go to Hell” Meaningful Instructions Effective

Meaningful Instructions Unambiguous A wedding journalist reported that the four bridesmaids wore the same dress.

Instructions “He gets the potato basket from the cellar, gets the pan from the cupboard, peels the potatoes returns the basket to the cellar” get the potato basket from the cellar, get the pan from the cupboard, peel the potatoes return the basket to the cellar Sequence: Correct Order

Jordan does something different get the potato basket from the cellar, get the pan from the cupboard, IF clothes are light colored THEN put on an apron peel the potatoes return the basket to the cellar IF some condition THEN some action Selection

“peel the potatoes” Halting

“peel the potatoes” IF number of peeled potatoes is not sufficient THEN peel a potato

“peel the potatoes” WHILE the number of potatoes is insufficient DO peel a potato get the potato basket from the cellar, get the pan from the cupboard, IF clothes are light colored THEN put on an apron WHILE the number of potatoes is insufficient DO peel a potato return the basket to the cellar WHILE condition is true DO an action Iteration

“peel the potatoes” Instruction Blocks WHILE condition is true DO action1 action2 action3 END WHILE

Algorithms – a definition Sequence of Instructions (ordered) Instructions are Effective and Unambigous Sequence must Halt in a finite time On halting, the sequence must have a Result Instructions may be Simple Actions Selections Iterations action IF condition THEN action WHILE condition is true DO action

Pseudo-code for Structured Programming WHILE condition is true action END WHILE DO action WHILE condition is true IF condition is true action END IF actions move robot forward by 20 cm get a coin from your pocket press a key on your phone conditions robot sensor shows obstacle coin is a 50p pocket is empty key pressed is 7 compound conditions NOT condition1 condition1 AND condition2 condition1 OR condition2 actions add, subtract, multiply, divide get, put (set) conditions equals less than, greater than combi’s of above

Pseudo-code Examples 1.Robot moves forward until senses obstacle 2.Check that you have typed in a password that ends with 5 3.Check that you have entered a 6-digit phone number

Computational Thinking - 1

Computational Thinking – 2 (Eight Coins Puzzle)

Dr.C’s “Atomic Language” Conjecture (weak version) Any computer program can be expressed using only the following: Declaration: as many variable you need Just 2 Operations: One loop construct: We do not need: IF condition THEN action FOR loop Operations of multiplication, division and anything else. WHILE condition action END WHILE add1 to a variable subtract 1 from a variable

Music Algorithmic?

get the potato basket from the cellar, get the pan from the cupboard, peel the potatoes return the basket to the cellar

I Have A Lovely Bunch Of Coconuts

x = 5 Y = 3 Temp = X X = Y Y = Temp

Computational Thinking – 3 Eight Coins Puzzle