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

Want to watch this again later?

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

Log in or Sign up

Speed Speed Audio mode

Recommended Lessons and Courses for You

Lesson Transcript
Paul Zandbergen

Paul is a GIS professor at Vancouver Island U, has a PhD from U of British Columbia, and has taught stats and programming for 15 years.

Expert Contributor
Elaine Chan

Dr. Chan has a Ph.D. from the U. of California, Berkeley. She has done research and teaching in mathematics and physical sciences.

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 item > Largest:

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.

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

Additional Activities

Root Finding Algorithm

A number x, such that f(x) = 0, is a root or a zero of the function. Solving an equation, f(x) = g(x), is the same as finding the roots of the function h(x) = f(x) - g(x).

The algorithm for the approximate zero of f(x) is xn+1 = xn - f(xn ) / f'( xn ) .

Starting with n = 1, you can get x2. Use x2 to get x3, and so on, recursively. The iteration stops when a fixed point (up to the desired precision) is reached, that is when the newly computed value is sufficiently close to the preceding ones. In the limit, as n goes to infinity, an infinite number of iterations, xn, approaches the zero of the function. This is a recursive formula that needs to be started with a reasonable initial guess. The function also needs to have a non-zero derivative. This method is called Newton's method or the Newton - Raphson method of root finding. Replacing the derivative in Newton's method with a finite difference, we get the secant method. This method does not require the computation (nor the existence) of a derivative, but the price is slower convergence.


Find the root of the equation cos(x) = x . Suggested initial guess of x = 1.


Solve for the zero of f(x) = cos(x) - x

The recursive algorithm for the approximate zero of f(x) is xn+1 = xn - f(xn ) / f'( xn ) .

The derivative is f'(x) = - sin(x) - 1

The initial guess is x = 1

Plug into the formula to find x2 = 0.75036387

Plug that into the formula to find x3 = 0.73911289

Plug that into the formula to find x4 = 0.73908513

Plug that into the formula to find x5 = 0.75908513

Since the last two approximants agree to six decimal places, we conclude that the root of the equation (correct to six decimal places) is 0.75908513

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 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? 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 risk-free for 30 days!
Create an account