Chapter 2: Problem 22
Verify the following identity \(\sum_{p=1}^{n}[A(p-1)+A(n-p)]=2 \sum_{p=1}^{n} A(p-1)\) This result is used in the discussion of the average-case time complexity analysis of Algorithm 2.6 (Quicksort).
Chapter 2: Problem 22
Verify the following identity \(\sum_{p=1}^{n}[A(p-1)+A(n-p)]=2 \sum_{p=1}^{n} A(p-1)\) This result is used in the discussion of the average-case time complexity analysis of Algorithm 2.6 (Quicksort).
All the tools & learning materials you need for study success - in one app.
Get started for freeShow that the worst-case time complexity for Binary Search (Algorithm 2.1) is given by \(W(n)=[\lg n]+1\) When \(n\) is not restricted to being a power of \(2 .\) Hint. First show that the recurrence equation for \(W(n)\) is given by \(W(n)=1+W\left(\left\lfloor\frac{n}{2}\right\rfloor\right) \quad\) for \(n>1\) \(W(1)=1\) To do this, consider even and odd values of \(n\) separately. Then use induction to solve the recurrence equation.
Write an algorithm that searches a sorted list of \(n\) items by dividing it into three sublists of almost \(n / 3\) items. This algorithm finds the sublist that might contain the given item and divides it into three smaller sublists of almost equal size. The algorithm repeats this process until it finds the item or concludes that the item is not in the list. Analyze your algorithm and give the results using order notation.
Write a divide-and-conquer algorithm for the Towers of Hanoi problem. The Towers of Hanoi problem consists of three pegs and \(n\) disks of different sizes. The object is to move the disks that are stacked, in decreasing order of their size, on one of the three pegs to a new peg using the third one as a temporary peg. The problem should be solved according to the following rules: (1) when a disk is moved, it must be placed on one of the three pegs; (2) only one disk may be moved at a time, and it must be the top disk on one of the pegs; and (3) a larger disk may never be placed on top of a smaller disk. a. Show for your algorithm that \(S(n)=2^{n}-1\). (Here \(S(n)\) denotes the number of steps (moves), given an input of \(n\) disks.) b. Prove that any other algorithm takes at least as many moves as given in part (a).
Write a recursive \(\Theta(n \lg n)\) algorithm whose parameters are three integers \(x, n,\) and \(p,\) and which computes the remainder when \(x^{n}\) is divided by \(p\) For simplicity, you may assume that \(n\) is a power of \(2-\) that is, that \(n=2^{k}\) for some positive integer \(k\)
Use Binary Search, Recursion (Algorithm 2.1) to search for the integer 120 in the following list (array) of integers. Show the actions step by step. \(\begin{array}{lllllllll}12 & 34 & 37 & 45 & 57 & 82 & 99 & 120 & 134\end{array}\)
What do you think about this solution?
We value your feedback to improve our textbook solutions.