Lecture 3

staff.fisika.ui.ac.id

Lecture 3

Introduction to AlgorithmsAdhi Harmoko S,M.Komp


A “Universal” MachineProgrammabilityBinary Code (everything stored as “0” or “1”)Program and Data are represented in the same formElectronic Components


Early Computing History in a Nutshell200 BC - today Abacus -~1670 Leibniz’“Rechenmaschine”Fixed calculations+, -, *, /, sqrt~1750 Jacquard’s Loom Punch Tape1820 Babbage’s“Difference Engine”1838 Babbage’s“Analytical Engine”1841 Ada Byron,Lady LovelaceFixedTable CalculationProgram & DataseparateFirst program(Bernoulli-Numbers)


Leibniz’s Step ReckonerGottfried von Leibniz 1670Add, subtract, multiply, divide, square roots


Jacquard’s punch cardJoseph Marie Jacquard 1804punch cards used to operate loom


Babbage’s analytical engineCharles Babbage (1791-1871)Programmable, but mechanical.Data+Program separate


One of the first ProgrammersLady Ada Augusta Byron, Countess of Lovelace (1815-1952)(1791-1871)


Early Computing History in a Nutshell200 BC - today Abacus -~1670 Leibniz’“Rechenmaschine”Fixed calculations~1750 Jacquard’s Loom Punch Tape1820 Babbage’s“Difference Engine”1838 Babbage’s“Analytical Engine”1841 Ada Byron,Lady LovelaceFixedTable CalculationProgram & DataseparateFirst program(Bernoulli-Numbers)First universal programmable machine


The AncestorsBinary codeuniversal1886 Hollerith Punch Cards1936 Zuse Z1 Relais1941-1944 Zuse Z3/Z4 “Plankalkül”1944 Mark I Partly mechanicelectronic1943 Colossus Not universal1946 Eniac Programmablewith Re-wiringIntegration:•fully electronic•binary•Programmable•universal1949 ManchesterUniversalComputerCathode-RayTube Memory


Hollerith’s Tabulating MachineHerman Hollerith (1860-1929)Invented a punched card device to helpanalyse the 1890 US census dataFounded “Tabulating Machine Company”18961924 – Tabulating Machine Companymerges with others to form IBM


Konrad Zuse1936: Z1 first binary computer using Erector Set parts,keyboard and lights for output (relay memory)1938: Z2 – using punched tape and relaysZ3: fully binary, fully programmable, but partly mechanical


Colossus1943 British Colossus – (1,500 vacuum tubes)Decipher enigma coded messages at 5,000 chars/secAt peak, 10 machines ran 24 hours a day in BletchleyParkA German enigma coding machineFully electronic, but not universally programmable


Harvard Mark 11943-44 Aiken at Harvard/IBM “Mark 1” – first electromechanical digital computer (electromagnetic relays –magnets open and close metal switches)(recreation of Analytical Engine)8 ft tall, 50 ft long, 1 million parts323 decimal-digit additions per secstorage for 72 23-digit numbers.Universal, fully programmable But partly mechanical


ENIAC (1946)18,000 tubes, 1500 sq ftProgrammed by wire plugs into panels5,000 decimal-digit additions/sec20 10-decimal digit “accumulators”Von Neumann and ENIACFully electronic, programmable But extensive-wiring required


How do we solve problems?We "just do"Guesswork-and-luckTrial-and-errorExperience (possibly someone else's)"Scientifically"


The Problem-solving ProcessProblemAnalysisProblemspecificationDesignAlgorithmProgramImplementationExecutable(solution)Compilation


The Problem-solving ProcessProblem"Doctor, my head hurts"AnalysisProblemspecificationDesignAlgorithm010011101011001010101010100101010101010011001010101010100101101001110101010101001001011101001111010101011111010101000110100001101...ProgramPatient has elevated pressure inanterior parietal lobe.ImplementationExecutable(solution)Compilation1. Sterilize cranial saw2. Anaesthetize patient3. Remove top of skull4. Get the big spoon...5. etc., etc.sterilize(saw,alcohol);raise_hammer();lower hammer(fast);start(saw);/* etc. etc. */


Algorithm – Working DefinitionA sequence of instructions describing how to do a taskUnambiguousExecutableTerminatingIf you can't find an algorithm, the computer can't solve yourproblem


Algorithm -- ExamplesA cooking recipeAssembly instructions for a modelThe rules of how to play a gameVCR instructionsDescription of a martial arts techniqueDirections for driving from A to BA knitting patternA car repair manualRecipe for Almond and honey sliceRecipe for Arroz con pollo


Almond and Honey Slice1/2 quantity Shortcrust Pastry185 g unsalted butter100 g castor sugar5 tablespoons honey50 ml cream50 ml brandy or any otherliqueur or spirit300 g flaked almondsPreheat oven for 200° CLine a 30 cm × 20 cm bakingtray with baking paper, and thenwith pastryBake blind for 20 minutes, thenremove weights and foilTurn oven up to 220° C.Bring remaining ingredients to aboil, stirring.Spread evenly over pastry.Bake until topping is bubblingand has caramelised evenly,about 15 minutes.Cool before cutting into fingersor squares.


Almond and Honey Slice1/2 quantity Shortcrust Pastry185 g unsalted butter100 g castor sugar5 tablespoons honey50 ml cream50 ml brandy or any otherliqueur or spirit300 g flaked almondsInstructions are given in theorder in which they areperformed (“executed”)Preheat oven for 200° CLine a 30 cm × 20 cm bakingtray with baking paper, andthen with pastryBake blind for 20 minutes, thenremove weights and foilTurn oven up to 220° C.Bring remaining ingredients to aboil, stirring.Spread evenly over pastry.Bake until topping is bubblingand has caramelised evenly,about 15 minutes.Cool before cutting into fingersor squares.


From Algorithms to ProgramsProblemAlgorithm: A sequence ofinstructions describing howto do a task (or process)C++ Program


Components of an AlgorithmVariables and valuesInstructionsSequencesProceduresSelectionsRepetitionsAlso required: Documentation


Almond and Honey Slice1/2 quantity Shortcrust Pastry185 g unsalted butter100 g castor sugar5 tablespoons honey50 ml cream50 ml brandy or any otherliqueur or spirit300 g flaked almondsPreheat oven for 200° CLine a 30 cm × 20 cm bakingtray with baking paper, and thenwith pastryBake blind for 20 minutes, thenremove weights and foilTurn oven up to 220° C.Bring remaining ingredients to aboil, stirring.Spread evenly over pastry.Bake until topping is bubblingand has caramelised evenly,about 15 minutes.Cool before cutting into fingersor squares.


Almond and Honey Slice1/2 quantity Shortcrust Pastry185 g unsalted butter100 g castor sugar5 tablespoons honey50 ml cream50 ml brandy or any otherliqueur or spirit300 g flaked almondsPreheat oven for 200° CLine a 30 cm × 20 cm bakingtray with baking paper, and thenwith pastryBake blind for 20 minutes, thenremove weights and foilTurn oven up to 220° C.Bring remaining ingredients to aboil, stirring.Spread evenly over pastry.Bake until topping is bubblingand has caramelised evenly,about 15 minutes.Cool before cutting into fingersor squares.


VariablesAre containers for values –places to storevaluesExample:VariableValuesThis jarcan contain10 cookies50 grams of sugar3 slices of cakeetc.


Restrictions on VariablesVariables may be restricted to contain a specific type ofvalue


Components of an Algorithm Values and VariablesInstruction (a.k.a. primitive)Sequence (of instructions)Procedure (involving instructions)Selection (between instructions)Repetition (of instructions)Documentation (beside instructions)

More magazines by this user
Similar magazines