IS5000xx Foundations of Problem Solving Dr Lahen Ouarbya Content of the course – At the end of the problem solving part of the course, the student will be able to: – Understand basic problem solving algorithms and corresponding data structures – Devise algorithms and build programs that solve concrete problems – Perform test on algorithms and programs and correct faults – Discuss and criticise basic programming principles – Read and understand simple programs and present them to others in a workshop setting – Different algorithm will be examined during this course 3 Delivery of the course The course will be taught via lectures only – One 2-hour lecture per week 4 Assessment Two courses and one exam – Coursework 1 (first term) is worth 20% – Coursework 2 (second term) is worth 20% – Exam (end of the year (May)) is worth 60% 5 Resources – We will start by working through the textbook How to think like a programmer by Paul Vickers. – The course web page on learn.gold will contain: – Lecture slides – Assignments and model solutions – Any important news about the course – Discussion forum 6 About the title of this course – What is the relationship between programming and problem solving? 7 About the title of this course – A computer program is a solution to a problem. – It is not the computer that solves a problem: it is you, the programmer who solves it by: – Identifying the problem – Understanding the problem – Identifying what factors are known and unknown – Figuring out a systematic procedure for finding the unknown values, given the known ones – Telling the computer what to do. 8 From problem solutions to programs (I) Programming involves distinct skills such as – Ability to code in one or more programming languages; understanding concepts such as variables, loops, conditionals; knowing where to put brackets, arrows, semi-colons, quote marks etc; knowing how to run programs on different computers – Ability to analyse problems and formulate solutions which are explicit, unambiguous and systematic, so that they can be coded in a programming language – This strand of lectures focusses on the second skillset. 9 From problem solutions to programs (II) – Human beings are very good at solving problems, we do it all the time: – Getting from your home to this room – Cooking dinner for 6 people – Making sure you can pay your bills every month – What we are sometimes less good at is explaining and reasoning about problem solutions. 10 From problem solutions to programs (III) – We will start by taking a closer look at “everyday” problems that we usually solve with very little thought, and see what is involved in analysing them as computational problems – This may involve trying out different ways of formulating or visualising problems – We will gradually introduce computational concepts such as variables, loops, conditionals etc – We will cover different ways of representing solutions such as flowcharts and pseudocode. 11 Class exercise – Suppose your cousin from the country is staying at your house. He has never been to London before or travelled on an underground train. You have decided to meet in Trafalgar Square after the class. – Get together in groups of 3 or 4 and compose a list of instructions for your cousin, which will ensure that he reaches Trafalgar Square by the agreed time without getting lost, run over or arrested. 12 Class exercise: discussion Some discussion points: – Does the problem naturally break down into subproblems? – What kind of terminology have you used? Can you be sure your cousin will have understood it? – Are any of your instructions vague or ambiguous? For instance, could your cousin have taken the wrong exit from a tube station? – What assumptions have you made? 13 Class exercise: discussion (cont) – Are there multiple solutions? If so, how do you evaluate them and choose the best one? – For example, solutions could include: – Walking all the way – Taking a taxi – Getting a lift all or part of the way – Hiring a chauffeur-driven Rolls-Royce – Cycling – Using public transport – Flying to Paris and taking the train through the Channel Tunnel – What constraints might influence your choice of solution? 14 Complicating the problem – – – – 15 Your cousin doesn’t speak English However, you can speak and write his language Will your previous solution still work? If not, what will have to change? The How to think like a programmer (HTTLAP) approach 1. 2. 3. 4. 5. 6. Understand the problem Devise a plan to solve the problem Carry out the plan Assess the result Describe what you have learned Document your solution An extended version can be downloaded from http://www.cengage.co.uk/vickers/students/Vickers_CH02_019-036.pdf 16 1. Understanding the problem A poor understanding of a problem can prevent you finding an optimal solution, or any solution at all. Two examples: 1. An ant is at the corner of the ceiling and wants to get to a bowl of sugar, which is on the floor at the far corner of the room. How would you calculate the shortest path it can follow? 2. Two trains are 100 miles apart on a single track, and heading towards each other at 60mph and 40mph respectively. A bird is flying back and forth between them at 70mph. How far will the bird have travelled before they collide? Please do NOT shout out the answers; give everyone a chance to think it through. 17 Summary of today’s lecture – Practicalities of the course – Relation between programming and problem solving – Starting to look at everyday problems in a computational way – A first look at the HTTLAP strategy (more next time) 18 Activity for week 1 – Download and read through the HTTLAP strategy. – Think about how you could apply it to the following problem: – You have a friend who comes from a very wealthy family. He is reasonably intelligent and well-educated, but has never had to do anything for himself around the house or seen the inside of a kitchen. Write out precise and explicit instructions he can follow to make a pot of coffee and pour a cup, using an electric filter machine. – Make a list of discussion points for next week’s lecture 19