Algorithms: Design Techniques and Analysis (Lecture Notes Series on Computing)
Format: PDF / Kindle (mobi) / ePub
Problem solving is an essential part of every scientific discipline. It has two components: (1) problem identification and formulation, and (2) solution of the formulated problem. One can solve a problem on its own using ad hoc techniques or follow those techniques that have produced efficient solutions to similar problems. This requires the understanding of various algorithm design techniques, how and when to use them to formulate solutions and the context appropriate for each of them. This book advocates the study of algorithm design techniques by presenting most of the useful algorithm design techniques and illustrating them through numerous examples.
operation deletes and returns an item of maximum key in a nonempty heap H . It costs Q(1) time t o return the element with maximum key in a heap, as it is the root of the tree. However, since deleting the root destroys the heap, more work is needed t o restore the heap data structure. A straightforward implementation of this operation makes use of the delete operation: Simply return the element stored in the root and delete it from the heap. The method for this operation is given in Algorithm
First, we note that the elements A"nI2J + "I21 111 f 211.. .1'4[nI correspond to the leaves of T , and therefore we may start adjusting the Heaps 123 array at A[ Ln/2]] and continue the adjustments at A[lnI2J - 1l,A[Ln/2J - 21,. . , 4 1 1 . Once the subtree rooted at A, which is T itself, is adjusted, the resulting array is the desired heap. Algorithm MAKEHEAP constructs a heap whose items are the elements stored in an array A[l..n]. Algorithm 4.4 MAKEHEAP Input,: An array A[l..n] of
input to the algorithm be A[l..n]. For the induction hypothesis, suppose we know how to sort the last n - 1 elements, i.e., A[2..n]. Let the minimum be A[j], for some j, 1 5 j 5 n. First, we interchange A and A [ j ] if j # 1. Next, since by induction we know how t o sort A[2..n],we recursively sort the elements in A[2..n]. This inductive reasoning leads to the recursive version of Algorithm SELECTIONSORT shown as Algorithm SELECTIONSORTREC. Converting this algorithm to an iterative one is
problems. Not only that; it was also proven that those algorithms are optimal in the sense that if any new algorithm to solve the same problem is discovered, then the gain in terms of efficiency is virtually minimal. For exampie, the problem of sorting a set of elements has been studied extensively; and as a result, several efficient algorithms to solve this problem have been devised, and it was proven that these algorithms are optimal in the sense that no substantially better algorithm can ever
o ~ ~ ~ si.e., volving objects in the input data. Thus, all other comparisons, e.g. those needed for the implementation of the while loop, will be excluded. Let the two subarrays be of sizes n1 and n2, where nl + 722 = n. The least number of comparisons happens if each entry in the smaller subarray is less than all entries in the larger subarray. For example, to merge the two subarrays m] and ,1-1 the algorithm performs only three comparisons. On the other hand, the Basic Concepts in