You are on page 1of 1

Algorithms

An algorithm is a set of instruction steps to solve a given problem. You are already familiar with breaking down a problem into its input, output and processing components. When you write an algorithm, you use those components in a logical sequence to solve a problem. Algorithms can be written as a narrative, or they can be written in pseudocode or by using flow chart. Writing in narrative means writing out the step-by-step solution to the problem in full sentenes. Pseudocode is language that mimics real programming language. Its commands and syntax are similar to the commands and syntax of a real program, but in more general terms. Writing an algorithm in pseudocode wll help you convert the problem into a programming language. Flowcharts are diagrams that arrange the components of a problem in a logical sequence, which helps to avoid logic errors.

Categories of data
To create an algorithm, you need to know that data can be constants or variables. Constants A constant is data that has a known value and keeps that value throughout a program. A constant does not change its value and does not depend on other factors. Here are some constants from mathematics and science. *the speed of light *the number of angles in a triangle *the value of pi () *the boiling temperature of water Constants can be any data that will not change its value throughout a process or calculation. A constant can also be a non-numerical value such as your name or address. To calculate the area of a circle you use the formula r2. You do not know what the radius is, but the value of is a constant, about 3.14. this value will not change and does not depend on the size of the circle. Variables Variables can change their value throughout a program, or do not have a known, fixed value. Examples are the temperature outdoors, the number of items bought by a shopper, and the price of an item. If you are solving a problem, variables are typically the data that is inputted by a user. Consider this problem: Add the prices of three items to get a total. We do not know the three prices that must be added. The solution will probably require a user to enter the three prices and they will depend on what the user has bought.

You might also like