The Need for Algorithms

Slides:



Advertisements
Similar presentations
101.  Take a look at this code and tell me what generation of programming language is used here. It is important that you can EXPLAIN how you came up.
Advertisements

8 Algorithms Foundations of Computer Science ã Cengage Learning.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
9-Aug-15 Vocabulary. Programming Vocabulary Watch closely, you might even want to take some notes. There’s a short quiz at the end of this presentation!
“The study of algorithms is the cornerstone of computer science.” Algorithms Fall 2011.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
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.
Introduction to CSCI 1311 Dr. Mark C. Lewis
How Do You Make a Program Wait?
AP CSP: Making Visualizations & Discovering a Data Story
AP CSP: Creating Functions & Top-Down Design
ORAL WORK.
Creativity of Algorithms & Simple JavaScript Commands
JavaScript/ App Lab Programming:
AP CSP: Cleaning Data & Creating Summary Tables
Algorithms and Problem Solving
Introduction: Computer programming
AP CSP: Sending Binary Messages with the Internet Simulator
AP CSP: The Need for Programming Languages and Algorithms
Introduction to Analysis of Algorithms
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
AP Computer Science Principles
Unit 3: Lesson 1 - The Need for Programming Languages
Unit 3 lesson 2&3 The Need For Algorithms- Creativity in Algorithms
Creativity in Algorithms
Lesson 5-15 AP Computer Science Principles
The Need for Programming Languages
The Need for Algorithms 2 days
Looping and Random Numbers
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer.
Unit 8 Learning a foreign language.
Foundations of Programming: Introduction to Programming
Foundations of Computer Science
Creativity in Algorithms
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
Understanding Tens and Ones
Lesson 15: Processing Arrays
UNIT 3 CHAPTER 1 LESSON 4 Using Simple Commands.
DAY 1 - Explore - AP Performance Task Prep
This Lecture Substitution model
Computational Thinking for KS3
Ways to Use Writing.
Open on the student drive
Solving Linear Equations
Computer Programming.
4. Computational Problem Solving
Algorithm and Ambiguity
Functions.
Algorithms and Problem Solving
6 Steps for Resolving Conflicts
PYTHON: BUILDING BLOCKS Sequencing & Selection
Unit 3 lesson 2-5 The Need For Algorithms- Creativity in Algorithms – Simple Commands - Functions Day 18.
COMPUTATIONAL THINKING COMPUTATIONAL THINKING IN PROGRAMMING
Writing your Elevator Pitch
U3L1 The Need For Programming
Unit 3: Lesson 1 - The Need for Programming Languages
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
This Lecture Substitution model
Basic Concepts of Algorithm
This Lecture Substitution model
Type Topic in here! Created by Educational Technology Network
Review of Previous Lesson
U3L2 The Need For Algorithms
Starter.
U3L4 Using Simple Commands
Presentation transcript:

The Need for Algorithms Lesson 3-2 – AP Computer Science Principles

Objectives Students will be able to: Trace programs written in the "Human Machine Language" Develop an algorithm to find the smallest playing card in a row of cards Express an algorithm in the "Human Machine Language" Identify the properties of sequencing, selection and iteration the "Human Machine Language" Evaluate the correctness of algorithms expressed in the "Human Machine Language"

Programming Languages Last time’s activity focused on the inherent difficulties of trying to express precise processes with written language. We arrived at a few conclusions… We need to agree on a set of commands and exactly what terms mean The fewer commands we have, the easier it is to agree We want to know what are the “primitive” operations - the most basic set of operations that will allow us to do most of the tasks that the situation requires.

Algorithms Language is important, but there is another part to programming. Once you have a well defined language you need to apply it to problems. The art (and science) of using a well-defined language of primitive operations to solve problems is the art and science of algorithms. The CS Principles definition of algorithm is: Algorithms are precise sequences of instructions for processes that can be executed by a computer and are implemented using programming languages.

Algorithms One way to think of the study of algorithms is that it is the study of processes – how can you use a small set of instructions to clearly and correctly define process that will solve some problem? With the LEGO blocks, you also attempted to design an algorithm. Any time you are trying to write a precise set of instructions for a process to solve a problem you are designing an algorithm. Today we’re going to get into algorithms a little more deeply.

Computational Processes Perhaps it goes without saying that in a Computer Science class we are concerned with not just any processes, but computational processes - ones that can be executed by a computer - which have specific sets of constraints. We often get started thinking about algorithms and computational processes by trying to rigorously act them out ourselves as a sort of “Human Machine”. When acting as a machine, we can keep the limitations of a computer in mind. In this activity you’re going to pretend that you are a “Human Machine” that operates on playing cards on the table.

Activity… In this activity, you’ll design an algorithm to find the smallest item in a list.  Obviously, if we were really writing instructions for a person, we could simply tell them: “find the smallest item in a list.”  But that won’t work for a computer.

Rules We’ll use playing cards face down on the table to represent a list of items.  Start with 8 random cards face down in a row. Any card on the table must be face down. When acting as the machine, you can pick up a card with either hand, but each hand can only hold one card at a time. You can look at and compare the values of any cards you are holding to determine which one is greater than the other. You can put a card back down on the table (face down), but once a card is face down on the table, you cannot remember (or memorize) its value or position in the list.

Write an algorithm to find the card with the lowest value in the row of cards. Goal: The algorithm must have a clear end to it.  The last instruction should be to say: “I found it!” and hold up the card with the lowest value. The algorithm should be written so that it would theoretically work for any number of cards (1 or 1 million). Write your algorithm out on paper as a clear list of instructions in “pseudocode.”  Your instructions can refer to the values on cards, and a person’s hands, etc., but you must invent a systematic way for finding the smallest card.

Let’s Look at your Algorithms

Journal As we look at these algorithms you came up with, we can see they are not all the same. However, there are common things that you are all making the human machine do and commonalities in some of your instructions. Can we define a language of common Human Machine commands for moving cards around? What are the commands or actions most of these instructions have in common?”

The “Human Machine” Language We have just identified a set of primitive commands that we can use to operate on a set of cards. To be very concrete let’s formalize this into a language…

Activity Guide - The “Human Machine” Language Read the first page of the Activity Guide. Look at the programs on page 2 and write down what the programs do.

Challenge This problem we identified with the last example speaks to the art and science of algorithm design and what can make it so interesting. The question is: Can we fix the problem without adding more commands to the language? If we can fix a problem without extending the language, that’s a good thing. We can focus our attention on designing algorithms given these constraints.

Challenge – What’s Changed? All cards are face up Card positions have numbers Don’t need to pick up cards or put them down There is actually no way to move cards at all - only hands The ending state is well defined - left hand touching the min card.

Shortest Solutions

The “Art” of Programming Last time we discussed the need for a programming language Today we came up with our own programming language and used it to implement an algorithm. The CSP definition of algorithm is: “a precise sequence of instructions for processes that can be executed by a computer and are implemented using programming languages.”

The “Art” of Programming Different algorithms can be developed to solve the same problem Even though you were all trying to solve the same problem (find min) as a class we came up with different methods for doing it. We would say we came up with different algorithms. Different code can be written to implement the same algorithm This is sometimes surprising to newcomers. When writing “code” (even with the human machine language) two people trying to write code to implement the same algorithm may very easily code it differently

The “Art” of Programming These two facts - Different algorithms can be developed to solve the same problem and different code can be written to implement the same algorithm - embody art of programming and what makes programming so fun, engaging and creative. In programming, just like art, we strive to make beautiful things: A beautiful algorithm is an elegant and clever idea for how to solve a problem. A beautiful program is an elegant use of whatever language structures are provided to make the algorithm actually work on a computer.