New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
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
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
introduction to algorithms
Data Structures and Algorithms in Java 6th edition Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser - Solutions
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 by the ‚-notation. The P-MATRIX-MULTIPLY-RECURSIVE procedure does have high
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 G = (V, E) with vertex capacities into an equivalent flow network G′
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 parallel for j = 2 to n parallel for i = 1 to j – 1 exchange a;; with a;; 3 4
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 graph. Analyze your algorithm.
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. Analyze your algorithm.
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 seconds, T10= 42 seconds, and T64= 10 seconds. Argue that the professor is either lying or
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 algorithm.
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. For i = 1 to n – 13. Swap A[i] with A[RANDOM (i + 1, n)]Does this code do what Professor Kelp
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 (n) ≤ cnlog3 4 fails( Then show how to subtract off a lower-order term to make a
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 maximum subarray seen so far. Knowing a maximum subarray of A[1 . . j], extend the answer to find a
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 algorithms that do not allow empty subarrays to permit an empty subarray to be the result?
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)? What would the running time of this algorithm be?
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 answers.a. T (n) = 3T (n/2) + n lg nb. T (n) = 4T (n/2) + n2√n.c. T (n) = 2T (n/2) + n/ lg n.d. T
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 matrix into pieces of size n/4 × n/4, and the divide and combine steps together will take
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 answers.a. T (n) = 2T (n/2) + n4.b. T (n) = T
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(), enqueue(9), enqueue(1), dequeue(), enqueue(7), enqueue(6), dequeue(), dequeue(), enqueue(4),
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(), push(7), push(6), pop(), pop(), push(4), pop(), 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 of S?
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. */ 2 public static void parenthesize(Tree T, Position p) { 3 System.out.print(p.getElement()); 4 if
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 96 50 17 31 96 50 85 24 45 (a) (b) 17 31 96 50 17 31 96 50 63 45 63 45 85 24 24 (c) (d) 17 31 96 50
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. What do the line thicknesses signify? What do the arrows signify? How about dashed lines? BOS BOS ORD
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 the line thicknesses signify? What do the arrows signify? How about dashed lines? B (D в н Н (N (м
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 traversal. What do the line thicknesses signify? What do the arrows signify? How about dashed lines? 11
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 channels (the minimum possible) in such a way that all the stations are linked by the channels and the
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 restructuring for the case in which both children of the node denoted as y have equal heights. Give a
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 y (so that x and y are both left children or both right children). To better understand this
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 store at w’s parent? Why?
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 a red-black tree.
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 restructuring.
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 approach to subMap. Describe how to modify the search-tree structure to support O(h) worst-case time
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 maintain support for the new method?
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 accurately maintain the reference to the leftmost position?
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 T and U into a single tree that stores all the entries in T and U.
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 without adding any extra space to standard binary search-tree nodes.
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 merge(Queue S1, Queue S2, Queue S, Comparator comp) { 3 while (!S1.isEmpty() && !S2.isEmpty()) { if
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 sequence representing the union A∪B (with no duplicates) as a sorted sequence.
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⌋. What is the running time of this version of quick-sort on a sequence that is already sorted?
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 version of quick-sort to run in Ω(n2) time.
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 are elements equal to the pivot? What is the running time of the algorithm if all the input
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 be a flaw. Explain the flaw and give a specific input sequence on which such an implementation
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. Explain the flaw and give a specific input sequence on which such an implementation fails. /** Sort
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 sequences of d-tuples (k1, k2, . . . , kd), where each ki is an integer in the range [0,N−1]?
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 asymptotic worst-case running time of quick-sort in this case?
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 worst-case partitions for good and bad splits, we can writewhere bn is the time needed to partition a
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 integers may be arbitrarily large (even if the number of candidates is not). Design an
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. Describe an O(nlogk)-time algorithm for determining who wins the election.In ExerciseSuppose we are
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 method?
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 well. The only kind of a comparison that Bob can make is to take a nut-bolt pair (a,b), such that a is
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 a 0/1 random variable that is 1 if and only if element x is in j+1 subproblems that have size s such
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 six. 0 12 3 4 5678 0000000000 0 000 10011 1 1111 1111 00112 2 2 2 2 2 3001|122 9 10 11 12 2 2 2 2 3
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; int[ ] fail = new int[m]; int j = 1; 2 // by default, all overlaps are zero 3 4 int k = 0; while (j
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, that is, if there is an index 0 ≤ k < m, such that P = T[n−m+k..n−1]+T[0..k−1]. Give an
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 pennies), with values 25, 10, 5, and 1, respectively. Argue why your algorithm is correct.
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 positions of paintings in this hallway. Suppose that a single guard can protect all the paintings within
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 bottle of water, design an efficient algorithm for determining where Anatjari should refill his bottle
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 edges of your graph, that is, you can trace all the edges in their respective directions without ever
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) time?
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 to use as little space as possible.b. The graph has 10,000 vertices and 20,000,000 edges, and it is
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 adjacent vertices1................................................(2, 3,
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, and LA169. The course prerequisites are:• LA15: (none)• LA16: LA15• LA22: (none)• LA31:
Showing 1200 - 1300
of 1549
First
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Step by Step Answers