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
Hire a Tutor
AI Study Help
New
Search
Search
Sign In
Register
study help
computer science
introduction to algorithms
Questions and Answers of
Introduction to Algorithms
The P-MATRIX-MULTIPLY-RECURSIVE procedure has the disadvantage that it must allocate a temporary matrix T of size n × n, which can adversely affect the constants hidden
Suppose that both f and f′ are flows in a network G and we compute flow f ↑ f′. Does the augmented flow satisfy the flow conservation property? Does it satisfy the capacity constraint?
Suppose that we redefine the residual network to disallow edges into s. Argue that the procedure FORD-FULKERSON still correctly computes a maximum flow.
Show that we could change line 6 of INITIALIZE-PREFLOW to without affecting the correctness or asymptotic performance of the generic push relabel algorithm. 6 s.h = |G.V|– 2
Suppose that, in addition to edge capacities, a flow network has vertex capacities. That is each vertex ν has a limit l(ν) on how much flow can pass through ν. Show how to transform a flow network
For how many processors do the two versions of the chess programs run equally fast, assuming that TP = T1/P + T ∞?
Suppose that we replace the parallel for loop in line 3 of P-TRANSPOSE (see Exercise 27.1-7) with an ordinary for loop. Analyze the work, span, and parallelism of the resulting algorithm.
Consider the following multithreaded pseudocode for transposing an n à n matrix A in place:Analyze the work, span, and parallelism of this algorithm. P-TRANSPOSE(A) 1 n = A.rows 2
Give pseudocode for an efficient multithreaded implementation of the Floyd-Warshall algorithm (see Section 25.2), which computes shortest paths between all pairs of vertices in an edge-weighted
Give a multithreaded algorithm to multiply an n × n matrix by an n-vector that achieves Θ( n2/ lg n) parallelism while maintaining Θ(n2) work.
Give pseudocode for an efficient multithreaded algorithm that transposes an n × n matrix in place by using divide-and-conquer to divide the matrix recursively into four n/2 × n/2 submatrices.
Professor Karan measures her deterministic multi-threaded algorithm on 4, 10, and 64 processors of an ideal parallel computer using a greedy scheduler. She claims that the three runs yielded T4= 80
Give pseudocode for an efficient multithreaded algorithm that multiplies a p × q matrix by a q × r matrix. Your algorithm should be highly parallel even if any of p, q, and r are 1. Analyze your
Give pseudocode for a multithreaded algorithm that multiplies two n × n matrices with work Θ(n3) but span only Θ(lg n). Analyze your algorithm.
Professor Kelp decides to write a procedure that produces at random any permutation besides the identity permutation. He proposes the following procedure:PERMUTE-WITHOUT-IDENTITY (A)1. N = A.length2.
Using the master method in Section 4.5, you can show that the solution to the recurrence T (n) = 4T (n/3) + n is T (n) = Θ(nlog3 4). Show that a substitution proof with the assumption T
Use the following ideas to develop a nonrecursive, linear-time algorithm for the maximum-subarray problem. Start at the left end of the array, and progress toward the right, keeping track of the
Suppose we change the definition of the maximum-subarray problem to allow the result to be an empty subarray, where the sum of the values of an empty subarray is 0. How would you change any of the
What is the largest k such that if you can multiply 3 × 3 matrices using k multiplications (not assuming commutativity of multiplication), then you can multiply n × n matrices in time o(nlg 7)?
Give asymptotic upper an= lower bounds for T (n) in each of the following recurrences. Assume that T (n) is constant for sufficiently small n. Make your bounds as tight as possible, and justify your
Professor Caesar wishes to develop a matrix-multiplication algorithm that is asymptotically faster than Strassen’s algorithm. His algorithm will use the divide and-conquer method, dividing each
Write pseudocode for Strassen’s algorithm.
Give asymptotic upper and lower bounds for T (n) in each of the following recurrences. Assume that T (n) is constant for n ≤ 2. Make your bounds as tight as possible, and justify your
Show that the solution of T(n) = T(n – 1) + n is O(n2).
Write pseudocode for the brute-force method of solving the maximum-subarray problem. Your procedure should run in Θ(n2) time.
What does FIND-MAXIMUM-SUBARRAY return when all elements of A are negative?
What values are returned during the following sequence of queue operations, if executed on an initially empty queue? enqueue(5), enqueue(3), dequeue(), enqueue(2), enqueue(8), dequeue(), dequeue(),
What values are returned during the following series of stack operations, if executed upon an initially empty stack? push(5), push(3), pop(), push(2), push(8), pop(), pop(), push(9), push(1), pop(),
Had the stack of the previous problem been an instance of the ArrayStack class, from Code Fragment 6.2, what would be the final value of the instance variable t?
Suppose an initially empty stack S has performed a total of 25 push operations, 12 top operations, and 10 pop operations, 3 of which returned null to indicate an empty stack. What is the current size
What is the running time of parenthesize(T, T.root( )), as given in Code Fragment 8.26, for a tree T with n nodes?Fragment 8.26 1 /** Prints parenthesized representation of subtree of T rooted at p.
In the merge-sort tree shown in Figures 12.2 through 12.4, some edges are drawn as arrows. What is the meaning of a downward arrow? How about an upward arrow?Figures 12.2Figures 12.4 85 24 45 17 31
Repeat Exercise R-14.28 for Figure 14.8 that illustrates a directed DFS traversal.Repeat ExerciseDescribe the meaning of the graphical conventions used in Figure 14.9 illustrating a DFS traversal.
Repeat Exercise R-14.28 for Figure 14.10 that illustrates a BFS traversal.Repeat ExerciseDescribe the meaning of the graphical conventions used in Figure 14.9 illustrating a DFS traversal. What do
Repeat Exercise R-14.28 for Figure 14.13 that illustrates the topological sorting algorithm.Repeat ExerciseDescribe the meaning of the graphical conventions used in Figure 14.9 illustrating a DFS
NASA wants to link n stations spread over the country using communication channels. Each pair of stations has a different bandwidth available, which is known a priori. NASA wants to select n−1
Repeat the previous problem, considering the case in which ys children start with different heights.Previous problemConsider a deletion operation in an AVL tree that triggers a trinode
The rules for a deletion in an AVL tree specifically require that when the two subtrees of the node denoted as y have equal height, child x should be chosen to be aligned with
An alternative way of performing a split at a node w in a (2,4) tree is to partition w into w′ and w′′, with w′ being a 2-node and w′′ a 3-node. Which of the keys k1, k2, k3, or k4 do we
Dr. Amongus claims that a (2,4) tree storing a set of entries will always have the same structure, regardless of the order in which the entries are inserted. Show that he is wrong.
Consider a tree T storing 100,000 entries. What is the worst-case height of T in the following cases?a. T is a binary search tree.b. T is an AVL tree.c. T is a splay tree.d. T is a (2,4) tree.e. T is
Give a proof of Proposition 11.9Proposition 11.9The insertion of an entry in a red-black tree storing n entries can be done in O(logn) time and requires O(logn) recolorings and at most one trinode
Can we use a splay tree to sort n comparable elements in O(nlogn) time in the worst case? Why or why not?
For a key k that is not found in binary search tree T, prove that both the greatest key less than k and the least key greater than k lie on the path traced by the search for k.
Suppose we wish to support a new method countRange(k1, k2) that determines how many keys of a sorted map fall in the specified range. We could clearly implement this in O(s + h) time by adapting our
If the approach described in the previous problem were implemented as part of the TreeMap class, what additionalmodifications (if any) would be necessary to a subclass such as AVLTreeMap in order to
If the approach described in the previous problem were implemented as part of the TreeMap class, what additional modifications (if any) would be necessary to a subclass such as AVLTreeMap in order to
Let T and U be (2,4) trees storing n and m entries, respectively, such that all the entries in T have keys less than the keys of all the entries in U. Describe an O(logn+logm)-time method for joining
The boolean indicator used to mark nodes in a red-black tree as being “red” or “black” is not strictly needed when we have distinct keys. Describe a scheme for implementing a red-black tree
Show that the nodes of any AVL tree T can be colored “red” and “black” so that T becomes a red-black tree.
Give a complete justification of Proposition 12.1.
Is our array-based implementation of merge-sort given in Section 12.1.2 stable? Explain why or why not.
Is our linked-list-based implementation of merge-sort (Code Fragment 12.3) stable? Explain why or why not. /** Merge contents of sorted queues S1 and S2 into empty queue S. */ public static void
Suppose we are given two n-element sorted sequences A and B each with distinct elements, but potentially some elements that are in both sequences. Describe an O(n)-time method for computing a
Suppose we modify the deterministic version of the quick-sort algorithm so that, instead of selecting the last element in an n-element sequence as the pivot, we choose the element at index ⌊n/2⌋.
Consider a modification of the deterministic version of the quick-sort algorithm where we choose the element at index ⌊n/2⌋ as our pivot. Describe the kind of sequence that would cause this
Suppose the method quickSortInPlace is executed on a sequence with duplicate elements. Prove that the algorithm still correctly sorts the input sequence. What happens in the partition step when there
If the outermost while loop of our implementation of quickSortInPlace (line 9 of Code Fragment 12.6) were changed to use condition left < right, instead of condition left <= right, there would
If the conditional at line 14 of our quickSortInPlace implementation of Code Fragment 12.6 were changed to use condition left < right, instead of condition left <= right, there would be a flaw.
Following our analysis of randomized quick-sort in Section 12.2.1, show that the probability that a given input element x belongs to more than 2logn subproblems in size group i is at most 1/n2.
Of the n! possible inputs to a given comparison-based sorting algorithm, what is the absolute maximum number of inputs that could be correctly sorted with just n comparisons?
Jonathan has a comparison-based sorting algorithm that sorts the first k elements of a sequence of size n in O(n) time. Give a big-Oh characterization of the biggest that k can be.
Is the bucket-sort algorithm in-place? Why or why not?
Describe a radix-sortmethod for lexicographically sorting a sequence S of triplets (k, l,m), where k, l, and m are integers in the range [0,N −1], for N ≥ 2. How could this scheme be extended to
Suppose S is a sequence of n values, each equal to 0 or 1. How long will it take to sort S with the merge-sort algorithm? What about quick-sort?
Suppose S is a sequence of n values, each equal to 0 or 1. How long will it take to sort S stably with the bucket-sort algorithm?
Given a sequence S of n values, each equal to 0 or 1, describe an in-place method for sorting S.
Give an example input that requires merge-sort and heap-sort to take O(nlogn) time to sort, but insertion-sort runs in O(n) time. What if you reverse this list?
Describe and analyze an efficient method for removing all duplicates from a collection A of n elements.
Consider a version of deterministic quick-sort where we pick as our pivot the median of the d last elements in the input sequence of n elements, for a fixed, constant odd number d ≥ 3. What is the
Another way to analyze randomized quick-sort is to use a recurrence equation. In this case, we let T(n) denote the expected running time of randomized quicksort, and we observe that, because of the
Suppose we are given an n-element sequence S such that each element in S represents a different vote for president, where each vote is given as an integer representing a particular candidate, yet the
Consider the voting problem from Exercise C-12.35, but now suppose that we know the number k < n of candidates running, even though the integer IDs for those candidates can be arbitrarily large.
Given an array A of n integers in the range [0,n2−1], describe a simple method for sorting A in O(n) time.
Given a sequence S of n elements, on which a total order relation is defined, describe an efficient method for determining whether there are two equal elements in S. What is the running time of your
Let S be a random permutation of n distinct integers. Argue that the expected running time of insertion-sort on S is Ω(n2).
Given two sets A and B represented as sorted sequences, describe an efficient algorithm for computing A⊕B, which is the set of elements that are in A or B, but not in both.
Bob has a set A of n nuts and a set B of n bolts, such that each nut in A has a unique matching bolt in B. Unfortunately, the nuts in A all look the same, and the bolts in B all look the same as
Show that randomized quick-sort runs in O(nlogn) time with probability at least 1−1/n, that is, with high probability, by answering the following:a. For each input element x, define Ci, j(x) to be
List the prefixes of the string P ="aaabbaaa" that are also suffixes of P.
What is the longest (proper) prefix of the string "cgtacgttcgtacg" that is also a suffix of this string?
In Figure 13.14, we illustrate that GTTTAA is a longest common subsequence for the given strings X and Y. However, that answer is not unique. Give another common subsequence of X and Y having length
Describe an example of a text T of length n and a pattern P of length m such that the brute-force pattern-matching algorithm achieves a running time that is Ω(nm).
Give a justification of why the computeFailKMP method (Code Fragment 13.4) runs in O(m) time on a pattern of length m. 1 private static int[] computeFailKMP(char[ ] pattern) { int m = pattern.length;
Let T be a text of length n, and let P be a pattern of length m. Describe an O(n+ m)-time method for finding the longest prefix of P that is a substring of T.
Say that a pattern P of length m is a circular substring of a text T of length n > m if P is a (normal) substring of T, or if P is equal to the concatenation of a suffix of T and a prefix of T,
Give an efficient algorithm for deleting a string from a standard trie and analyze its running time.
Describe an efficient greedy algorithm for making change for a specified value using a minimum number of coins, assuming there are four denominations of coins (called quarters, dimes, nickels, and
Give an example set of denominations of coins so that a greedy change-making algorithm will not use the minimum number of coins.
In the art gallery guarding problem we are given a line L that represents a long hallway in an art gallery. We are also given a set X = {x0,x1, . . . ,xn−1} of real numbers that specify the
A native Australian named Anatjari wishes to cross a desert carrying only a single water bottle. He has a map that marks all the watering holes along the way. Assuming he can walk k miles on one
If G is a simple undirected graph with 12 vertices and 3 connected components, what is the largest number of edges it might have?
Draw a simple, connected, directed graph with 8 vertices and 16 edges such that the in-degree and out-degree of each vertex is 2. Show that there is a single (nonsimple) cycle that includes all the
Suppose we represent a graph G having n vertices and m edges with the edge list structure. Why, in this case, does the insertVertex method run in O(1) time while the removeVertex method runs in O(m)
Would you use the adjacency matrix structure or the adjacency list structure in each of the following cases? Justify your choice.a. The graph has 10,000 vertices and 20,000 edges, and it is important
A simple undirected graph is complete if it contains an edge between every pair of distinct vertices. What does a depth-first search tree of a complete graph look like?
Recalling the definition of a complete graph from Exercise R-14.14, what does a breadth-first search tree of a complete graph look like?
Draw the transitive closure of the directed graph shown in Figure 14.2. SW 45 BOS ORD JFK SFO UA 120 AA 1387 DFW LAX AA 49 AA 523 AA 411 MIA UA 877 DL 335 NW 35, AA 903 DL 247
Let G be an undirected graph whose vertices are the integers 1 through 8, and let the adjacent vertices of each vertex be given by the table below:vertex
Bob loves foreign languages and wants to plan his course schedule for the following years. He is interested in the following nine language courses: LA15, LA16, LA22, LA31, LA32, LA126, LA127, LA141,
Showing 1200 - 1300
of 1549
First
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16