Login

What is an Algorithm in Programming? - Definition, Examples & Analysis

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: What is an HTML Document? - Structure, Types & Examples

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
 Replay
Your next lesson will play in 10 seconds
  • 0:02 What is a Programming…
  • 1:45 Programming Algorithm Example
  • 3:59 Lesson Summary
Add to Add to Add to

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Login or Sign up

Timeline
Autoplay
Autoplay
Create an account to start this course today
Try it free for 5 days!
Create An Account

Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Lonny Meinecke

Lonny is a PhD student, a part-time teaching assistant/Sennseis for positive psychology, and has a bachelor's degree in IT and a master's degree in psychology.

In this lesson, we look at what a programming algorithm is - and what it isn't. We also look at an example of a common algorithm shown as both a numbered list and a flowchart, after which we briefly analyze what it does.

What Is a Programming Algorithm?

So, what is a programming algorithm? You can think of a programming algorithm as a recipe that describes the exact steps needed for the computer to solve a problem or reach a goal. We've all seen food recipes - they list the ingredients needed and a set of steps for how to make the described meal. Well, an algorithm is just like that. In computer lingo, the word for a recipe is a procedure, and the ingredients are called inputs. Your computer looks at your procedure, follows it to the letter, and you get to see the results, which are called outputs. A programming algorithm describes how to do something, and your computer will do it exactly that way every time. Well, it will once you convert your algorithm into a language it understands!.

However, it's important to note that a programming algorithm is not computer code. It's written in simple English (or whatever the programmer speaks). It doesn't beat around the bush--it has a start, a middle, and an end. In fact, you will probably label the first step 'start' and the last step 'end.' It includes only what you need to carry out the task. It does not include anything unclear, often called ambiguous in computer lingo, that someone reading it might wonder about.

It always leads to a solution and tries to be the most efficient solution we can think up. It's often a good idea to number the steps, but you don't have to. Instead of numbered steps, some folks use indentation and write in pseudocode, which is a semi-programming language used to describe the steps in an algorithm. But, we won't use that here since simplicity is the main thing. Other folks just use a diagram called a flowchart, which we will discuss soon.

Programming Algorithm Example

Okay, you probably wish you could see an example, right? So, what exactly does an algorithm in programming look like? Well, asking a user for an email address is probably one of the most common tasks a web-based program might need to do, so that is what we will use here for an example. An algorithm can be written as a list of steps using text or as a picture with shapes and arrows called a flowchart. We will make one of each which you will see here:


Wasn't that easy? Notice how the top of our example is just a numbered list of steps using plain English, stating exactly what we want the procedure to do (no more, no less). The bottom is the very same algorithm, but this time we used shapes and arrows in a flowchart (like a map of the route), so that a reader can visualize the journey. That's a nice thing here, because in one of our steps (step 7) a decision must be made, and depending on the result of that decision, our steps may not go in order from start to end.

Okay! Let's take a quick run through our little recipe:

1. Step 1 is really just a reminder that this is a procedure with a beginning and an end.

2. In step 2, we make a place in the computer to store what the user types in, also called a variable

3. In step 3, we clear this variable, because we might need to use it again and don't want the old contents mixed in with the new.

4. In step 4, we prompt the user for an email address

5. In step 5 we stick it in our nifty variable.

6. In step 6, we tell our computer to take a close look at this email address-- is it really an email address?

7. In step 7, we make a decision; if we got a valid email address, proceed to step 8 (the End), and if not, well, we'd better go back and get one that is!

8. Step 8 - End

To unlock this lesson you must be a Study.com Member.
Create your account

Register for a free trial

Are you a student or a teacher?
I am a teacher
What is your educational goal?
 Back

Unlock Your Education

See for yourself why 10 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back

Earning College Credit

Did you know… We have over 95 college courses that prepare you to earn credit by exam that is accepted by over 2,000 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it free for 5 days!
Create An Account
Support