34.8 KB · commit a9602da
When does an algorithm provide a satisfactory solution to a problem? First, it must always produce the correct answer. How this can be demonstrated will be discussed in Chapter 5. Second, it should be efficient. The efficiency of algorithms will be discussed in this section.
How can the efficiency of an algorithm be analyzed? One measure of efficiency is the time used by a computer to solve a problem using the algorithm, when input values are of a specified
size. A second measure is the amount of computer memory required by the algorithm to solve a problem, when input values are of a specified size.
The time required to solve a problem of a specified size has been, and will continue to be, of greater importance than the space required. The reason is that hardware is continually becoming cheaper and faster, while the time required to solve a problem using a particular algorithm grows very rapidly with the size of the input. In this section we will focus on the time required by an algorithm to solve a problem.
The time complexity of an algorithm can be expressed in terms of the number of operations used by the algorithm when the input has a particular size. The operations used to measure time complexity can be the addition of two numbers, the multiplication of two numbers, the comparison of two numbers, or the assignment of a value to a variable. In this section we will analyze the number of operations used by an algorithm when the input has a particular size. We will focus on the number of comparisons used by searching and sorting algorithms and the number of additions and multiplications used by algorithms for matrix multiplication.
The time complexity of an algorithm is generally expressed in terms of the number of operations it uses for input of a given size. The worst-case time complexity of an algorithm is the maximum number of operations used by the algorithm to solve a problem with input of a given size. The average-case time complexity of an algorithm is the average number of operations used by the algorithm to solve a problem with input of a given size, assuming some probability distribution on the input values. The best-case time complexity of an algorithm is the minimum number of operations used by the algorithm to solve a problem with input of a given size.
Worst-case analysis tells us the maximum number of operations an algorithm can use to solve a problem of a given size. It guarantees that the algorithm will always solve the problem without using more than this number of operations. Consequently, worst-case analysis provides an upper bound on the time required by the algorithm. Average-case analysis gives the average number of operations used by the algorithm over all possible input of a given size. It provides a measure of how the algorithm performs in typical situations. Best-case analysis tells us the minimum number of operations the algorithm will use.
In this section we will focus on worst-case complexity, because worst-case analysis is generally much easier than average-case analysis, and because it provides an upper bound on the time required by the algorithm.
Describe the time complexity of Algorithm 1 of Section 3.1 for finding the maximum element in a finite sequence of integers.
Solution: The operations used by Algorithm 1 of Section 3.1 are comparisons. First, we note that the algorithm assigns the first element of the sequence to the variable max. Then, each of the remaining n−1 terms of the sequence is compared to max. Because each iteration of the loop uses two comparisons—one to determine whether the end of the loop has been reached and one to compare a term of the sequence to max—a total of 2(n−1) comparisons are used in the loop. One comparison is also used to exit the loop. Hence, a total of 2(n−1)+1=2n−1 comparisons are used. Note that for this algorithm the number of comparisons is independent of particular input values; it depends only on n, the number of terms in the sequence. It follows that the algorithm has Θ(n) worst-case time complexity (and also Θ(n) average-case and best-case time complexity) in terms of the number of comparisons used. ◀
We will now analyze the time complexity of the linear search algorithm (Algorithm 2 in Section 3.1) in terms of the number of comparisons used.
Describe the worst-case time complexity of the linear search algorithm (Algorithm 2 of Section 3.1) in terms of the number of comparisons used.
Solution: At each step of the loop in the linear search algorithm, two comparisons are used: one to determine whether the end of the list has been reached, that is, the comparison i≤n, and one to determine whether the element x has been found, that is, the comparison x=ai. A comparison is also used outside the loop to determine whether i≤n (which checks whether x was found). The worst case occurs when x is not in the list, or when x is the last term of the list. In the worst case, the loop is executed n times. Hence, 2n comparisons are used in the loop. In addition, one comparison is used to exit the loop, and one comparison is used outside the loop. It follows that 2n+2 comparisons are used in the worst case. Consequently, the linear search algorithm has Θ(n) worst-case time complexity in terms of the number of comparisons used. ◀
We now analyze the time complexity of the binary search algorithm (Algorithm 3 in Section 3.1) in terms of the number of comparisons used.
Describe the worst-case time complexity of the binary search algorithm (Algorithm 3 of Section 3.1) in terms of the number of comparisons used.
Solution: For simplicity, assume there are n=2k elements in the list a1,a2,…,an, where k is a nonnegative integer. Note that k=logn. (If n, the number of elements in the list, is not a power of 2, the list can be considered part of a larger list with 2k+1 elements, where 2k<n<2k+1. Here 2k+1 is the smallest power of 2 larger than n.)
At each stage of the algorithm, i and j, the locations of the first term and the last term of the restricted list at that stage, are compared to see whether the restricted list has more than one term. If i<j, a comparison is done to determine whether x is greater than the middle term of the restricted list.
At the first stage the search is restricted to a list with 2k−1 terms. So far, two comparisons have been used. This procedure is continued, using two comparisons at each stage to restrict the search to a list with half as many terms. In other words, two comparisons are used at the first stage of the algorithm when the list has 2k elements, two more when the search has been reduced to a list with 2k−1 elements, two more when the search has been reduced to a list with 2k−2 elements, and so on, until two comparisons are used when the search has been reduced to a list with 21=2 elements. Finally, when one term is left in the list, one comparison tells us that there are no additional terms left, and one more comparison is used to determine if this term is x.
Hence, at most 2k+2=2logn+2 comparisons are required to perform a binary search when the list being searched has 2k elements. (If n is not a power of 2, the original list is expanded to a list with 2k+1 terms, where k=⌊logn⌋, and the search requires at most 2⌈logn⌉+2 comparisons.) It follows that in the worst case, binary search requires O(logn) comparisons. Note that in the worst case, 2logn+2 comparisons are used by the binary search. Hence, the binary search uses Θ(logn) comparisons in the worst case, because 2logn+2=Θ(logn).
From this analysis it follows that in the worst case, the binary search algorithm is more efficient than the linear search algorithm, because we know by Example 2 that the linear search algorithm has Θ(n) worst-case time complexity. ◀
Another important type of complexity analysis, besides worst-case analysis, is called average-case analysis. The average number of operations used to solve the problem over all possible inputs of a given size is found in this type of analysis. Average-case time complexity analysis is usually much more complicated than worst-case analysis.
However, the average-case analysis for the linear search algorithm can be done without difficulty, as shown in Example 4.
Describe the average-case performance of the linear search algorithm in terms of the average number of comparisons used, assuming that the integer x is in the list and it is equally likely that x is in any position.
Solution: By hypothesis, the integer x is one of the integers a1,a2,…,an in the list. If x is the first term a1 of the list, three comparisons are needed, one i≤n to determine whether the end of the list has been reached, one x=ai to compare x and the first term, and one i≤n outside the loop. If x is the second term a2 of the list, two more comparisons are needed, so that a total of five comparisons are used. In general, if x is the ith term of the list ai, two comparisons will be used at each of the i steps of the loop, and one outside the loop, so that a total of 2i+1 comparisons are needed. Hence, the average number of comparisons used equals n3+5+7+⋯+(2n+1)=n2(1+2+3+⋯+n)+n. Using the formula from line 2 of Table 2 in Section 2.4 (and see Exercise 37(b) of Section 2.4), 1+2+3+⋯+n=2n(n+1). Hence, the average number of comparisons used by the linear search algorithm (when x is known to be in the list) is n2[n(n+1)/2]+1=n+2, which is Θ(n). ◀
We analyze the worst-case complexity of the bubble sort and the insertion sort in Examples 5 and 6.
What is the worst-case complexity of the bubble sort in terms of the number of comparisons made?
Solution: The bubble sort described before Example 4 in Section 3.1 sorts a list by performing a sequence of passes through the list. During each pass the bubble sort successively compares adjacent elements, interchanging them if necessary. When the ith pass begins, the i−1 largest elements are guaranteed to be in the correct positions. During this pass, n−i comparisons are used. Consequently, the total number of comparisons used by the bubble sort to order a list of n elements is (n−1)+(n−2)+⋯+2+1=2(n−1)n
using a summation formula from line 2 in Table 2 in Section 2.4 (and Exercise 37(b) in Section 2.4). Note that the bubble sort always uses this many comparisons, because it continues even if the list becomes completely sorted at some intermediate step. Consequently, the bubble sort uses (n−1)n/2 comparisons, so it has Θ(n2) worst-case complexity in terms of the number of comparisons used. ◀
What is the worst-case complexity of the insertion sort in terms of the number of comparisons made?
Solution: The insertion sort (described in Section 3.1) inserts the jth element into the correct position among the first j−1 elements that have already been put into the correct order. It does this by using a linear search technique, successively comparing the jth element with successive terms until a term that is greater than or equal to it is found or it compares aj with itself and stops because aj is not less than itself. Consequently, in the worst case, j comparisons are required to insert the jth element into the correct position. Therefore, the total number of comparisons used by the insertion sort to sort a list of n elements is 2+3+⋯+n=2n(n+1)−1, using the summation formula for the sum of consecutive integers in line 2 of Table 2 of Section 2.4 (and see Exercise 37(b) of Section 2.4), and noting that the first term, 1, is missing in this sum. Note that the insertion sort may use considerably fewer comparisons if the smaller elements started out at the end of the list. We conclude that the insertion sort has worst-case complexity Θ(n2). ◀
In Examples 5 and 6 we showed that both the bubble sort and the insertion sort have worst-case time complexity Θ(n2). However, the most efficient sorting algorithms can sort n items in O(nlogn) time, as we will show in Sections 8.3 and 11.1 using techniques we develop in those sections. From this point on, we will assume that sorting n items can be done in O(nlogn) time.
The definition of the product of two matrices can be expressed as an algorithm for computing the product of two matrices. Suppose that C=[cij] is the m×n matrix that is the product of the m×k matrix A=[aij] and the k×n matrix B=[bij]. The algorithm based on the definition of the matrix product is expressed in pseudocode in Algorithm 1.
ALGORITHM 1 Matrix Multiplication.
procedure matrix multiplication(A, B: matrices)
for i := 1 to m
for j := 1 to n
cij := 0
for q := 1 to k
cij := cij + aiq * bqj
return C {C = [cij] is the product of A and B}
We can determine the complexity of this algorithm in terms of the number of additions and multiplications used.
How many additions of integers and multiplications of integers are used by Algorithm 1 to multiply two n×n matrices with integer entries?
Solution: There are n2 entries in the product of A and B. To find each entry requires a total of n multiplications and n−1 additions. Hence, a total of n3 multiplications and n2(n−1) additions are used. ◀
Surprisingly, there are more efficient algorithms for matrix multiplication than that given in Algorithm 1. As Example 7 shows, multiplying two n×n matrices directly from the definition requires O(n3) multiplications and additions. Using other algorithms, two n×n matrices can be multiplied using O(n7) multiplications and additions.
We can also analyze the complexity of the algorithm we described in Chapter 2 for computing the Boolean product of two matrices, which we display as Algorithm 2.
ALGORITHM 2 The Boolean Product of Zero-One Matrices.
procedure Boolean product of Zero-One Matrices(A, B: zero–one matrices)
for i := 1 to m
for j := 1 to n
cij := 0
for q := 1 to k
cij := cij ∨ (aiq ∧ bqj)
return C {C = [cij] is the Boolean product of A and B}
The number of bit operations used to find the Boolean product of two n×n matrices can be easily determined.
How many bit operations are used to find A⊙B, where A and B are n×n zero–one matrices?
Solution: There are n2 entries in A⊙B. Using Algorithm 2, a total of n ORs and n ANDs are used to find an entry of A⊙B. Hence, 2n bit operations are used to find each entry. Therefore, 2n3 bit operations are required to compute A⊙B using Algorithm 2. ◀
There is another important problem involving the complexity of the multiplication of matrices. How should the matrix-chain A1A2⋯An be computed using the fewest multiplications of integers, where A1,A2,…,An are m1×m2,m2×m3,…,mn×mn+1 matrices, respectively, and each has integers as entries? (Because matrix multiplication is associative, as shown in Exercise 13 in Section 2.6, the order of the multiplication used does not change the product.) Note that m1m2m3 multiplications of integers are performed to multiply an m1×m2 matrix and an m2×m3 matrix using Algorithm 1. Example 9 illustrates this problem.
In which order should the matrices A1,A2, and A3—where A1 is 30×20, A2 is 20×40, and A3 is 40×10, all with integer entries—be multiplied to use the least number of multiplications of integers?
Solution: There are two possible ways to compute A1A2A3. These are A1(A2A3) and (A1A2)A3.
If A2 and A3 are first multiplied, a total of 20⋅40⋅10=8000 multiplications of integers are used to obtain the 20×10 matrix A2A3. Then, to multiply A1 and A2A3 requires 30⋅20⋅10=6000 multiplications. Hence, a total of 8000+6000=14,000
multiplications are used. On the other hand, if A1 and A2 are first multiplied, then 30⋅20⋅40=24,000 multiplications are used to obtain the 30×40 matrix A1A2. Then, to multiply A1A2 and A3 requires 30⋅40⋅10=12,000 multiplications. Hence, a total of 24,000+12,000=36,000 multiplications are used.
Clearly, the first method is more efficient. ◀
We will return to this problem in Exercise 57 in Section 8.1. Algorithms for determining the most efficient way to carry out matrix-chain multiplication are discussed in the literature.
In Section 3.1 we introduced the basic notion of an algorithm. We provided examples of many different algorithms, including searching and sorting algorithms. We also introduced the concept of a greedy algorithm, giving examples of several problems that can be solved by greedy algorithms. Greedy algorithms provide an example of an algorithmic paradigm, that is, a general approach based on a particular concept that can be used to construct algorithms for solving a variety of problems.
In this book we will construct algorithms for solving many different problems based on a variety of algorithmic paradigms, including the most widely used algorithmic paradigms. These paradigms can serve as the basis for constructing efficient algorithms for solving a wide range of problems.
Some of the algorithms we have already studied are based on an algorithmic paradigm known as brute force, which we will describe in this section. Algorithmic paradigms, studied later in this book, include divide-and-conquer algorithms studied in Chapter 8, dynamic programming, also studied in Chapter 8, backtracking, studied in Chapter 10, and probabilistic algorithms, studied in Chapter 7. There are many important algorithmic paradigms besides those described in this book.
Brute force is an important, and basic, algorithmic paradigm. In a brute-force algorithm, a problem is solved in the most straightforward manner based on the statement of the problem and the definitions of terms. Brute-force algorithms are designed to solve problems without regard to the computing resources required. For example, in some brute-force algorithms the solution to a problem is found by examining every possible solution, looking for the best possible. In general, brute-force algorithms are naive approaches for solving problems that do not take advantage of any special structure of the problem or clever ideas.
Note that Algorithm 1 in Section 3.1 for finding the maximum number in a sequence is a brute-force algorithm because it examines each of the n numbers in a sequence to find the maximum term. The algorithm for finding the sum of n numbers by adding one additional number at a time is also a brute-force algorithm, as is the algorithm for matrix multiplication based on its definition (Algorithm 1). The bubble, insertion, and selection sorts (described in Section 3.1 in Algorithms 4 and 5 and in Exercise 42, respectively) are also considered to be brute-force algorithms; all three of these sorting algorithms are straightforward approaches much less efficient than other sorting algorithms such as the merge sort and the quick sort discussed in Chapters 5 and 8.
Although brute-force algorithms are often inefficient, they are often quite useful. A brute-force algorithm may be able to solve practical instances of problems, particularly when the input
is not too large, even if it is impractical to use this algorithm for large instances. Also, a brute-force algorithm can serve as a benchmark to compare with more clever and sophisticated algorithms.
We now describe a brute-force algorithm for an important problem in computational geometry, that of finding the closest pair of points in the plane.
Given n points (x1,y1),(x2,y2),…,(xn,yn) in the plane, find a pair of points with the smallest distance between them. Describe a brute-force algorithm for solving this problem and determine its time complexity.
Solution: Recall that the distance between (xi,yi) and (xj,yj) is (xj−xi)2+(yj−yi)2. A brute-force algorithm computes the distances between all pairs of points and selects a pair with the smallest distance. There are (2n)=n(n−1)/2 pairs of points. Computing the distance between a pair of points requires four additions/subtractions, two multiplications, and one square root. Then, finding the smallest distance among the n(n−1)/2 distances requires n(n−1)/2−1 comparisons (using Algorithm 1 of Section 3.1).
It follows that the number of operations used to find the closest pair of points among n points in the plane is O(n2). (A more efficient algorithm that uses the divide-and-conquer paradigm to find the closest pair of points in O(nlogn) time will be discussed in Section 8.3.) ◀
Table 1 displays some common terminology used to describe the time complexity of algorithms.
| Complexity | Terminology |
|---|---|
| Θ(1) | Constant complexity |
| Θ(logn) | Logarithmic complexity |
| Θ(n) | Linear complexity |
| Θ(nlogn) | Linearithmic complexity |
| Θ(nb) | Polynomial complexity |
| Θ(bn), where b>1 | Exponential complexity |
| Θ(n!) | Factorial complexity |
Algorithms with constant complexity are ideal. These algorithms require only a fixed number of operations, regardless of the size of the input. Algorithms with logarithmic complexity are also extremely efficient, because logn grows very slowly as n grows. Algorithms with linear complexity are also considered efficient. Algorithms with O(nlogn) complexity are called linearithmic algorithms; they are also considered relatively efficient.
Algorithms with polynomial time complexity, that is, with complexity Θ(nb) where b is an integer with b≥1, are considered to be efficient if b is relatively small (such as b=1,2, or 3). For instance, the linear search algorithm has linear complexity, and the bubble and insertion sorts have quadratic complexity, which is Θ(n2).
An algorithm that has exponential time complexity, that is, Θ(bn) where b>1, or factorial time complexity, that is, Θ(n!), is not considered to be efficient. For example, an algorithm that determines whether a compound proposition in n variables is satisfiable by checking all possible assignments of truth variables is an algorithm with exponential complexity, because it uses Θ(2n) operations. Finally, an algorithm has factorial complexity if it has Θ(n!) time complexity. The algorithm that finds all orders that a traveling salesperson could use to visit n cities has factorial complexity; we will discuss this algorithm in Chapter 9.
A problem that is solvable using an algorithm with polynomial worst-case complexity is called tractable, because the expectation is that the algorithm will produce the solution to the problem for reasonably sized input in a relatively short time. However, if the polynomial in the big-Θ estimate has high degree (such as degree 100) or if the coefficients are extremely large, the algorithm may take an extremely long time to solve the problem. Consequently, that a problem can be solved using an algorithm with polynomial worst-case time complexity is no guarantee that the problem can be solved in a reasonable amount of time for even relatively small input values. Fortunately, in practice, the degree and coefficients of polynomials in such estimates are often small.
The situation is much worse for problems that cannot be solved using an algorithm with worst-case polynomial time complexity. Such problems are called intractable. Usually, but not always, an extremely large amount of time is required to solve the problem for the worst cases of even small input values. In practice, however, there are situations where an algorithm with a certain worst-case time complexity may be able to solve a problem much more quickly for most cases than for its worst case. When we are willing to allow that some, perhaps small, number of cases may not be solved in a reasonable amount of time, the average-case time complexity is a better measure of how long an algorithm takes to solve a problem. Many problems important in industry are thought to be intractable but can be practically solved for essentially all sets of input that arise in daily life. Another way that intractable problems are handled when they arise in practical applications is that instead of looking for exact solutions of a problem, approximate solutions are sought. It may be the case that fast algorithms exist for finding such approximate solutions, perhaps even with a guarantee that they do not differ by very much from an exact solution.
Some problems even exist for which it can be shown that no algorithm exists for solving them. Such problems are called unsolvable (as opposed to solvable problems that can be solved using an algorithm). The first proof that there are unsolvable problems was provided by the great English mathematician and computer scientist Alan Turing when he showed that the halting problem is unsolvable. Recall that we proved that the halting problem is unsolvable in Section 3.1.
The study of the complexity of algorithms goes far beyond what we can describe here. Note, however, that many solvable problems are believed to have the property that no algorithm with polynomial worst-case time complexity solves them, but that a solution, if known, can be checked in polynomial time. Problems for which a solution can be checked in polynomial time are said to belong to the class NP (tractable problems are said to belong to class P). The abbreviation NP stands for nondeterministic polynomial time. The satisfiability problem, discussed in Section 1.3, is an example of an NP problem—we can quickly verify that an assignment of truth values to the variables of a compound proposition makes it true, but no polynomial time algorithm has been discovered for finding such an assignment of truth values. (For example, an exhaustive search of all possible truth values requires Θ(2n) bit operations where n is the number of variables in the compound proposition.)
There is also an important class of problems, called NP-complete problems, with the property that if any of these problems can be solved by a polynomial worst-case time algorithm, then all problems in the class NP can be solved by polynomial worst-case time algorithms. The satisfiability problem is also an example of an NP-complete problem. It is an NP problem and if a polynomial time algorithm for solving it were known, there would be polynomial time algorithms for all problems known to be in this class of problems (and there are many important problems in this class). This last statement follows from the fact that every problem in NP can be reduced in polynomial time to the satisfiability problem. Although more than 3000 NP-complete problems are now known, the satisfiability problem was the first problem shown to be NP-complete. The theorem that asserts this is known as the Cook-Levin theorem after Stephen Cook and Leonid Levin, who independently proved it in the early 1970s.
The P versus NP problem asks whether NP, the class of problems for which it is possible to check solutions in polynomial time, equals P, the class of tractable problems. If P=NP, there would be some problems that cannot be solved in polynomial time, but whose solutions could be verified in polynomial time. The concept of NP-completeness is helpful in research aimed at solving the P versus NP problem, because NP-complete problems are the problems in NP considered most likely not to be in P, as every problem in NP can be reduced to an NP-complete problem in polynomial time. A large majority of theoretical computer scientists believe that P=NP, which would mean that no NP-complete problem can be solved in polynomial time. One reason for this belief is that despite extensive research, no one has succeeded in showing that P=NP. In particular, no one has been able to find an algorithm with worst-case polynomial time complexity that solves any NP-complete problem. The P versus NP problem is one of the most famous unsolved problems in the mathematical sciences (which include theoretical computer science). It is one of the seven famous Millennium Prize Problems, of which six remain unsolved. A prize of $1,000,000 is offered by the Clay Mathematics Institute for its solution.
Note that a big-Θ estimate of the time complexity of an algorithm expresses how the time required to solve the problem increases as the input grows in size. In practice, the best estimate (that is, with the smallest reference function) that can be shown is used. However, big-Θ estimates of time complexity cannot be directly translated into the actual amount of computer time used. One reason is that a big-Θ estimate f(n) is Θ(g(n)), where f(n) is the time complexity of an algorithm and g(n) is a reference function, means that C1g(n)≤f(n)≤C2g(n) when n>k, where C1,C2, and k are constants. So without knowing the constants C1,C2, and k in the inequality, this estimate cannot be used to determine a lower bound and an upper bound on the number of operations used in the worst case. As remarked before, the time required for an operation depends on the type of operation and the computer being used. Often, instead of a big-Θ estimate on the worst-case time complexity of an algorithm, we have only a big-O estimate. Note that a big-O estimate on the time complexity of an algorithm provides an upper, but not a lower, bound on the worst-case time required for the algorithm as a function of the input size. Nevertheless, for simplicity, we will often use big-O estimates when describing the time complexity of algorithms, with the understanding that big-Θ estimates would provide more information.
Table 2 displays the time needed to solve problems of various sizes with an algorithm using the indicated number n of bit operations, assuming that each bit operation takes 10−11 seconds, a reasonable estimate of the time required for a bit operation using the fastest computers available today. Times of more than 10100 years are indicated with an asterisk. In the future, these times will decrease as faster computers are developed. We can use the times shown in Table 2 to see whether it is reasonable to expect a solution to a problem of a specified size using an algorithm with known worst-case time complexity when we run this algorithm on a modern computer. Note that we cannot determine the exact time a computer uses to solve a problem with input of a particular size because of a myriad of issues involving computer hardware and the particular software implementation of the algorithm.
| Problem Size n | logn | n | nlogn | n2 | 2n | n! |
|---|---|---|---|---|---|---|
| 10 | 3×10−11 s | 10−10 s | 3×10−10 s | 10−9 s | 10−8 s | 3×10−7 s |
| 102 | 7×10−11 s | 10−9 s | 7×10−9 s | 10−7 s | 4×1011 yr | ∗ |
| 103 | 1.0×10−10 s | 10−8 s | 1×10−7 s | 10−5 s | ∗ | ∗ |
| 104 | 1.3×10−10 s | 10−7 s | 1×10−6 s | 10−3 s | ∗ | ∗ |
| 105 | 1.7×10−10 s | 10−6 s | 2×10−5 s | 0.1 s | ∗ | ∗ |
| 106 | 2×10−10 s | 10−5 s | 2×10−4 s | 0.17 min | ∗ | ∗ |
* Times exceeding 10100 years are indicated with an asterisk.
It is important to have a reasonable estimate for how long it will take a computer to solve a problem. For instance, if an algorithm requires approximately 10 hours, it may be worthwhile to spend the computer time (and money) required to solve this problem. But, if an algorithm requires approximately 10 billion years to solve a problem, it would be unreasonable to use resources to implement this algorithm. One of the most interesting phenomena of modern technology is the tremendous increase in the speed and memory space of computers. Another important factor that decreases the time needed to solve problems on computers is parallel processing, which is the technique of performing sequences of operations simultaneously.
Efficient algorithms, including most algorithms with polynomial time complexity, benefit most from significant technology improvements. However, these technology improvements
offer little help in overcoming the complexity of algorithms of exponential or factorial time complexity. Because of the increased speed of computation, increases in computer memory, and the use of algorithms that take advantage of parallel processing, many problems that were considered impossible to solve five years ago are now routinely solved, and certainly five years from now this statement will still be true. This is even true when the algorithms used are intractable.