|
The concept of the complexity of an algorithm is measured as the time or storage space cost required to execute it in the worst or average case. This concept provides a mathematical definition for the rather vague term "hardness," which is sometimes used to characterize algorithms. |
|
When an algorithm |
|
|
|
For a fixed input size, the inputs of an algorithm can vary, in which case the cost generally varies as well.
The worst-case time and space complexities of an algorithm ![]() ![]() ![]() ![]() |
|
|
|
The worst-case complexity determines a tight upper bound for the possible cost of the algorithm on inputs of given size. It cannot be ruled out that in some cases this bound is rather large, while inputs corresponding to the worst case are rarely encountered among all inputs of given size. |
|
|
Question:
Suppose that an algorithm
![]() ![]() ![]() ![]() ![]()
|
|
Question:
Let
![]() ![]() ![]() ![]() ![]() ![]()
|
|
Question:
Is it true that the space complexity of selection sort (with the array length
![]() ![]()
|
|
Question:
Let an algorithm
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
|
When discussing average-case complexity, we consider only the situation when, for each fixed input size
|
|
|
|
Given an arbitrary algorithm |
|
|
|
If an algorithm is repeatedly applied to inputs of given size, it can be expected that the arithmetic mean of the costs is close to the average-case complexity of this algorithm. However, it is assumed in this case that the inputs of given size are appropriately assigned some probabilities, while this assumption has to be justified (the typical assumption that all the inputs of each size are equiprobable may appear groundless in a particular situation). |
|
|
|
|
|
Question:
Is it true that the average-case complexity of an algorithm requires that
a probability distribution be specified:
|
|
Question:
Let an algorithm
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
|
Question:
Consider the set of all permutations of
![]() ![]() ![]() ![]() ![]() ![]()
|
|
As was discussed above, the worst- and average-case complexities of an algorithm are both a function of a numerical argument-the input size. The growth of the complexity of a particular algorithm with increasing input size is frequently analyzed using asymptotic bounds of the form ![]() ![]() ![]() ![]() |
|
|
|
A comparison of the complexities of different algorithms based on their asymptotic
complexity bounds can be made not for all types of such bounds.
For example, if algorithms |
|
|
|
|
|
|
|
Question:
Suppose that the polynomial
![]() ![]()
|
|
Question:
Which of the following assertions is not true for the complexity
![]() ![]()
|
|
Question:
Let the cost of any compass-and-straightedge construction in plane geometry be the number of lines
(circles or straight lines) drawn in the course of the construction. Consider the problem of constructing
a line segment whose length is
![]() ![]() ![]()
|
|
We can consider different complexities according to the costs taken into account. Suppose that a time cost function gives the number of operations of some type, assuming that they require an identical runtime independent of the operand size and set equal to 1. Then we obtain an algebraic complexity measured as the number of operations of the given type. |
|
|
|
Bit time complexity is obtained when the number of bit operations is used as a cost function. In a similar fashion, the space algebraic and bit space complexities can be defined using the number of operations values of the considered type. |
|
|
|
|
Question:
It is well known that the multiplicative complexity of Gaussian elimination as applied to a system of
![]() ![]()
|
|
Question:
Suppose that two positive integers
![]() ![]() ![]() ![]() ![]()
|
|
Question:
Given a number initially equal to zero, a 1 is added to it at every step until
![]() ![]() ![]()
|
|
The concept of complexity is also considered in the case of randomized algorithms, i.e., algorithms making calls to a random number generator with a known distribution. |
|
|
|
Generally, the cost of a randomized algorithm is not uniquely determined by its input, but also depends on the generated random numbers. However, the averaged cost for each particular input gives a scalar numeric function on the set of inputs. As a result, the complexity of an algorithm can be treated following the general definition of complexity. |
|
|
|
As was previously discussed, the average-case complexity of a "usual" (deterministic) algorithm is of interest only if correct assumptions are made about the probability of occurrence of one or another input. The considered complexity of randomized algorithms is worst-case complexity but it is determined by the averaged costs. Nevertheless, this averaging can be trusted, since randomized algorithms make use of random number generators in which the probability distribution is fixed and independent of the inputs. |
|
|
|
|
|
Question:
Is it true that the determination of the averaged cost of a randomized algorithm requires specifying a probability distribution:
|
|
Question:
An array
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
|
Question:
Assume that there is a random number generator returning 0 with probability
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
|
In computational complexity theory, initial assumptions are made about a hypothetical computing device (known as a model of computation). |
|
A random-access machine (RAM) is used as such a model in some cases, while a Turing machine is chosen in other cases. |
|
|
|
The former model is closer to actual devices, while the latter is more formalized, which is frequently useful in the existence analysis of an algorithm with certain complexity properties. |
|
We will use the RAM model. The assumption that the size of a cell is unlimited leads to algebraic complexity, while the assumption that one bit is stored in a cell leads to time or space bit complexity. |
|
The considered concept of complexity is sometimes referred to as computational complexity (its possible special cases are algebraic and bit complexities) in order to distinguish it from descriptive complexity, which is somehow defined relying on the code of an algorithm. |
|
|
|
Only computational complexity is discussed below, and we continue to refer to it as complexity. |
|
Considering a class of algorithms for solving a problem yields a family of functions that are complexities (for example, time complexities) of algorithms in this class. Accordingly, we can discuss a lower bound for this family and the existence of a minimal function in it. |
|
|
|
If there is a minimal function in this family, then the corresponding algorithm is optimal in the considered class of algorithms. |
|
|
|
|
Question:
Is
![]() ![]() ![]()
|
|
Question:
Consider the problem of computing
![]() ![]() ![]() ![]()
|
|
Question:
A traveler encounters a wall that extends to infinity in both directions.
There is a door in the wall, but neither the distance to it nor
the direction toward it is known to the traveler. Let the input size be the number
![]() ![]() ![]() ![]()
|
|
Question:
Is it true that the function
![]() ![]()
|
|
Question:
Let
![]() ![]() ![]() ![]() ![]() ![]()
|
|
Optimal algorithms in a given class are not always known. It is also possible that a given class has no optimal algorithm, i.e., an algorithm whose complexity is a lower complexity bound for algorithms in this class. |
|
|
|
Rather frequently, it is very difficult to answer whether a particular class of algorithms has one whose complexity does not grow too fast with increasing input size. |
|
|
|
For some classes of algorithms, a difficult question is whether there exists an algorithm in such a class with complexity bounded above by a polynomial whose form is not specified (such an algorithm is known as polynomial-time). |
|
|
|
In particular, many unanswered questions concern polynomial-time algorithms for decision problems, i.e., those having a yes/no solution, or a 1/0 solution, etc. In this context, we mention the well-known P≟NP problem. |
|
|
|
|
Question:
Assume that the cost of any compass-and-straightedge construction in the plane is the number of lines
(circles or straight lines) drawn in the course of the construction. Consider the problem
of constructing a segment whose length is
![]() ![]() ![]()
|
|
Question:
The existence of a polynomial-time algorithm for decomposing an integer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
|
Question:
Is it possible to compute the product of two given complex numbers
![]() ![]() ![]() ![]()
|
|
Question:
Is it true that P
![]()
|
|
When we examine the existence of an algorithm of "not very high" complexity, an important role is played by the reducibility of one problem to another. The possibility of quickly solving some problem can imply the same possibility for a number of other problems and, on the contrary, if a certain problem cannot be quickly solved, the same can automatically be implied for a number of other problems. |
|
Considering linear reducibility, we can rigorously define the fact that one computational problem is not harder than another. |
|
|
|
Polynomial reducibility means that, if a computational problem is solvable by a polynomial-time algorithm, then another problem is also solvable by a polynomial-time algorithm. |
|
|
|
|
Question:
Is the multiplication of arbitrary square matrices linearly
reducible (see above in this section) to the multiplication of upper
triangular matrices, assuming that the latter problem is solved only by algorithms
for which
![]()
|
|
Question:
Are there problems in NP that are not NP-complete?
|
|
Question:
Imagining that there is no polynomial-time algorithm for testing
the primality of a positive integer (i.e., the AKS algorithm (see Section 9) does not exist),
would it be true that P
![]()
|
|
Along with various questions concerning the possible limits for algorithms from one or another class, always important are problems associated with complexity bounds for particular algorithms. Frequently, trivial upper and lower bounds are easy to derive, while deriving close-to-tight bounds for an algorithm requires much effort and nontrivial approaches. |
|
|
|
|
Question:
A binary algorithm for finding an element place in an ordered array of length
![]() ![]() ![]() ![]() ![]() ![]()
|
|
Question:
The complexity
![]() ![]() ![]() ![]() ![]()
|
|
Question:
Is it true that
![]() ![]() ![]() ![]()
|
|
Question:
Let
![]() ![]()
for
if od assuming that all possible relative orders of the elements in the original array of length![]()
|