



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Chapter 10 – Limitations of Algorithm Power At the beginning of the class, we discussed a number of approaches to this subject. We mentioned that we could consider problems, strategies, algorithms, and programs. At this point, we restate these categories. Algorithms can be defined as formal well-defined approaches to solving problems. When algorithms are adapted to run on computers, we call them programs. We have noted that there are a number of strategies for designing algorithms, in that many algorithms for different problems share common design approaches. At this point, we focus only on problems and algorithms. Each problem of interest is usually solvable by a number of algorithms. It is quite simple to assess the time complexity of a given algorithm. We now address the more difficult question of the time complexity of a specific problem; that is, to specify the lower bound on time complexity on any algorithm that solves the problem. Some lower bounds are simple, even trivial. Other lower bounds have defied every attempt, up to present, to compute a meaningful value. One of the best ways to introduce this chapter is to quote from the standard source on this subject, the monograph by Michael Garey and David Johnson published in 1979 with the title Computers and Intractability: A Guide to the Theory of NP-Completeness. This book opens with a hypothetical example. You are the chief algorithm designer for a manufacturing company. Your boss presents you with a problem for which you can find no algorithm more efficient than examining every possible solution to the problem and ranking the cost of each solution. Since this approach is prohibitively expensive, you decide to report to your boss. What do you say?
A lower bound on computational complexity is considered to be tight , if there exists an algorithm with that complexity. Consider two problems associated with matrix arithmetic: matrix addition and matrix multiplication. Each of these involves processing an N-by-N matrix and thus each of these problems must be (N^2 ). Let’s compare these two problems with another famous problem, the Traveling Salesman Problem (TSP), which is also easily shown to be (N^2 ) as it must process (^) 2 N =
intercity distances. But one glance at the following table will show that we have vastly different scenarios. Problem Lower Best Known Comment Bound Algorithm Matrix Addition (N^2 ) O(N^2 ) Lower bound is tight. Matrix Multiplication (N^2 ) O(N2.376) Lower bound is not too bad. TSP (N^2 ) O(2N) Lower bound is useless. Decision Trees and Lower Bound Arguments We now discuss a method that can give non-trivial lower bounds for two problems of interest: searching an ordered list of N items and sorting a list of N items. The lower bound for each of these two problems is established by use of binary decision trees. Although other decision trees are possible, indeed ternary decision trees are discussed in the text, we restrict ourselves to binary trees because we are dealing with operators having two results. Search the operator is equality, with two results “=” or “” Sorting the operator is either “≥” with two results “≥” or “<”, or “” with two results “” or “>”. The basic lower bound result depends on the fact that a binary tree of height H cannot have more than 2 H^ leaf nodes. Thus, given a binary tree with L leaves, we obtain the lower bound on the tree height as H ≥ log 2 L, thus a binary tree with 8 leaves must have height at least 3. In a decision tree, each leaf node represents a possible outcome of the sequence of decisions, while each interior node represents a decision. Thus, if a problem modeled by a decision tree has L possible outcomes, then the decision tree has L leaf nodes, and a binary decision tree representing the problem must have height at least log 2 L. This observation places a lower limit on the time complexity of any algorithm that solves the problem. We use binary decision trees to examine three different problems (and skip the ternary trees).
Here is a version of the game for the interval 0 through 15 inclusive. After each answer, we present the closed interval that is consistent with the answers already given. Thus, if the number is not greater than 7, it must be in the closed interval [0, 7]. Q: Is the number larger than 7? A: No [0, 7] Q: Is the number larger than 3? A: Yes [4, 7] Q: Is the number larger than 5? A: No [4, 5] Q: Is the number larger than 4? A: No [4, 4] At this point, there is only one number in the interval that is consistent with all of my answers. This is the number 4, which must be the answer if I have answered truthfully. Recall that the adversary in this game must answer truthfully, but is allowed to change the target of the search in any way that makes the process more difficult as long as each change is consistent with all answers and honest at the time of the answer. To simplify the example, we show the decision tree for a successful search of 8 elements, A 0 , A 1 , …, A 7 sorted in increasing order with no two elements equal. In general, the decision tree for a binary search of N sorted elements has N leaves, thus the height of the tree is given by H ≥ log 2 N. The height gives the minimum number of comparisons to solve the problem generally and hence dictates the time complexity of the algorithm. Binary search is the best algorithm for searching a sorted array, so the problem is (log N). The lower bound on any algorithm to solve the problem is (log N) and we have an algorithm that is O(log N), so we say that the lower limit is sharp.
Sorting an Array of N Distinct Items We start by noting that we have a number of good sort algorithms, each of time complexity O(N log 2 N). We now establish a theoretical lower bound on the problem of sorting by comparison only. Here we assume that the operator is “≥“, but it could be “”. To start the discussion, consider the problem of sorting an array of three distinct elements: A 0 , A 1 , A 2. There are six possible orderings of these elements, one of which is sorted. A 0 , A 1 , A 2 A 0 , A 2 , A 1 A 1 , A 0 , A 2 A 1 , A 2 , A 0 A 2 , A 0 , A 1 A 2 , A 1 , A 0 In general there are N! possible orderings of a list of N distinct elements and less when the elements are not required to be distinct. As we must examine the worst case of the problem in order to establish a lower bound, we shall consider all elements to be distinct. It there are N! possible outcomes to the sorting problem, then the decision tree must have at least N! leaf nodes. Given that we are using a binary operator for sorting, we must assume a binary decision tree, which must have height greater than log 2 (N!). Thus, the number of comparisons to determine the correct sorted order is at least log 2 (N!). It is a standard result to show that log 2 (N!) Nlog 2 (N), so that we have concluded that any algorithm that can possibly sort an array by comparison must have complexity at least Nlog 2 (N). We have a number of algorithms with that time complexity, so we have another sharp lower bound. The student should note that the binary decision tree for the sort problem does not have all of its leaf nodes. This is because the number of orderings, N!, is never a power of two. In fact we here prove that N! is not a power of 2 unless N 2. 0! = 1, by definition and 2^0 = 1, so 0! is a power of two. 1! = 1 and 2^0 = 1, so 1! is a power of two. 2! = 2 and 2^1 = 2, so 2! is a power of two. For N ≥ 3, the number N! has at least one 3 as a factor. No number with 3 as a factor can be a power of two, so our proof is complete.