PDF download Download Article PDF download Download Article

An algorithm is a set of steps designed to solve a problem or accomplish a task. Algorithms are usually written in pseudocode, or a combination of your speaking language and one or more programming languages, in advance of writing a program. This wikiHow teaches you how to piece together an algorithm that gets you started on your application.

How to Write an Algorithm

  1. Know the outcome of your code.
  2. Find the starting and ending point.
  3. List the steps from start to finish.
  4. Find how you’ll accomplish each step.
  5. Look over your work and evaluate the process.
  1. What is the specific problem you want to solve or the task you want it to accomplish? Once you have a solid idea of what you're aiming to accomplish, you can determine the steps it will take to get there.
  2. Finding your starting and ending point are crucial to listing the steps of the process. To determine a starting point, determine the answers to these questions: [1]
    • What data/inputs are available?
    • Where is that data located?
    • What formulas are applicable to the issue at hand?
    • What are the rules to working with the available data?
    • How do the data values relate to each other?
    Advertisement
  3. As with the starting point, you can find the end point of your algorithm by focusing on these questions: [2]
    • What facts will we learn from the process?
    • What changes from the start to the end?
    • What will be added or no longer exist?
  4. Start with broad steps. [3] To use a real-world example, let's say your goal is to have lasagna for dinner. You've determined that the starting point is to find a recipe, and that the end result is that you'll have a lasagna fully cooked and ready to eat by 7 PM. Your steps may look something like this:
    • Search for a recipe online.
    • Look for the ingredients you already have in the kitchen.
    • Make a list of ingredients you'll need from the store.
    • Buy the missing ingredients.
    • Return home.
    • Prepare the lasagna.
    • Remove the lasagna from the oven.
  5. Now that you have a step-by-step outline, it's time to think about how you might code each step. Which language will you use? What resources are available? What's the most efficient way to accomplish each step in that language? Incorporate some of that code into your algorithm. Expand each step until you've detailed the entire process.
    • For example, the first step in our lasagna algorithm is Search for a recipe online. But what is involved in this search? Be specific. For example:
      • Turn on your computer.
        • Check to make sure you're connected to the internet. Connect to the internet if you aren't already.
      • Open a web browser.
      • Enter your search terms.
      • Click a recipe link.
      • Determine whether the recipe meets your needs.
        • Filter out recipes that aren't vegetarian.
        • Make sure the recipe makes at least 5 servings.
      • Repeat some of these steps until you find the right recipe.
    • Consider the resources at your disposal, such as the capabilities of the system you're developing a program for. In the case of lasagna, we assume the person making the lasagna knows how to search the internet, operate an oven, etc.
  6. Now that you've written your algorithm, it's time to evaluate the process. Your algorithm is designed to accomplish something specific, and you'll need it to start writing your program. Ask yourself the following questions, and address each as necessary: [4]
    • Does the algorithm solve the problem/accomplish the task?
    • Does it have clearly defined inputs and outputs?
    • Should the end goal be redefined to be more general? More specific?
    • Can any of the steps be simplified?
    • Is the algorithm guaranteed to end with the correct result?
  7. Advertisement


Expert Q&A

Search
Add New Question
  • Question
    How do I plan or map out an algorithm process?
    Tyrone Showers
    Technologist
    Tyrone Showers is a Technologist and the Co-owner of Taliferro Group, an IT consulting company based in Seattle, Washington. With over 35 years of professional experience, he specializes in API Design, e-Commerce, Operational Efficiency, and website development. He has a B.S. in Computer Science from DeVry Institute of Technology.
    Technologist
    Expert Answer
    Lay the groundwork first, learn some of the common algorithms, and understand what they do and what they're attempting to do. Bayes is one of my favorite algorithms. I build on this in my code to develop software agents that pick up new skills depending on previous behavior.
  • Question
    How do I write an algorithm that 7 is greater than 5?
    nicholasz2510 Gaming, Travel, and Music
    Community Answer
    The syntax can vary over different languages, but to write the conditional 7 is greater than 5 would most likely by simply be this: 7 > 5.
  • Question
    How do I make an algorithm of the sum of two numbers?
    Adam Blalock
    Community Answer
    To add two numbers in a programming language, you just use a "+" between them. In Python (a programming language), it would look like: x = 10, y = 13; print x + y.
See more answers
Ask a Question
      Advertisement

      Tips

      Show More Tips


      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!
      Advertisement

      Expert Interview

      Thanks for reading our article! If you’d like to learn more about writing algorithms, check out our in-depth interview with Tyrone Showers .

      About This Article

      Article Summary X

      1. Determine the problem or task to accomplish.
      2. Decide the starting point.
      3. Figure out the endpoint.
      4. List the steps that occur between the start and finish.
      5. Break down the steps as necessary.
      6. Review the algorithm and change where necessary.

      Did this summary help you?
      Thanks to all authors for creating a page that has been read 478,793 times.

      Is this article up to date?

      Advertisement