What's The Plan?: Algorithmic Thinking

Slides:



Advertisements
Similar presentations
Chapter 11: Models of Computation
Advertisements

College of Information Technology & Design
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Algorithmic Thinking What’s the Plan? lawrence snyder c h a p t e r 10.
8 Algorithms Foundations of Computer Science ã Cengage Learning.
Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the five essential properties of an algorithm.
Chapter 10 Algorithmic Thinking. Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Learning Objectives List the five essential.
Chapter 10 What's The Plan?: Algorithmic Thinking.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Introduction to Computers CS Dr. Zhizhang Shen Chapter 10: How to.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Chapter 2 The Algorithmic Foundations of Computer Science
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Chapter 2: Algorithm Discovery and Design
Algorithms Algorithms are a familiar idea. Our goal is to learn to specify them right so someone or something else does the work.
Invitation to Computer Science, Java Version, Second Edition.
Some quotes…. I really hate this damned machine I wish that they would sell it. It never does quite what I want But only what I tell it. ~Anon These machines.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
Algorithms CS139 – Aug 30, Problem Solving Your roommate, who is taking CS139, is in a panic. He is worried that he might lose his financial aid.
Lecture 6 Problem Solving: Algorithm Design & Analysis.
Algorithms Algorithms are a familiar idea. Our goal is to learn to specify them right so someone or something else does the work.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
What's The Plan? Algorithmic Thinking Step-by-step directions for whatever someone, or the computer, needs to do © 2004 Lawrence Snyder.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
Chapter 10 Algorithmic Thinking. Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Chapter 2 Principles of Programming and Software Engineering.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004.
CPS Today’s topics l Algorithms and pseudocode l Notes adapted from Marti Hearst at UC Berkeley and David Smith at Georgia Tech Upcoming ä Beginning.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
CMSC 104, Version 8/061L05Algorithms2.ppt Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode Control Structures Reading Section 3.1.
Principles of Programming & Software Engineering
Chapter 13 Recursion Copyright © 2016 Pearson, Inc. All rights reserved.
ICS 3UI - Introduction to Computer Science
Data Abstraction: The Walls
Algorithms and Problem Solving
Principles of Programming and Software Engineering
Chapter 2 Limits Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Algorithm and Ambiguity
CS 240 – Lecture 11 Pseudocode.
Computer Programming.
Chapter 17 Linked Lists.
Chapter 4 Inheritance.
Algorithms Chapter 3 With Question/Answer Animations
Copyright © Cengage Learning. All rights reserved.
PROBLEM SOLVING SKILLS
Objective of This Course
INFO/CSE 100, Spring 2005 Fluency in Information Technology
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
CSCI 1250 Information Technologies
Chapter One: An Introduction to Programming and Visual Basic
Algorithm and Ambiguity
Chapter 10: Algorithm TECH Prof. Jeff Cheng.
Algorithms and Problem Solving
What's The Plan?: Algorithmic Thinking
The Facts to Be Explained
Classes, Objects and Methods
Introduction: Some Representative Problems
Basic Concepts of Algorithm
What's The Plan?: Algorithmic Thinking
Chapter 13 Recursion Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Early Midterm Some Study Reminders.
Chapter 6 Dynamic Programming.
Chapter 2 Reference Types.
Chapter 4 Greedy Algorithms.
Presentation transcript:

What's The Plan?: Algorithmic Thinking Chapter 10 What's The Plan?: Algorithmic Thinking

Algorithm A precise, systematic method for producing a specified result We have already seen several: Recognition of a button click (Ch.1) Placeholder technique (Ch.2) Hex to bits (Ch.8) Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Algorithms in Everyday Life Some algorithms are learned—arithmetic Some we figure out ourselves—looking up a phone number Others require written instructions—recipe, assembly instructions, driving directions Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Five Essential Properties of Algorithms Input specified Data to be transformed during the computation to produce the output Must specify type, amount, and form of data Output specified Data resulting from the computation— intended result It is possible to have no output Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Five Essential Properties (cont'd) 3. Definiteness Specify the sequence of events Details of each step, including how to handle errors 4. Effectiveness The operations are doable 5. Finiteness Must eventually stop Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Language in Algorithms Natural language For people, we use a natural language like English Ambiguity is common in natural language Programming Language Formal languages designed to express algorithms Precisely defined; no ambiguity Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

The Context of a Program Program can fulfill five properties of an algorithm, be unambiguous, and still not work right because it is executed in the wrong context e.g., last name in Western countries means family name; in Asian countries it may mean given name Context matters: Driving instructions "From the Limmat River go to Bahnhof Strasse and turn right." Assumes you are traveling in a specific direction. If you are not, the directions will fail Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Program vs. Algorithm A program is an algorithm that has been customized to solve a specific task under a specific set of circumstances using a specific language Algorithm is a general method; program is a specific method Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

An Algorithm: Alphabetize CDs Imagine CDs in a slotted rack, not organized You want to alphabetize by name of group, performing musician, or composer How do you solve this problem? Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Alphabetize CDs (cont'd) Input: An unordered sequence of CDs filling a slotted rack Output: The same CDs in the rack in alphabetical order Instructions: Use the term Artist_Of to refer to the name or the group or musician or composer on a CD Decide which end is the beginning of the sequence and call the slot at that end the Alpha slot Call the slot next to Alpha the Beta slot Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Alphabetize CDs (cont'd) If the Artist_Of the CD in Alpha comes later in alphabet than the Artist_Of in Beta, swap the CDs; otherwise continue on If there is a slot following Beta, begin calling it Beta and go to Instruction 4; otherwise continue on If there are two or more slots following Alpha, begin calling the slot following Alpha, Alpha and begin calling the slot following it Beta, and go to Instruction 4; otherwise stop Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Instruction 1 Use the term Artist_Of to refer to the name of the group or musician or composer on a CD This gives a name to the operation of locating the name used for alphabetizing Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Instruction 2 Decide which end of the rack is the beginning of the alphabetic sequence and call the slot at that end the Alpha slot Gives the process a starting point. Defines the word Alpha. At the start, Alpha refers to the first slot in the sequence; as the algorithm progresses it refers to successive slots Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Instruction 3 Call the slot next to the Alpha slot the Beta slot Gives Beta its initial meaning. Alpha and Beta have no inherent meaning; they are chosen by the programmer to name slots in the rack Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Instruction 4 If the Artist_Of the CD in the Alpha slot comes later in the alphabet than the Artist_Of the CD in the Beta slot, swap the CD's; otherwise continue on This is the workhorse instruction of the algorithm. It compares the names of the artists of the CDs in Alpha and Beta and, if necessary, swaps them so that they are in the correct order Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Instruction 5 If there is a slot following the Beta slot, begin calling it the Beta slot and go to Instruction 4; otherwise, continue Re-defines Beta slot so that it refers to the next slot in the sequence, if any. Then Instruction 4 can be executed again, comparing a different pair of CDs Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Instruction 6 If there are two or more slots following the Alpha slot, begin calling the slot following the Alpha slot Alpha and the slot following it Beta, and go to Instruction 4; otherwise stop By the time we get to this instruction, the alphabetically earliest CD is in the Alpha slot. We advance Alpha to the next slot and sweep through the CD rack again, locating the alphabetically earliest CD. When there are no longer enough slots to call one Alpha and one Beta, the entire rack has been alphabetized and the algorithm stops Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Analyzing Alphabetize CDs Algorithm Illustrates the five basic properties of algorithms Inputs and Outputs were listed Each instruction was defined precisely (definiteness) Operations are effective because they are simple and mechanically doable Alphabetizing is mechanical, so our algorithm is effective Finiteness is satisfied because there are only a finite number of slots that can be paired, so instructions 4, 5, and 6 cannot be repeated indefinitely Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

A Deeper Analysis Structural features Two instructions, 5 and 6, in which the agent is directed to go back and repeat instructions. This is called a loop Loops and Tests A loop must include a test to determine whether the instructions should be repeated one more time Assumptions We assume that The CD rack is full (instructions do not handle the case of an empty slot) The word "following" means a slot further from the start point Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

The Exchange Sort Algorithm The Alphabetize CDs example illustrates the standard Exchange Sort algorithm The idea of comparing pairs of items chosen in a particular way, exchanging them if they are out of order, and continuing to sweep through the items We could use the same algorithm to sort on a different principle Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Abstraction in Algorithmic Thinking Thinking of parts of the algorithm's behavior as whole units rather than individual instructions Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Beta Sweep Abstraction Instructions 4 and 5 illustrate abstract computational unit, which we'll call Beta Sweep Operation of considering in order all CDs following a specific Alpha While Alpha points to a fixed slot, Beta visits each slot following Alpha, in sequence, comparing its CD with the CD in the Alpha slot, and swapping when necessary Has the effect of finding the next CD in order and moving it to the Alpha slot Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Alpha Sweep Abstraction Alpha sweeps from the slot where alphabetization begins through all slots (except the last), performing the Beta sweep instructions each time Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Properties of Alpha Sweep Abstraction Exhaustive. Considers all CDs from the first to (but not including) the last Nonredundant. No slot is assigned to Alpha more than once, so the process stops if the Beta sweep stops Progressive. At the end of each Beta sweep, the alphabetically next earliest CD is in Alpha Complete. When the last Beta sweep is completed, the CD in the last slot is later than the CD in the next-to-last slot Goal-achieving. The alphabetically earliest CD is in the first slot at the end of the first Beta sweep, by its property 4 and the fact that all CDs are considered; thereafter, in every new position for Alpha the Beta sweep assigns the next earliest CD. The program alphabetizes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Abstracting for Other Algorithms and Programs The Alpha sweep and Beta sweep abstractions are specific to the Exchange Sort algorithm and to programs derived from it Other algorithms and programs exhibit different behaviors and require different abstractions, which will have different properties Every situation is different, but the approach—abstracting the behavior and understanding the properties—is always the same Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.

Copyright © 2006 Pearson Addison-Wesley. All rights reserved.