Algorithms 1 (Lecture 2 of CSE1301) Dr Damian Conway Room 132, Building 26 (Consult hours on the door)
Notice Thursday 9am-12pm prac in G13 has been moved to 10am-1pm in the same room. ALLOCATE+ will continue to show 9am, but it actually starts at 10am. If you need to be in the prac (e.g. Sci/Eng students), allocate yourself into the 9am G13 prac, but turn up at 10am.
Topics Solving problems Algorithms Values and variables
The Problem-solving Process How do we solve problems? We "just do". Guesswork-and-luck Trial-and-error Experience (possibly someone else's) "Scientifically"
The Problem-solving Process "Doctor, my head hurts" Analysis Patient has elevated pressure in anterior parietal lobe. Problem specification Design 1. Sterilize cranial saw 2. Anaesthetize patient 3. Remove top of skull 4. Get the big spoon... 5. etc., etc. Algorithm Implementation sterilize(saw, alcohol); raise_hammer(); lower hammer(fast); start(saw); /* etc. etc. */ Program Compilation 010011101011001010101010100101010101010011001010101010100101101001110101010101001001011101001111010101011111010101000110100001101... Executable (solution)
Algorithm A set of instructions specifying the steps required to accomplish some task
Algorithm Named after: Muhammad ibn Musa al-Khwarizmi circa 160-230 AH (780-850 CE) Wrote books on arithmetic (especially decimal numbers) and algebra
Algorithm Named after: Muhammad ibn Musa al-Khwarizmi
Algorithm Examples: A cooking recipe Assembly instructions for a model The rules of how to play a game VCR instructions Description of a martial arts technique Directions for driving from A to B A knitting pattern A car repair manual
Algorithm Examples: A cooking recipe Assembly instructions for a model The rules of how to play a game VCR instructions Description of a martial arts technique Directions for driving from A to B A knitting pattern A car repair manual
Algorithm Examples: Arroz con pollo Almond and honey slice
Components of an algorithm Variables and values Instructions Sequences Procedures Selections Repetitions
Values Represent quantities, amounts, or measurements May be numerical or alphabetic (or other more mysterious things) Often has a unit related to their purpose Examples: Recipe ingredients Hardware requirements
Variables Are containers for values Places to store values when we're not using them. May be restricted to containing a specific type of value (i.e. only stores integers) Examples: Little black book Cricket team
Reading Deitel & Deitel, C: How to program Chapter 1, Sections 1.1 to 1.10 Chapter 3, Sections 3.1 to 3.3