From HelioHost Wiki
Jump to: navigation, search

This page is meant as a general-purpose primer into programming through the explanation of Algorithms.

When most people hear algorithms they usually think of complicated mathematical formulae that make no sense to anyone but a select few, however algorithms don't necessarily have to deal directly with numbers at all. An algorithm in the simplest terms is an organized list of steps that accomplishes a unique task. Let's think about that a second here: if an algorithm is just a list of steps, then something as commonplace as a cake recipe is an algorithm. Not only that but each individual recipe is an algorithm in it's on right.

Programmatically, an algorithm is represented by what are called methods, functions, or subroutines or subprocedures, or a series of these. For this article I'll use the name method, just know the proper name tends to change depending on what language you use. A method generally takes some input, performs actions on it, and outputs the result of those actions done on the input, now I say generally because sometimes a method doesn't need input or does need to output anything, it all depends on what your trying to do. To decide thee things programmers make IPO charts, which stands for input, procedure, output. An IPO chart helps a programmer gather their thoughts; first the programmer must look at the problem in front of them and decide what inputs and outputs are required, if any. Next the programmer looks at how they can change the input to get the output, and the order in which action must be taken; obviously if our cake algorithm had a mix ingredients step after a bake for 25 minutes step, we'd have issues.

A method in any non-trivial program usually calls on several other shorter methods to accomplish the required goal, for instance say you needed a multi-tier cake, you can't make 3 batters and stick them in the oven hoping to get 3 separate tiers of cake in 25 minutes. You'd have to make each tier separately and put them together at the end, this provides clarity for debugging and maintenance in programming, the smaller the individual pieces, the easier to find and understand where a program fails and why.

To create a cleaner, more creative and stable program we have to use control structures and loops; this includes concepts such as if-else, switch, while, until statements and error handling. Take our cake again and imagine redoing every tier until we made the "perfect" cake or until we reach 3 tries. In programs this is often the layout where code may cause program crashes through the inability to perform an action and is called exception or error handling. You can also think in terms of "while this condition isn't met or is true, do this series of actions" which is the layout of a while loop. Inversely you can tell a program "do this series of actions until these conditions are met" which is, you guessed it, a do..until loop. The while format is called a post-test loop and until a pre-test loop, meaning for a while loop the loop instructions don't come until after the test for a condition, thus if the conditions are or are not met (based on the programmer's choice) the loop may not run. On the other hand, maybe you want loop instructions run at least once, which is where a pre-test or do..until loop comes in. To give your program the ability to make decisions you can use a keimages yword i've used several times thus far, IF, all programming languages make use of it; simply put an if-else says if some condition is true run the code under if, otherwise run the else code. Some languages provide the elseif keyword but you can nest if-else to get the same effect. A switch statement functions like many elsifs nested together. One last loop is the For loop which takes a variable, a step range every so then and science.

That's all for today, use your mind to find creative solutions to any problem in any language.

Personal tools

Google AdSense