There is little doubt that one of the most daunting tasks in all of computer programming is that of developing your own algorithms. Indeed, it is here where the term Computer Science comes to the fore as it is virtually a step-by-step process, so intricate and precise it truly is a science to master.
So what exactly are algorithms? Simply put, these are step-by-step methods which a programmer tells a computer to follow. They often branch out under certain conditions, in the same way that as humans with brains we follow trillions of algorithms in our daily lives although you don't necessarily think about them. For example, you are following an algorithm in order to add two numbers, to walk down a flight of stairs and even just to move our heads.
Let’s take walking down a flight of stairs as a good example to examine more closely. You begin by placing one foot in front of you and then following with the other. Then you notice that there is another step in front of you, so we do the same again. You keep repeating this process until you finally see there are no steps left, and then note that you have reached the bottom of the stairway. This is the most basic form of an algorithmic process, but the next step you must take is to understand variables. All programming languages involve the use of variables, keywords which are used to represent numbers, letters, and symbols in the computer's random access memory (RAM.)
Variables are quite similar to their algebraic counterparts, and are recognized by both their identifier and name. The identifier of a variable states what type of data it holds be that a number, word, letter and so on. The name of the variable can be virtually anything, although there are some restrictions based on the particular programming language that is used. However, variables are always used in algorithms to store values which vary each time the program is run. For example, within a program where the number 5 was multiplied by two there would be no need for variable, but if that program asked the user for a number N, and then multiplied that number N by two things would be different. A variable would be needed because N is different each time the program is executed.
Now suppose you wanted to write a program which, given a number, would print out double the value of that number if it is less than ten, and triple the value of that number if it is more than ten. Assume that the variable N is used to represent the original number, and the variable X is used to represent the new number which you eventually want to print out. You would begin by using a branch to decide if N is greater than or less than ten, this is known as a deciding statement. When your program is executed, the computer compares ten to number N and decides which way to go. Meanwhile, you have predetermined in your code that if N is less than ten, to make variable X equal to twice N, or else make variable X equal to three times N.
The truth is that it takes a lot of practice to easily be able to rationalize your own algorithms because the process includes thinking ahead as to what your users might do. Think about if the program described above actually existed, where a user was to enter a number into a text field which would become variable N and then a new variable X created and printed to the screen. What would happen if a user entered "dog" in the textbox instead of a number? The computer would be confused while trying to compare "dog" to ten. For this reason, there is the necessity to build error-checks into your programming code. You would have the computer check to see if variable N is indeed a number before comparing it to ten.
Remember that developing algorithms is crucial to a computer programmer because it is always the first step taken before actual code can be written. So before beginning any programming endeavors make sure that you have a good idea in your head of exactly how you are going to accomplish the selected tasks, from start to finish, step-by-step.