How to Implement an Algorithm to Your Computer

How to Implement an Algorithm to Your Computer thumbnail
Converting an instruction process into computer language requires precise programming.

Algorithms are very useful in carrying out complicated or repetitive steps to accomplish a task. A database may have millions of people's names, phone numbers and other data. A search algorithm takes a name entered by the userm the input, and reports back any matches in a database. Algorithms that are too complicated to program and analyze in one step need especially close attention, as logical links and loops compound the possibility of human error.

Things You'll Need

  • C++ compiler
Show More

Instructions

    • 1

      Identify inputs and outputs. Inputs can be numbers, words, sensor data and anything that "initiates" a program. Outputs are the desired results: what the programmer intends the algorithm to do. A finite series of steps relate inputs and outputs. These steps can be simple or complicated, depending on the algorithm's purpose.

    • 2

      Draft the core pseudo-code. Pseudo-code is semi-formal notation "halfway" between formal programming language and "natural" language. Pseudo-code contains the essential inputs, steps, and output. In this case, pseudo-code would contain a prompt for a number, the multiplying operation that gives the number's cube, and an "output command" that displays the resulting cube. Example of pseudocode for the algorithm might be:

      Define variable "number";

      Input(number);

      NewNumber = number^3 ;

      //number^3 = number*number*number//

      Output(NewNumber);

    • 3

      Make notes of unclear or specialized terms and steps. In this example, the "//number^3 = number*number*number//" is for a programmer's benefit. It has no effect on the code, but is simply a reminder to the current, or any future programmers, what "number^3" means. These notes are very helpful in communicating complex information to people who may be new or inexperienced with the algorithm.

    • 4

      Convert the pseudo-code into code in a formal language within a computer. This requires a compiler in a programming language. Most programming languages such as C++ differ in notation and formatting details, but are otherwise similar. With quality pseudo-code, the translation to formal language should not be difficult. Common programs such as Microsoft Excel, Matlab or Mathematica can be platforms for formal-language algorithm writing. In C++, the computer algorithm would be similar to:

      #include<stdio.h>

      int main()

      {

      float Number;

      Number = -3.815;

      float NewNumber;

      printf("Input number: %f\n", Number);

      NewNumber = Number*Number*Number; //Number^3 = Number*Number*Number

      printf("\nThe number cubed is:\n");

      printf("%f", NewNumber);

      }

    • 5

      Test the programmed algorithm. Verify calculations and results by hand. In this example, this is easy. A calculator shows that (-3.815)^3 = -55.524.

    • 6

      Build in checks and fail-safes to make the algorithm robust. The given example sets up a number, -3.815, and cubes it. In a realistic algorithm, there would be safeguards against nonsensical inputs. Failure to do so could crash a program or give nonsensical answers. Algorithms that ignore the "what ifs" of human error and programming intricacies are prone to errors, and typically require revision.

Related Searches:

References

  • Photo Credit computer image by Orlando Florin Rosu from Fotolia.com

Comments

You May Also Like

  • How to Decode a Barcode Algorithm

    Virtually every product you buy in a retail establishment has a barcode or UPC symbol as of 2011. Barcodes are black and...

  • Introduction to Pseudocode

    Pseudocode is a tool used to prototype and document computer algorithms. Rather than designing by writing programming statements in a specific language,...

  • Quality Metrics Tools

    Quality Metrics Tools. Quality is defined as meeting customer expectations at a price that they are willing to pay. Quality metrics measure...

  • The Properties of an ERP Modeling Language

    The Properties of an ERP Modeling Language. Enterprise Resource Modeling (ERP) is a software package that supports various functions of a business,...

  • The Types of Search Algorithms

    Search algorithms are an important part of many programs. Some searches involve looking for something in a database --- like looking up...

  • How to Understand Numerical Analysis

    Stability refers to accurate solution approximations. Stability can be an issue if a denominator with a variable occurs. If an algorithm gives...

  • How to Calculate Rate of Return

    In order to calculate rate of return, a person needs their current value, how much their investments are worth and how much...

  • How to Understand Computer Algorithms

    Computer algorithms are pieces of instructions that tell the machine to do a task. While they are written in many different programming...

  • How to Convert a String to an INT C

    Many C++ programs need to present data in a human-readable format. The easiest way to do this is to convert numeric data...

  • How to Understand Algorithms

    In simplest terms, learning how to understand algorithms requires little more than the ability to visualize lists of fixed directives that offer...

Related Ads

Featured