16
May

Algorithms are an important fundamental in understanding Computer Science as a subject. The purpose of this article is to thoroughly define what an algorithm is and how it relates to computer. An algorithm is a mathematical term that means a plan for solving a problem. Algorithms consist of a sequence of steps. Computers use algorithms. An algorithm is a set of instructions that is used to get something done. EXAMPLE: An algorithm for selecting the right kind of shirt might have the following steps: 1. Pick a shirt from your closet. 2. Put the shirt on. 3. Look at yourself in the mirror. 4. Decide whether you like the way you look in that shirt. If you like how you look, leave the shirt on and go to step 6. If you do not like how you look, take the shirt off and put it back in the closet where you got it from. 5. Repeat steps 1.-5. 6. End this procedure. Computers perform functions by processing algorithms. You can create algorithms for computers to follow, that other people can then use in the future without having to repeat the creation process you did. For example: When your computer prints something, there are many massive algorithms it uses to figure out which type of printer you have, how to communicate the document to the printer in such a way it understands, etc., all done behind the scenes for you so all you need to do is click “print”. These algorithms were written by others to get the computer and printer to comply with your wishes. An example of an algorithm could be a simple recipe, such as: 1. Crack three eggs and pour their contents into a small bowl – attempt to avoid getting eggshell in the bowl. 2. In the case of eggshells, remove any eggshell from the bowl. 3. Beat the 3 eggs for 30 seconds in the small bowl until they are well mixed. 4. Put a small frying pan on the stove and turn the burner on to medium temperature. 5. Pour the eggs in a small frying pan and cook until very little to no wetness remains. 6. Serve the eggs While there are similarities, computers and people do not use algorithms in the same way. There are similar features in real life algorithms and computer algorithms but they are not identical. Computers can’t think – they are completely literal – so when writing an algorithm for computers there are certain characteristics that must be present for a computer to use the algorithm. People can deduce things and extrapolate data; people have imagination. Computers can only do what they’ve been told to do. COMPUTER ALGORITHMS To fully understand what an algorithm is for computers, some terms and concepts must be cleared up first. Algorithms are composed of five separate characteristics: 1) Result: The outcome of something. In computers, a response could be considered the result. You type in: “Tell me the date”, the computer replies: “Jan 3, 2017”. “Jan 3, 2017” would be the result. Answers to problems are also considered a result. Algorithms always have a result. If there is no result, it cannot be considered a valid algorithm. EXAMPLE: Print the number “2”, Result: 2. 2) Finite amount of time: This is an exact amount of time for something. Algorithms should have an exact amount of operations included in them and should execute these operations in a set period of time. Algorithms should never be open-ended or infinite. An incorrect algorithm would be: 1. Start at an amount of 1 2. Add 1 to that amount 3. Go to step 2 The computer would then count 0, 1, 2, 3, 4, etc. forever. EXAMPLE: “Count from 1 to 10 and then print a message that says, ‘I counted from 1-10’,” would be a correct algorithm because it contains a finite amount of time. 3) Well-ordered: If something is well-ordered, it means it is listed out in the correct sequence and in an organized fashion. Computers can only execute an algorithm if it is well-ordered. If it is put out of sequence or no sequence is specified, etc., the computer cannot process the algorithm. EXAMPLE: This is an incorrect algorithm because it is not well-ordered: 1. Close the program 2. Print “I am here” inside the program. 3. Save the program 4. Open the program You would get an error message because this is the incorrect sequence. 4) Effectively computable operations: This means a command that can be processed successfully by a computer. The phrase literally means an operation that can be computed in an effective way. In algorithms, all of the parts of the algorithm must be possible to execute. EXAMPLE: A non-effectively computable operation could be: Multiply green by red – the computer can’t process this because it isn’t computable. Operations contained in algorithms must be effectively computable operations. Such as, “2 + 2 =”. 5) Unambiguous: Ambiguous means unclear, confusing, not specified. Un = not. Something that is unambiguous means that it is clear and defined. In computers, your algorithms must be unambiguous. You have to be extremely specific about each step/part of an algorithm or the algorithms cannot be processed by the computer. EXAMPLE: If you have an algorithm that is processing a list of ten numbers and then a step of your algorithm is “delete the number”, the computer cannot process this because you did not clearly specify which number you wanted deleted. ALGORITHMS Now that you know the above terms and concepts, we have the full definition of “algorithm” as defined in the book “Invitation to Computer Science” by Schneider and Gersting: Algorithm: A well-ordered collection of unambiguous and effectively computable operations that when executed produces a result and halts in a finite amount of time. Sorting means to put something in an exact sequence or order. Computers sort things often. On your computer, you can sort files by things like when they were created, their name, etc. Algorithms can be used by computers to organize data. For example: You can sort files on your computer by name or date. This is done by a sorting algorithm within the computer. There are several different ways algorithms can be written to sort data. In learning how to program, you will be writing algorithms to perform various functions. Computers have many algorithms programmed into them already that cause them to do a lot of the things you use computers for. E.g. Your computer performs many complicated steps save a document on your computer and these steps are taken care of because programmers entered in algorithms to handle it for you.

## Comments