Algorithms What Is An Algorithm? Source: Wikipedia Source: http://en.wikipedia.org/wiki/ Algorithm Information Technology Simply put, an algorithm is a series of instructions (a procedure) that solves a problem by using a finite number of steps. A Computer Scientist would more accurately describe an algorithm as an effective method expressed as a finite list of well-defined instructions for calculating a function. Starting from an initial state and initial input the instructions describe a computation that, when executed, will proceed through a finite number of well-defined successive states, eventually producing output and terminating at a final ending state. (Phew)! ITaCS and Computer Science Algorithms: Example 1 Food Recipe A food recipe is a step-by-step procedure – like a list of instructions - to complete a task. A food recipe therefore is like an algorithm. In this analogy it can be compared to the software in a system. The hardware is the oven and the other cooking utensils. The input is the ingredients and the output is the cake. Source: Wikipedia Information Technology ITaCS and Computer Science Algorithms: Example 2 “Get To School” 1. Walk to bus stop 2. Wait for bus No.123 3. Get on bus 4. Ride bus to school 5. Get off bus at school bus stop 6. Walk to class 1. Get in car 2. Be driven along City Road 3. Turn left into Town Lane 4. Car stops in drop off zone 5. Get out of car 6. Walk to class For more examples visit : http://computer.howstuffworks.com/ques tion717.htm Information Technology Designing algorithms is about designing solutions to solve problems. If you were to design an algorithm to solve the problem of ‘getting to school’ you would be able to solve this problem in several different ways (see left). Different algorithms can solve the same problem – but in different ways. Algorithms that solve the same problem may differ in length, efficiency and cost. In computer programming there are many different ways - algorithms - of solving a problem and completing a task. A computer program can be viewed as an elaborate algorithm. ITaCS and Computer Science Algorithms: Flowcharts …making your thinking ‘visible’ Lamp does not work Lamp plugged in? No Plug in lamp Yes Bulb ‘blown’? Yes Replace bulb No Repair lamp What other steps could be included in this example? Information Technology Developing a flowchart helps to formalise the algorithm – and allows more choices, complexity and variables - crucial as you move past the simplest of algorithms. Simple problems can often be shown best as a flowchart. Flowcharts can help you to think logically about problems by working through each step. Flowcharts can help you explain your work to others – and they can follow your thinking (very useful when trying to ‘fault find’ errors /mistakes’ in your algorithms). ITaCS and Computer Science Algorithms: Flowcharts A Guide to understanding flow charts Source: xkcd.com/518/ http://www.cs.nyu.edu/~acase/classes/spring11/intropr og/handouts/notes/class5.pdf stion717.htm Information Technology ITaCS and Computer Science Algorithms: Pseudocode ….like ‘real’ code 1.. If student's grade is greater than or equal to 60 Print "passed" else Print "failed" 2. Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total Set the class average to the total divided by ten Print the class average. Information Technology Computer languages need the correct syntax or they do not work properly. Pseudocode has no real syntax rules because it is not real computer code – it is a natural language that is close to ‘computer ‘language. The benefit of pseudocode is that it enables the programmer to concentrate on the algorithms without worrying about all the syntax which is specific to a particular programming language. You can even write pseudocode without knowing what programming language you will use for the solution – and others could take your code but use it with a different language! ITaCS and Computer Science Algorithms On The Internet (1) PageRank Cartoon representation of PageRank. Source Wikipedia: http://en.wikipedia.org/wiki/PageRank Information Technology PageRank is a famous algorithm used by the Google Internet search engine, that assigns a numeric value that represents how important a page is on the web. When one page links to another page, it is effectively casting a vote for the other page. The more votes that are cast for a page, the more important (in theory) the page must be. PageRank is Google's way of deciding a page's importance. It matters because it is one of the factors that determines a page's ranking in the search results. It isn't the only factor that Google uses to rank pages, but it is an important one. ITaCS and Computer Science Algorithms On The Internet (2) EdgeRank / Amazon / Facebook EdgeRank is an algorithm developed by Facebook to govern what is displayed— and how high—on each users News Feed. Amazon uses a number of algorithms. The popularity list algorithm is the accumulated sales of a book’s last 30 days compared to those in its category–but free books given away only count for roughly 10% of a paid sale, and price is factored in as well, in that the higher your price, the more each sale counts for on the list. Formula: (sales + (0.1 x free downloads)) x (unknown sales factor) / last 30 days. Youtube uses a number of modified Amazon algorithms. Information Technology ITaCS and Computer Science Algorithms In The News (1) ‘Right Place Right Time’ Image: Cutegeek.com Research: Find out more about this type of algorithm: http://www.bbc.co.uk/news/business-19286426 Information Technology Picture yourself in an expensive designer clothes shop. Your smartphone knows where you are – (thanks to the GPS) - and it alerts your bank through an automated system that you've signed up to. Knowing you've got a history of buying from similar stores, your bank also knows that you're running a bit low on cash. Your phone beeps. A text message. Buy it in the next 20 minutes and you can borrow the money at a good rate. Also you'll get 20% off the clothes. You make the purchase – thanks in part to a ‘right place, right time’ algorithm. ITaCS and Computer Science Algorithms In The News (2) Image source: http://pulse2.com Google Algorithms Sued Debate: Can the Google algorithm be manipulated? What problems may a case like this cause for Google? Information Technology Bettina Wulff - the wife of a former German president has filed a lawsuit against Google to remove autocomplete suggestions that she is claiming as libel. Some of the suggestions that pop-up when searching for Bettina include the words “prostitute” and “red light”. Head of PR for Google Germany, Kay Oberbeck, said the site's search terms were "algorithmically generated" and "include the popularity of the entered search terms". "All terms that appear have been previously entered by Google users," he added in a statement. ITaCS and Computer Science