Introduction to Algorithms/What is an Algorithm
< Introduction to AlgorithmsThis is a lesson in in the course, Introduction to Algorithms, which is a part of The School of Computer Science
Objective![]() Our main objective is to learn what an algorithm is and its basic components/concepts. By the end of this you should be able to recall what an algorithm is and what it does. |
Definition of AlgorithmMerriam-Webster Online defines "Algorithm" as " a step-by-step procedure for solving a problem or accomplishing some end, especially by a computer" . The dictionary definition is missing the component that the procedure must be finite, that is, there has to be a condition for the termination of the algorithm. Examples: 1. One example would be knitting socks. The first step is to cast on stitches. Step-by-step the rows are knitted, the heel turned, and finally the last row cast off. The algorithm specifies how to do the sock, but each sock knitted is different, as it uses different wool, but all are similar in structure to each other. 2. Another important example would be sorting a hand of cards. There are multiple ways of doing this, but one method is to take the lowest card and move it to the leftmost (or rightmost) position. Next, find the second lowest card and move it to the second leftmost position. Repeat until the cards are sorted. Everyday example: Here is a perhaps slightly whimsical example of an algorithm. Algorithm for making buttered toast (1.0) step1: Get a loaf of bread. step2: Cut one slice from end of the loaf of bread. step3: Put slice of bread into toaster. step4: Turn toaster on. step5: Wait for toaster to finish. step6: Put toasted bread onto a plate. step7: Spread butter on toast. As can be seen, the algorithm is a set of steps that can be followed in order to achieve a result. Basic conceptsThis simple example already contains many components commonly found in most algorithms:
|
AssignmentsYour assignment is to create a simple algorithm. If you need help then you can go back and look at the example above of an algorithm. ![]() |
|