Академический Документы
Профессиональный Документы
Культура Документы
Administrivia
Last time Exam #1
Scores are posted Exams will be returned/discussed on Thursday
Program
Results
(computer)
implementation of an Algorithm
walls!
Only allowed the following commands: Move X
pattern
Language should be: Convenient for humans to express algorithms Convenient for computers to understand
Why not Natural Languages ? (like English)
Machine Language
0001110010000110 1101110110000010 0101001100110111
Sequence of instructions in binary code Code corresponds directly to instruction set of computer
Assembly Language
LW r5, 0(r10) LW r6, 4(r10) ADD r7, r5, r6 SW r7, sum
These instructions typically correspond 1-to-1 with machine
language instructions Mnemonic codes Symbolic names (like sum) Direct control over the hardware Still hard to use and not portable
High-Level Languages
sum = 5 + 6;
Examples: C++, Fortran, Java, Python, Maple, Matlab,
Mathematica, Closer to natural language Easier to read, write, debug & modify Employ powerful data and control primitives, which allow relatively concise specification of complex computation patterns Requires no knowledge of computer hardware
Portability!
Introduction to Algorithms
Do algorithms relate to algebra? Both are derived from mathematician Mohammed ibn-Musa al-Khwarizmi Both deal with abstraction and manipulation Recall your basic algebra Variables a symbol that represents a number Expression a mathematical statement that may use numbers, variables, or both Equation statement that two expressions are equal Typical Application: Story Problems
Introduction to Algorithms
Algebra uses proven equations to transform one set of true
State collection of variables with a value The value of a variable can change over time!
x := 3 x := x + 1
Introduction to Algorithms
Algebra has many truth-preserving manipulations Algorithms have only a handful of state-mutating
manipulations
Core Manipulations
Assignment to variables Sequence Selection Iteration
Assignment to Variables
Always need a variable on the left-hand side Three variants for right-hand side: A constant value
Another variable
Sequence
Most primitive form of controlling action one after the other Example: Baking a Take-Home Pizza
Preheat conventional oven to 475 degrees. Remove the plastic wrap and cardboard circle Save the cardboard circle to cut and serve your pizza on. Place the pizza on a pizza pan and place on the center rack in your oven. Bake for 20 30 minutes. Remove pizza from oven. Place pizza onto saved cardboard circle Cut into desired slices Serve and enjoy
Selection
Select between options based on some condition Example: Baking a Take-Home Pizza (frozen or thawed)
Preheat conventional oven to 475 degrees. Remove the plastic wrap and cardboard circle Save the cardboard circle to cut and serve your pizza on. Place the pizza on a pizza pan and place on the center rack in your oven. if the pizza is frozen then Bake for 20 30 minutes else bake for 15 20 minutes Remove pizza from oven. Place pizza onto saved cardboard circle Cut into desired slices Serve and enjoy
Iteration
Repeat steps based on some condition Example: Baking multiple Take-Home Pizzas (frozen or thawed)
Preheat conventional oven to 475 degrees. while there are more pizzas to bake do Select pizza to bake Remove the plastic wrap and cardboard circle Save the cardboard circle to cut and serve your pizza on. Place the pizza on a pizza pan Place pan on the center rack in your oven. If the pizza is frozen then bake for 20 30 minutes else bake for 15 25 minutes Remove pizza from oven. Place pizza onto saved cardboard circle Cut into desired number of slices Serve and enjoy
HOMEWORK!
Homework 6 Maple Tutorial 1 Complete the worksheets questions and turn it in Due 10/25/2010