Safekipedia

Analysis of algorithms

Adapted from Wikipedia · Adventurer experience

In computer science, the analysis of algorithms is how we study the time, space, or other resources an algorithm needs to work. This helps us know how well an algorithm does, especially with big data. By seeing how the size of the input changes the steps an algorithm takes, we can tell if it is efficient or not.

The idea of analyzing algorithms started with Donald Knuth. This analysis is a big part of computational complexity theory, which studies the resources needed to solve different problems. It helps researchers make faster and better algorithms.

When studying algorithms, scientists use special ways to describe how they grow with bigger inputs. They use Big O notation, Big-omega notation, and Big-theta notation to give a general idea of an algorithm’s performance. For example, binary search works in logarithmic time, meaning it takes steps related to the logarithm of the number of items searched. These descriptions help compare different ways to solve the same problem, even though the exact speed can change based on how the algorithm is used.

Sometimes, we can find the exact efficiency of an algorithm, but this often depends on details about how it is made. This is studied using a model of computation, such as an abstract computer like a Turing machine, where some operations are thought to take a set amount of time. For example, with binary search, if each lookup in a list of n items takes one unit of time, we can know exactly how long the search will take.

Cost models

When we talk about how fast a computer program runs, we need to decide what counts as a single step. For this to match real-life timing, each step should take about the same amount of time.

There are two main ways to measure these steps:

  • the uniform cost model, which says every step takes the same time, no matter how big the numbers are
  • the logarithmic cost model, which says the time depends on how many digits are involved

The logarithmic model is trickier and is only used when needed, like in special math for cryptography.

Run-time analysis

Run-time analysis is a way to guess how much time a computer program will take when the size of its input gets bigger. It's very important in computer science because a program might take seconds, hours, or even years to finish depending on the method it uses. While actual testing can show how long a program takes, it can't predict times for every possible input size. That's why scientists use special theories to understand run-time analysis.

Different computers and software can change how fast a program runs, so scientists need better ways to compare programs. For example, imagine a program that searches a list. One computer might use a simple search and be fast, but if the list gets very big, a smarter search method on a slower computer might become faster overall.

Scientists use a special way to describe how a program's time grows with bigger inputs, called Big O notation. It helps them understand the worst-case scenario. For example, some sorting programs might take much longer on very large lists, and Big O notation shows this clearly.

By looking at the steps in a program, scientists can predict how much time it will take. They break down each part and add up the time needed. This helps them see which parts might slow down the program the most. For example, some programs might need a lot of memory as the input grows, which can also be predicted using similar methods.

n (list size)Computer A run-time
(in nanoseconds)
Computer B run-time
(in nanoseconds)
168100,000
6332150,000
250125200,000
1,000500250,000
n (list size)Computer A run-time
(in nanoseconds)
Computer B run-time
(in nanoseconds)
168100,000
6332150,000
250125200,000
1,000500250,000
.........
1,000,000500,000500,000
4,000,0002,000,000550,000
16,000,0008,000,000600,000
.........
63,072 × 101231,536 × 1012 ns,
or 1 year
1,375,000 ns,
or 1.375 milliseconds
n (list size)Computer A run-time
(in nanoseconds)
Local order of growth
(n^_)
Computer B run-time
(in nanoseconds)
Local order of growth
(n^_)
157100,000
65321.04150,0000.28
2501251.01200,0000.21
1,0005001.00250,0000.16
.........
1,000,000500,0001.00500,0000.10
4,000,0002,000,0001.00550,0000.07
16,000,0008,000,0001.00600,0000.06
.........

Relevance

Analyzing algorithms is important because using the wrong one can make a computer work very slowly. In cases where time matters, a slow algorithm might give answers too late to be useful. Some algorithms also need too much memory or power, which can make them too expensive or hard to use.

Constant factors

When we study how fast computer programs run, we look at how their speed changes with more data. But real-world speed also depends on small details, like how much memory the computer has.

Computers have limits on how much data they can handle. For example, a computer with 32-bit processing can handle about 4 billion pieces of data, while one with 64-bit processing can handle much more.

Some types of calculations grow very slowly. For example, even with huge amounts of data, certain steps might only need to be done a few times. Because of this, for small or medium amounts of data, a program that usually needs more steps might actually run faster than one that needs fewer steps for very large data. This idea is used in special computer programs that change how they work depending on the size of the data they are handling.

Related articles

This article is a child-friendly adaptation of the Wikipedia article on Analysis of algorithms, available under CC BY-SA 4.0.