Algorithms What Is An Algorithm?

Source: Wikipedia

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 Source: http://en.wikipedia.org/wiki/Algorithm terminating at a final ending state. (Phew)!

Algorithms: Example 1 Food Recipe A food recipe is a step-by-step procedure â&#x20AC;&#x201C; 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

Algorithms: Example 2 “Get To School” 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 For more examples visit : problem and completing a task. http://computer.howstuffworks.com/question717.htm A computer program can be viewed as an elaborate algorithm. 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

Algorithms: Flowcharts …making your thinking ‘visible’ Lamp does not work

Lamp plugged in?

No

Plug in lamp

Yes Bulb ‘blown’? No

Repair lamp

Yes

Replace bulb

What other steps could be included in this example?

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).

Algorithms: Flowcharts A Guide to understanding flow charts

Source: xkcd.com/518/ http://www.cs.nyu.edu/~acase/classes/spring11/introprog/handouts

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.

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!

Algorithms On The Internet (1) PageRank

Cartoon representation of PageRank. Source Wikipedia: http://en.wikipedia.org/wiki/PageRank

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.

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.

Algorithms In The News (1) ‘Right Place Right Time’ Image: Cutegeek.com

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.

Algorithms In The News (2) Image source: http://pulse2.com