All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Ask a Question
Search
Search
Sign In
Register
study help
computer science
introduction to algorithms
Questions and Answers of
Introduction to Algorithms
Show that RANDOMIZED-QUICKSORT's expected running time is Ω(n lg n).
Banks often record transactions on an account in order of the times of the transactions, but many people like to receive their bank statements with checks listed in order by check number. People
How would you modify QUICK SORT to sort into non increasing order?
Show that the expression q2 + (n - q – 1)2 achieves a maximum over q = 0, 1, . . . , n - 1 when q = 0 or q = n - 1.
Give a brief argument that the running time of PARTITION on a subarray of size n is Θ(n).
An alternative analysis of the running time of randomized quicksort focuses on the expected running time of each individual recursive call to RANDOMIZED-QUICKSORT, rather than on the number of
When RANDOMIZED-QUICKSORT runs, how many calls are made to the random number generator RANDOM in the worst case? How about in the best case? Give your answer in terms of Θ-notation.
What is the running time of QUICKSORT when all elements of array A have the same value?
What value of q does PARTITION return when all elements in the array A[p . . r] have the same value? Modify PARTITION so that q = ⌊(p + r) = 2⌋ when all elements in the array A[p . . r] have the
The version of PARTITION given in this chapter is not the original partitioning algorithm. Here is the original partition algorithm, which is due to C. A. R. Hoare: HOARE-PARTITION (A, p,
Show that in the recurrence T(n) max (T(q) +T(n – q – 1))+ O(n) , 0
Why do we analyze the expected running time of a randomized algorithm and not its worst-case running time?
Using Figure 7.1 as a model, illustrate the operation of PARTITION on the array A = ?13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11?. Figure 7.1 i pj 2 871 3564 (a) p,i j 28713 5 6 4 (b) p.i 28 71 356 4
Give an O(n lg k)-time algorithm to merge k sorted lists into one sorted list, where n is the total number of elements in all the input lists. Use a min heap for k-way merging.
The operation HEAP-DELETE (A, i) deletes the item in node i from heap A. Give an implementation of HEAP-DELETE that runs in O(lg n) time for an n-element max-heap.
Write pseudocode for the procedures HEAP-MINIMUM, HEAP-EXTRACT-MIN, HEAP-DECREASE-KEY, and MIN-HEAP-INSERT that implement a min-priority queue with a min-heap.
Argue the correctness of HEAPSORT using the following loop invariant:At the start of each iteration of the for loop of lines 2–5, the subarray A[1. . i] is a max-heap containing the i smallest
This problem examines three algorithms for searching for a value x in an unsorted array A consisting of n elements.Consider the following randomized strategy: pick a random index i into A. If A[i] =
An m ? n array A of real numbers is a Monge array if for all i, j, k, and l such that 1 ? i In other words, whenever we pick two rows and two columns of a Monge array and consider the four
Show that, with the array representation for storing an n-element heap, the leaves are the nodes indexed by ⌊n/2⌋ + 1, ⌊n/2⌋ + 2, . . . ,n.
Show how to implement a first-in, first-out queue with a priority queue. Show how to implement a stack with a priority queue.
Is the array with values 〈23, 17, 14, 6, 13, 10, 1, 5, 7, 12〉 a max-heap?
The code for MAX-HEAPIFY is quite efficient in terms of constant factors, except possibly for the recursive call in line 10, which might cause some compilers to produce inefficient code. Write an
Is an array that is in sorted order a min-heap?
Argue the correctness of HEAP-INCREASE-KEY using the following loop invariant:At the start of each iteration of the while loop of lines 4-6, the subarray A[1 . .A.heap-size] satisfies the
Show that when all elements are distinct, the best-case running time of HEAPSORT is Ω(n lg n).
What is the effect of calling MAX-HEAPIFY (A, i) for i > A.heap-size/2?
Where in a max-heap might the smallest element reside, assuming that all elements are distinct?
Why do we bother setting the key of the inserted node to – ∞ in line 2 of MAXHEAP-INSERT when the next thing we do is increase its key to the desired value?
Show that the worst-case running time of HEAPSORT is Ω(n lg n).
What is the effect of calling MAX-HEAPIFY (A, i) when the element A[i] is larger than its children?
An m × n Young tableau is an m × n matrix such that the entries of each row are in sorted order from left to right and the entries of each column are in sorted order from top to bottom. Some of the
What is the running time of HEAPSORT on an array A of length n that is already sorted in increasing order? What about decreasing order?
Starting with the procedure MAX-HEAPIFY, write pseudocode for the procedure MIN-HEAPIFY (A, i), which performs the corresponding manipulation on a min-heap. How does the running time of MIN-HEAPIFY
Why do we want the loop index i in line 2 of BUILD-MAX-HEAP to decrease from ⌊A.length/2⌋ to 1 rather than increase from 1 to ⌊A.length/2⌋?
Using Figure 6.2 as a model, illustrate the operation of MAX-HEAPIFY (A, 3) on the array A = ?27, 17, 3, 16, 13, 10, 1, 5, 7, 12, 4 8, 9, 0?. Figure 6.2 16 16 3 2 3 10 14 10 4 5 6. 5 6. 14 9. 3. 9
Illustrate the operation of HEAP-EXTRACT-MAX on the heap A = 〈15, 13, 9, 5, 12, 8, 7, 4, 0, 6, 2, 1〉.
Using Figure 6.3 as a model, illustrate the operation of BUILD-MAX-HEAP on the array A = ?5, 3, 17, 10, 84, 19, 6, 22, 9?. Figure 6.3 A 4132 9 10 14 8 7 i(16 10 16 10 8 10 8 9 10 14 14 (b) 3 10 4 5
Sharpen the lower bound on streak length by showing that in n flips of a fair coin, the probability is less than 1/n that no streak longer than lg n – 2 lg lg n consecutive heads occurs.
What is the probability that a k-string over a set of size n forms a k-permutation? How does this question relate to the birthday paradox?
Prove that in the array P in procedure PERMUTE-BY-SORTING, the probability that all elements are unique is at least 1 – 1/n.
How many people should be invited to a party in order to make it likely that there are three people with the same birthday?
Use indicator random variables to compute the expected value of the sum of n dice.
For the analysis of the birthday paradox, is it important that the birthdays be mutually independent, or is pairwise independence sufficient? Justify your answer.
Describe an implementation of the procedure RANDOM (a, b) that only makes calls to RANDOM (0, 1). What is the expected running time of your procedure, as a function of a and b?
Suppose that we toss balls into b bins until some bin contains two balls. Each toss is independent, and each ball is equally likely to end up in any bin. What is the expected number of ball tosses?
Show that the assumption that we are always able to determine which candidate is best, in line 4 of procedure HIRE-ASSISTANT, implies that we know a total order on the ranks of the candidates.
How many people must there be in a room before the probability that someone has the same birthday as you do is at least 1/2? How many people must there be before the probability that at least two
Solve the recurrence T (n) = 3T (√n) + log n by making a change of variables. Your solution should be asymptotically tight. Do not worry about whether values are integral.
Use a recursion tree to give an asymptotically tight solution to the recurrence T (n) = T (n- a) + T (a) + cn, where a ≥ 1 and c > 0 are constants.
Draw the recursion tree for T (n) = 4T (⌊n/2⌋) + cn, where c is a constant, and provide a tight asymptotic bound on its solution. Verify your bound by the substitution method.
Show how to multiply the complex numbers a + bi and c + di using only three multiplications of real numbers. The algorithm should take a, b, c, and d as input and produce the real component ac - bd
Show that the solution to T (n) = 2T (⌊n/2 ⌋ + 17 n is O(n lg n).
How quickly can you multiply a kn × n matrix by an n × kn matrix, using Strassen’s algorithm as a subroutine? Answer the same question with the order of the input matrices reversed.
Use a recursion tree to determine a good asymptotic upper bound on the recurrence T (n) = T (n – 1) + T (n/2) + n. Use the substitution method to verify your answer.
Professor Diogenes has n supposedly identical integrated-circuit chips that in principle are capable of testing each other. The professor?s test jig accommodates two chips at a time. When the jig is
Consider the regularity condition af (n/b) ≤ cf (n) for some constant c < 1, which is part of case 3 of the master theorem. Give an example of constants a ≥ 1 and b > 1 and a function f (n)
Consider linear search again (see Exercise 2.1-3). How many elements of the input sequence need to be checked on the average, assuming that the element being searched for is equally likely to be any
Prove that o(g (n)) ∩ ω(g (n)) is the empty set.
Some authors define ? in a slightly different way than we do; let?s use ??(read ?omega infinity?) for this alternative definition. We say that f (n) = ?? (g(n)) if there exists a positive constant c
The following code fragment implements Horner?s rule for evaluating a polynomial The following code fragment implements Horner?s rule for evaluating a polynomial given the coefficients a0, a1??.,an
V. Pan has discovered a way of multiplying 68 × 68 matrices using 132,464 multiplications, a way of multiplying 70 × 70 matrices using 143,640 multiplications, and a way of multiplying 72 × 72
Use a recursion tree to determine a good asymptotic upper bound on the recurrence T (n) = 2T (n – 1) + 1. Use the substitution method to verify your answer.
Show that by making a different inductive hypothesis, we can overcome the difficulty with the boundary condition T(1) = 1 for recurrence (4.19) without adjusting the boundary conditions for the
This problem develops properties of the Fibonacci numbers, which are defined by recurrence (3.22). We shall use the technique of generating functions to solve the Fibonacci recurrence. Define the
Can the master method be applied to the recurrence T (n) = 4T (n/2) + n2 lg n? Why or why not? Give an asymptotic upper bound for this recurrence.
Use a recursion tree to determine a good asymptotic upper bound on the recurrence T (n) = 4T (n/2 + 2) + n. Use the substitution method to verify your answer.
We saw that the solution of T(n) = 2T (⌊n/2⌋ + n is O(n lg n). Show that the solution of this recurrence is also Ω(n lg n). Conclude that the solution is Θ(n lg n).
Implement both the brute-force and recursive algorithms for the maximum subarray problem on your own computer. What problem size n0 gives the crossover point at which the recursive algorithm beats
Show that case 3 of the master theorem is overstated, in the sense that the regularity condition af (n/b) ≤ cf (n) for some constant c < 1 implies that there exists a constant ∈ > 0 such
How would you modify Strassen’s algorithm to multiply n × n matrices in which n is not an exact power of 2? Show that the resulting algorithm runs in time Θ(nlg 7).
Use a recursion tree to determine a good asymptotic upper bound on the recurrence T (n) = T (n/2) + n2. Use the substitution method to verify your answer.
Show that the solution of T(n) = T(⌈n=2⌉) + 1 is O(lg n).
Show that if f (n) = Θ(nlogb a lgk n), where k ≥ 0, then the master recurrence has solution T (n) = Θ(nlogb a lgk + 1 n). For simplicity,
Throughout this book, we assume that parameter passing during procedure calls takes constant time, even if an N-element array is being passed. This assumption is valid in most systems because a
Use a recursion tree to determine a good asymptotic upper bound on the recurrence T (n) = 3T (⌊n/2⌋) + n. Use the substitution method to verify your answer.
Give a simple and exact expression for nj in equation (4.27) for the case in which b is a positive integer instead of an arbitrary real number. (4.27) if j = 0, Inj-1/b] if j > 0. n n j
Use the master method to give tight asymptotic bounds for the following recurrences.a. T (n) = 2T (n/4) + 1.b. T (n) = 2T (n/4) + √nc. T (n) = 2T (n/4) + nd. T (n) = 2T (n/4) + n2
Use Strassen?s algorithm to compute the matrix product Show your work. 1 3 7 5 6 8 4 2
Show that k ln k = Θ(n) implies k = Θ(n/ ln n).
Prove by induction that the i th Fibonacci number satisfies the equality where ? is the golden ratio and ?? is its conjugate. F; V5
Show that the golden ratio ϕ and its conjugate ϕ̂ both satisfy the equation x2 = x + 1.
Prove that the running time of an algorithm is Θ(g (n)) if and only if its worst-case running time is O(g (n)) and its best-case running time is Ω(g (n)).
We can apply the iteration operator ? used in the lg? function to any monotonically increasing function f (n) over the reals. For a given constant c ? ?, we define the iterated function f*c by which
Which is asymptotically larger: lg(lg∗n) or lg∗(lg n)?
Let f (n) an= g(n) be asymptotically positive functions. Prove or disprove each of the following conjectures.a. f (n) = O(g(n)) implies g(n) = O(f (n)).b. f (n) + g(n) = Θ(min(f (n), g(n))).c. f (n)
Prove equation (3.19). Also prove that n! = ?(2n)?and?n!?=?o(nn). Equation (3.19) (2") Ig(n!) O(n lg n) , || || ||" style="" class="fr-fic fr-dib"> п! о (п"), n! >(2") Ig(n!) O(n lg n) , || ||
Indicate, for each pair of expressions (A, B) in the table below, whether A is O, o, ? , ?, or ? of B. Assume that k ? 1, ? > 0, and c > 1 are constants. Your answer should be in the form of
Show that if f (n) and g(n) are monotonically increasing functions, then so are the functions f (n) + g(n) and f (g(n)), and if f (n) and g(n) are in addition nonnegative, then f (n) · g(n) is
Consider the problem of adding two n-bit binary integers, stored in two n-element arrays A and B. The sum of the two integers should be stored in binary form in an (n + 1)-element array C. State the
Consider the searching problem:Input: A sequence of n numbers A = 〈a1, a2,......,an〉 and a value ν.Output: An index i such that ν = A[i] or the special value NIL if ν does not appear in
Using Figure 2.4 as a model, illustrate the operation of merge sort on the array A = (3; 41; 52; 26; 38; 57; 9; 49).Figure 2.4 5 2 2 5 10 merge 2 1 4 2 5 merge 4 4 2 7 sorted sequence 3 4 7 merge
Express the function n3/1000 – 100n2 – 100n + 3 in terms of Θ-notation.
Using Figure 2.2 as a model, illustrate the operation of INSERTION-SORT on the array A = ?31, 41, 59, 26, 41, 58?. Figure 2.2 4 5 6 1 2 3 4 5 6 4 6 1 1 2 3 4 5 6 1 2 3 (a) 2 4 6. 1 3 (b) 2 |5 3 (c)
Come up with a real-world problem in which only the best solution will do. Then come up with one in which a solution that is “approximately” the best is good enough.
How are the shortest-path and traveling-salesman problems given above similar? How are they different?
What is the smallest value of n such that an algorithm whose running time is 100n2 runs faster than an algorithm whose running time is 2n on the same machine?
Select a data structure that you have seen previously, and discuss its strengths and limitations.
Suppose we are comparing implementations of insertion sort and merge sort on the same machine. For inputs of size n, insertion sort runs in 8n2 steps, while merge sort runs in 64n lg n steps. For
Other than speed, what other measures of efficiency might one use in a real-world setting?
Showing 1000 - 1100
of 1549
First
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16