Login

What is a Computer Algorithm? - Design, Examples & Optimization

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: Debugging and Compiling Code

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:05 What Is an Algorithm?
  • 1:27 How Do Algorithms Work?
  • 3:43 Alternative Approaches…
  • 7:11 Lesson Summary
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: Paul Zandbergen

Paul has a PhD from the University of British Columbia and has taught Geographic Information Systems, statistics and computer programming for 15 years.

Modern computers can carry out very complex tasks. Each task consists of well-defined procedures known as algorithms. Learn how computers use algorithms to perform the tasks we expect them to do.

What Is an Algorithm?

Consider how you use a computer in a typical day. For example, you start working on a report, and once you have completed a paragraph, you perform a spell check. You open up a spreadsheet application to do some financial projections to see if you can afford a new car loan. You use a web browser to search online for a kind of car you want to buy.

You may not think about this very consciously, but all of these operations performed by your computer consist of algorithms. An algorithm is a well-defined procedure that allows a computer to solve a problem. Another way to describe an algorithm is a sequence of unambiguous instructions. The use of the term 'unambiguous' indicates that there is no room for subjective interpretation. Every time you ask your computer to carry out the same algorithm, it will do it in exactly the same manner with the exact same result.

Consider the earlier examples again. Spell checking uses algorithms. Financial calculations use algorithms. A search engine uses algorithms. In fact, it is difficult to think of a task performed by your computer that does not use algorithms.

How Do Algorithms Work?

Let's take a closer look at an example.

A very simple example of an algorithm would be to find the largest number in an unsorted list of numbers. If you were given a list of five different numbers, you would have this figured out in no time, no computer needed. Now, how about five million different numbers? Clearly, you are going to need a computer to do this, and a computer needs an algorithm.

Below is what the algorithm could look like. Let's say the input consists of a list of numbers, and this list is called L. The number L1 would be the first number in the list, L2 the second number, etc. And we know the list is not sorted - otherwise, the answer would be really easy. So, the input to the algorithm is a list of numbers, and the output should be the largest number in the list.

The algorithm would look something like this:

Step 1: Let Largest = L1

This means you start by assuming that the first number is the largest number.

Step 2: For each item in the list:

This means you will go through the list of numbers one by one.

Step 3: If the itemLargest:

If you find a new largest number, move to step four. If not, go back to step two, which means you move on to the next number in the list.

Step 4: Then Largest = the item

This replaces the old largest number with the new largest number you just found. Once this is completed, return to step two until there are no more numbers left in the list.

Step 5: Return Largest

This produces the desired result.

Notice that the algorithm is described as a series of logical steps in a language that is easily understood. For a computer to actually use these instructions, they need to be written in a language that a computer can understand, known as a programming language.

Alternative Approaches and Optimization

There are many different types of algorithms. Search algorithms are used to find an item with specific properties among a collection of items. For example, you may want to know if a particular word occurs in a list of words or not. Searching is closely related to the concept of dictionaries since it is like looking up a word in a dictionary. There are different approaches to searching, each representing a slightly different technical approach to the same problem.

In a sequential or linear search, you start by examining the first item in the list to see if it matches the properties you are looking for. If not, you continue examining each sequential item until a match is found.

This approach will produce the correct result, but it is not very efficient. For a relatively small list that only needs to be searched once, it may not matter much if the search takes a little longer. However, many computer tasks require not just one, but hundreds, of algorithms to be run. The datasets can also be very large and may need to be processed repetitively. As a result, processing speed matters.

Alternative algorithms may require less time to find the correct answer. This is known as optimization: the process of finding the most computationally efficient algorithms to solve a particular problem.

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 79 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