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
Introduction to Algorithms 3rd edition Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest - Solutions
For each function f (n) and time t in the following table, determine the largest size n of a problem that can be solved in time t, assuming that the algorithm to solve the problem takes f (n) microseconds. 1 1 1 second minute hour day month year century lgn n lg n n? n3 2" n!
Give an example of an application that requires algorithmic content at the application level, and discuss the function of the algorithms involved.
Give a real-world example that requires sorting or a real-world example that requires computing a convex hull.
Given two strings a = a0a1 . . .ap and b = b0b1 . . .bq, where each ai and each bj is in some ordered set of characters, we say that string a is lexicographically less than string b if either 1. there exists an integer j, where 0 ≤ j ≤ min(p, q), such
Suppose that we are given a directed acyclic graph G = (V, E) with real-valued edge weights and two distinguished vertices s and t. Describe a dynamic-programming approach for finding a longest weighted simple path from s to t. What does the subproblem graph look like? What is the efficiency of
Give a sequence of m MAKE-SET, UNION, and FIND-SET operations, n of which are MAKE-SET operations, that takes Ω(m lg n) time when we use union by rank only.
Suppose that we wish to add the operation PRINT-SET(x), which is given a node x and prints all the members of x’s set, in any order. Show how we can add just a single attribute to each node in a disjoint-set forest so that PRINT-SET(x) takes time linear in the number of members of x’s set and
There are two types of professional wrestlers: "babyfaces" ("good guys") and "heels" ("bad guys"). Between any pair of professional wrestlers, there may or may not be a rivalry. Suppose we have n professional wrestlers and we have a list of r pairs of wrestlers for which there are rivalries. Give
Show that edge (u, ν) isa. a tree edge or forward edge if and only if u.d < ν.d < ν.f < u.f,b. a back edge if and only if ν.d ≤ u.d < u.f ≤ ν.f, andc. a cross edge if and only if ν.d < ν.f < u.d < u.f.
Professor Newman thinks that he has worked out a simpler proof of correctness for Dijkstra’s algorithm. He claims that Dijkstra’s algorithm relaxes the edges of every shortest path in the graph in the order in which they appear on the path, and therefore the path-relaxation property applies to
Suppose that you wish to find, among all minimum cuts in a flow network G with integral capacities, one that contains the smallest number of edges. Show how to modify the capacities of G to create a new flow network G′ in which any minimum cut in G′ is a minimum cut with the smallest number of
Suppose that we have found a maximum flow in a flow network G = (V, E) using a push-relabel algorithm. Give a fast algorithm to find a minimum cut in G.
Let f be a flow in a network, and let α be a real number. The scalar flow product, denoted αf, is a function from V à V to defined byProve that the flows in a network form a convex
Suppose that a flow network G = (V, E) violates the assumption that the network contains a path s ⤳ ν ⤳ t for all vertices ν ∈ V. Let u be a vertex for which there is no path s ⤳ u ⤳ t. Show that there must exist a maximum flow f in G such that f (u, ν) = f (ν, u) = 0 for all vertices
Prove that, after the procedure INITIALIZE-PREFLOW (G, s) terminates, we have s.e ≤ − |f*|, where f* is a maximum flow for G.
Show that splitting an edge in a flow network yields an equivalent network. More formally, suppose that flow network G contains edge (u, ν), and we create a new flow network G² by creating a new vertex x and replacing (u, ν) by new edges (u, x) and (x,
Prove that the summations in equation (26.6) equal the summations in equation (26.7).(26.6)(26.7) |f ↑ f'l Συ6,) + fG, ν) - f' (ν, s)) - Σf(v, s) + f'0, s) - f'6, v)) Ξ νeV νEV Σ16) +ΣΓa)-Σ Γ0.3) νε V Ξ νεV νEVi -Σf0.) -Σ f0.) +Σrον νεV νε V νεW Σ f 8,)-Σ fv.3) Ξ
How can we use the output of the Floyd-Warshall algorithm to detect the presence of a negative-weight cycle?
What does the matrix used in the shortest-paths algorithms correspond to in regular matrix multiplication? 888 8 8 • 88
Let G = (V, E) be a weighted, directed graph with nonnegative weight function w : E → {0, 1, . . . ,W} for some nonnegative integer W. Modify Dijkstra's algorithm to compute the shortest paths from a given source vertex s in O(W V + E) time.
Let G = (V, E) be a weighted, directed graph that contains no negative-weight cycles. Let s ∈ V be the source vertex, and let G be initialized by INITIALIZE-SINGLE-SOURCE (G, s). Prove that there exists a sequence of |V| − 1 relaxation steps that produces ν.d = δ(s, ν) for all ν ∈ V.
A sequence is bitonic if it monotonically increases and then monotonically decreases, or if by a circular shift it monotonically increases and then monotonically decreases. For example the sequences 〈1, 4, 6, 8, 3, −2〉, 〈9, 2, −4, −10, −5〉, and 〈1, 2, 3, 4〉 are bitonic, but
Professor Gaedel has written a program that he claims implements Dijkstra’s algorithm. The program produces ν.d and ν.π for each vertex ν ∈ V. Give an O(V + E)-time algorithm to check the output of the professor’s program. It should determine whether the d and π attributes match those of
A scaling algorithm solves a problem by initially considering only the highest-order bit of each relevant input value (such as an edge weight). It then refines the initial solution by looking at the two highest-order bits. It progressively looks at more and more high-order bits, refining the
Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 U.S. dollar buys 49 Indian rupees, 1 Indian rupee buys 2 Japanese yen, and 1 Japanese yen buys 0.0107 U.S. dollars. Then, by
A d-dimensional box with dimensions (x1, x2, . . . ,xd) nests within another box with dimensions (y1, y2, . . . ,yd) if there exists a permutation π on {1, 2, . . . ,d} such that xπ(1) < y1, xπ(2) < y2, . . . , xπ(d) < yd.a. Argue that the nesting relation is transitive.b. Describe an
Let (u, ν) be a minimum-weight edge in a connected graph G. Show that (u, ν) belongs to some minimum spanning tree of G.
Show that we can use a depth-first search of an undirected graph G to identify the connected components of G, and that the depth-first forest contains as many trees as G has connected components. More precisely, show how to modify depth-first search so that it assigns to each vertex ν an integer
Give a counterexample to the conjecture that if a directed graph G contains a path from u to ν, then any depth-first search must result in ν.d ≤ u.f.
Give a counterexample to the conjecture that if a directed graph G contains a path from u to ν, and if u.d < ν.d in a depth-first search of G, then ν is a descendant of u in the depth-first forest produced.
The incidence matrix of a directed graph G = (V, E) with no self-loops is a |V| Ã |E| matrix B = (bij) such thatDescribe what the entries of the matrix product BBT represent, where BT is the transpose of B. -1
Most graph algorithms that take an adjacency-matrix representation as input require time Ω(V2), but there are some exceptions. Show how to determine whether a directed graph G contains a universal sink-a vertex with in-degree |V| - 1 and out-degree 0-in time O(V), given an adjacency matrix
Give an example of a directed graph G = (V, E), a source vertex s ∈ V, and a set of tree edges Eπ ⊆ E such that for each vertex ν ∈ V, the unique simple path in the graph (V, Eπ) from s to ν is a
Argue that in a breadth-first search, the value u.d assigned to a vertex u is independent of the order in which the vertices appear in each adjacency list. Using Figure 22.3 as an example, show that the breadth-first tree computed by BFS can depend on the ordering within adjacency lists.Figure
Show that using a single bit to store each vertex color suffices by arguing that the DFS procedure would produce the same result if line 3 of DFS-VISIT was removed.
Show that using a single bit to store each vertex color suffices by arguing that the BFS procedure would produce the same result if lines 5 and 14 were removed.
A depth-first forest classifies the edges of a graph into tree, back, forward, and cross edges. A breadth-first tree can also be used to classify the edges reachable from the source of the search into the same four categories.a. Prove that in a breadth-first search of an undirected graph, the
Consider the function α′(n) = min {k : Ak(1) ≥ lg(n + 1)}. Show that α′(n) ≤ 3 for all practical values of n and, using Exercise 21.4-2, show how to modify the potential-function argument to prove that we can perform a sequence
Suggest a simple change to the UNION procedure for the linked-list representation that removes the need to keep the tail pointer to the last object in each list. Whether or not the weighted-union heuristic is used, your change should not change the asymptotic running time of the UNION procedure.
Professor Dante reasons that because node ranks increase strictly along a simple path to the root, node levels must monotonically increase along the path. In other words, if x.rank > 0 and x.p is not a root, then level(x) ≤ level (x. p). Is the professor correct?
Show that any sequence of m MAKE-SET, FIND-SET, and LINK operations, where all the LINK operations appear before any of the FIND-SET operations, takes only O(m) time if we use both path compression and union by rank. What happens in the same situation if we use only the path-compression heuristic?
Professor Gompers suspects that it might be possible to keep just one pointer in each set object, rather than two (head and tail), while keeping the number of pointers in each list element at two. Show that the professor’s suspicion is well founded by describing how to represent each set by a
Using Exercise 21.4-2, give a simple proof that operations on a disjoint-set forest with union by rank but without path compression run in O(m lg n) time.Exercise 21.4-2Prove that every node has rank at most ⌊lg n⌋.
Adapt the aggregate proof of Theorem 21.1 to obtain amortized time bounds of O(1) for MAKE-SET and FIND-SET and O(lg n) for UNION using the linked-list representation and the weighted-union heuristic.
In the depth-determination problem, we maintain a forest F = {Ti} of rooted trees under three operations:MAKE-TREE (ν) creates a tree whose only node is ν.FIND-DEPTH (ν) returns the depth of node ν within its tree.GRAFT (r, ν) makes
The off-line minimum problem asks us to maintain a dynamic set T of elements from the domain {1, 2, . . . ,n} under the operations INSERT and EXTRACT-MIN.We are given a sequence S of n INSERT and m EXTRACT-MIN calls, where each key in {1, 2, . . .
Suppose we perform a sequence of n operations on a data structure in which the i th operation costs i if i is an exact power of 2, and 1 otherwise. Use aggregate analysis to determine the amortized cost per operation.
Redo Exercise 17.1-3 using an accounting method of analysis.17.1-3Suppose we perform a sequence of n operations on a data structure in which the i th operation costs i if i is an exact power of 2, and 1 otherwise. Use aggregate analysis to determine the amortized cost per operation.
Modern computers use a cache to store a small amount of data in a fast memory. Even though a program may access large amounts of data, by storing a small subset of the main memory in the cache-a small but faster memory-overall access time can greatly decrease. When a computer program executes, it
Consider a modification to the activity-selection problem in which each activity ai has, in addition to a start and finish time, a value νi. The objective is no longer to maximize the number of activities scheduled, but instead to maximize the total value of the activities scheduled. That is,
Professor Gekko has always dreamed of inline skating across North Dakota. He plans to cross the state on highway U.S. 2, which runs from Grand Forks, on the eastern border with Minnesota, to Williston, near the western border with Montana. The professor can carry two liters of water, and he can
Show that if (S, I) is a matroid, then (S, I′) is a matroid, where I′ = {A′ . S − A′ contains some maximal A ∈ I} .That is, the maximal independent sets of (S, I′) are just the complements of the maximal independent sets of (S, I).
Given an m × n matrix T over some field (such as the reals), show that (S, I) is a matroid, where S is the set of columns of T and A ∈ I if and only if the columns in A are linearly independent.
Explain why, in the proof of Lemma 16.2, if x.freq = b.freq, then we must have a.freq = b.freq = x.freq = y.freq.
Give a dynamic-programming algorithm for the activity-selection problem, based on recurrence (16.2). Have your algorithm compute the sizes c[I, j] as defined above and also produce the maximum-size subset of mutually compatible activities. Assume that the inputs have been sorted as in
Suppose that you are the general manager for a major-league baseball team. During the off-season, you need to sign some free-agent players for your team. The team owner has given you a budget of $X to spend on free agents. You are allowed to spend less than $X altogether, but the owner will fire
The Rinky Dink Company makes machines that resurface ice rinks. The demand for such products varies from month to month, and so the company needs to develop a strategy to plan its manufacturing given the fluctuating, but predictable, demand. The company wishes to design a plan for the next n
A certain string-processing language allows a programmer to break a string into two pieces. Because this operation copies the string, it costs n time units to break a string of n characters into two pieces. Suppose a programmer wants to break a string into many pieces. The order in which the breaks
We are given a color picture consisting of an m × n array A[1 . .m, 1 . . n] of pixels, where each pixel specifies a triple of red, green, and blue (RGB) intensities. Suppose that we wish to compress this picture slightly. Specifically, we wish to remove one pixel from each of the m rows, so that
Imagine that you wish to exchange one currency for another. You realize that instead of directly exchanging one currency for another, you might be better off making a series of trades through other currencies, winding up with the currency you want. Suppose that you can trade n different
Suppose that in the rod-cutting problem of Section 15.1, we also had limit li on the number of pieces of length i that we are allowed to produce, for i = 1, 2, . . . ,n. Show that the optimal-substructure property described in Section 15.1 no longer holds.
Describe the subproblem graph for matrix-chain multiplication with an input chain of length n. How many vertices does it have? How many edges does it have, and which edges are they?
In the euclidean traveling-salesman problem, we are given a set of n points in the plane, and we wish to find the shortest closed tour that connects all n points. Figure 15.11(a) shows the solution to a 7-point problem. The general problem is NP-hard, and its solution is therefore believed to
Consider a modification of the rod-cutting problem in which, in addition to a price pi for each rod, each cut incurs a fixed cost of c. The revenue associated with a solution is now the sum of the prices of the pieces minus the costs of making the cuts. Give a dynamic-programming algorithm to
A palindrome is a nonempty string over some alphabet that reads the same forward and backward. Examples of palindromes are all strings of length 1, civic, racecar, and aibohphobia (fear of palindromes).Give an efficient algorithm to find the longest palindrome that is a sub sequence of a given
Show, by means of a counterexample, that the following "greedy" strategy does not always determine an optimal way to cut rods. Define the density of a rod of length i to be pi/i, that is, its value per inch. The greedy strategy for a rod of length n cuts off a first piece of length i, where 1 ≤
Show that equation (15.4) follows from equation (15.3) and the initial condition T(0) = 1.(15.4) (1
VLSI databases commonly represent an integrated circuit as a list of rectangles. Assume that each rectangle is rectilinearly oriented (sides parallel to the x- and y-axes), so that we represent a rectangle by its minimum and maximum x and y-coordinates. Give an O(n lg n)-time algorithm to decide
Observe that whenever we reference the size attribute of a node in either OSSELECT or OS-RANK, we use it only to compute a rank. Accordingly, suppose we store in each node its rank in the subtree of which it is the root. Show how to maintain this information during insertion and deletion. (Remember
We define the Josephus problem as follows. Suppose that n people form a circle and that we are given a positive integer m ≤ n. Beginning with a designated first person, we proceed around the circle, removing every mth person. After each person is removed, counting continues around the circle that
Can we maintain the black-heights of nodes in a red-black tree as attributes in the nodes of the tree without affecting the asymptotic performance of any of the red black tree operations? Show how, or argue why not. How about maintaining the depths of nodes?
Suppose that a node x is inserted into a red-black tree with RB-INSERT and then is immediately deleted with RB-DELETE. Is the resulting red-black tree the same as the initial red-black tree? Justify your answer.
Professors Skelton and Baron are concerned that at the start of case 1 of RB-DELETE-FIXUP, the node x.p might not be black. If the professors are correct, then lines 5-6 are wrong. Show that x.p must be black at the start of case 1, so that the professors have nothing to worry about.
Professor Teach is concerned that RB-INSERT-FIXUP might set T.nil.color to RED, in which case the test in line 1 would not cause the loop to terminate when z is the root. Show that the professor’s concern is unfounded by arguing that RBINSERT- FIXUP never sets T.nil.color to RED.
During the course of an algorithm, we sometimes find that we need to maintain past versions of a dynamic set as it is updated. We call such a set persistent. One way to implement a persistent set is to copy the entire set whenever it is modified, but this approach can slow down a program and also
An alternative method of performing an in order tree walk of an n-node binary search tree finds the minimum element in the tree by calling TREE-MINIMUM and then making n - 1 calls to TREE-SUCCESSOR. Prove that this algorithm runs in Θ(n) time.
Show that the function ƒ(x) = 2x is convex.
In this problem, we prove that the average depth of a node in a randomly built binary search tree with n nodes is O(lg n). Although this result is weaker than that of Theorem 12.4, the technique we shall use reveals a surprising similarity between the building of a binary search tree and the
Describe a binary search tree on n nodes such that the average depth of a node in the tree is Θ(lg n) but the height of the tree is ω(lg n). Give an asymptotic upper bound on the height of an n-node binary search tree in which the average depth of a node is Θ(lg n).
Suppose we have stored n keys in a hash table of size m, with collisions resolved by chaining, and that we know the length of each chain, including the length L of the longest chain. Describe a procedure that selects a key uniformly at random from among the keys in the hash table and returns it in
a. Assuming uniform hashing, show that for i = 1,2, . . . ,n, the probability is at most 2-k that the i th insertion requires strictly more than k probes.b. Show that for i = 1,2, . . . ,n, the probability is O(1/n2) that the i th
Professor Olay is consulting for an oil company, which is planning a large pipeline running east to west through an oil field of n wells. The company wants to connectFigure 9.2 Professor Olay needs to determine the position of the east-west oil pipeline that minimizes the total length of the
In this problem, we use indicator random variables to analyze the RANDOMIZED SELECT procedure in a manner akin to our analysis of RANDOMIZED-QUICKSORT in Section 7.4.2.As in the quicksort analysis, we assume that all elements are distinct, and we rename the elements of the input array A as z1, z2,
Show how quicksort can be made to run in O(n lg n) time in the worst case, assuming that all elements are distinct.
A compare-exchange operation on two array elements A[i] and A[j], where i < j, has the form COMPARE-EXCHANGE (A, i, j)1 If A[i] > A[j]2 exchange A[i] with A[j]After the compare-exchange operation, we know that A[i] ¤ A[j]. An
Show how to sort n integers in the range 0 to n3 - 1 in O(n) time.
Suppose that we were to rewrite the for loop header in line 10 of the COUNTING SORT as10 for j = 1 to A.lengthShow that the algorithm still works properly. Is the modified algorithm stable?
Explain why the worst-case running time for bucket sort is Θ(n2). What simple change to the algorithm preserves its linear average-case running time and makes its worst-case running time O(n lg n)?
In this problem, we prove a probabilistic Ω(n lg n) lower bound on the running time of any deterministic or randomized comparison sort on n distinct input elements. We begin by examining a deterministic comparison sort A with decision tree TA. We assume that every permutation of A's inputs is
The analysis of the expected running time of randomized quicksort in Section 7.4.2 assumes that all element values are distinct. In this problem, we examine what happens when they are not.a. Suppose that all element values are equal. What would be randomized quicksort's running time in this
Each exchange operation on line 5 of HEAP-INCREASE-KEY typically requires three assignments. Show how to use the idea of the inner loop of INSERTION-SORT to reduce the three assignments down to just one assignment.
Show that there are at most ⌈n=2h+1⌉ nodes of height h in any n-element heap.
A d-ary heap is like a binary heap, but (with one possible exception) non-leaf nodes have d children instead of 2 children.a. How would you represent a d-ary heap in an array?b. What is the height of a d-ary heap of n elements in terms
We can build a heap by repeatedly calling MAX-HEAP-INSERT to insert the elements into the heap. Consider the following variation on the BUILD-MAX-HEAP procedure:BUILD-MAX-HEAP′ (A)1 A.heap-size = 12 for i = 2 to A.length3 MAX-HEAP-INSERT(A,
Suppose we want to create a random sample of the set {1, 2, 3, . . . , n}, that is, an m-element subset S, where 0 ≤ m ≤ n, such that each m-subset is equally likely to be created. One way would be to
Suppose that n balls are tossed into n bins, where each toss is independent and the ball is equally likely to end up in any bin. What is the expected number of empty bins? What is the expected number of bins with exactly one ball?
Professor Armstrong suggests the following procedure for generating a uniform random permutation:PERMUTE-BY-CYCLIC (A)1. n = A.length2. let B[1. . n] be a new array3. offset = RANDOM (1, n)4. for i = 1 to n5. dest = i + offset6. if dest > n7. dest = dest – n8. B[dest] = A[i]9. return BShow
Suppose that you are given a flow network G, and G has edges entering the source s. Let f be a flow in G in which one of the edges (ν, s) entering the source has f (ν, s) = 1. Prove that there must exist another flow f′ with f′(ν, s) = 0 such that |f| = |f′|. Give an O(E)-time algorithm to
Consider the following multithreaded algorithm for performing pairwise addition on n-element arrays A[1 . . n] and B[1. . n], storing the sums in C[1. . n].SUM-ARRAYS (A, B, C)a. Rewrite the parallel loop in SUM-ARRAYS using nested parallelism (spawn and sync) in the manner
Suppose that we spawn P-FIB(n – 2) in line 4 of P-FIB, rather than calling it as is done in the code. What is the impact on the asymptotic work, span, and parallelism?
Showing 1100 - 1200
of 1549
First
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Step by Step Answers