Data Structures And Algorithm Analysis In Java 3rd Edition Weiss Solutions Manual - Available For One-Click Instant Download
Data Structures And Algorithm Analysis In Java 3rd Edition Weiss Solutions Manual - Available For One-Click Instant Download
https://testbankdeal.com/product/data-structures-and-algorithm-
analysis-in-c-4th-edition-weiss-solutions-manual/
https://testbankdeal.com/product/data-structures-and-algorithms-in-
java-1st-edition-peter-drake-solutions-manual/
https://testbankdeal.com/product/starting-out-with-java-from-control-
structures-through-data-structures-3rd-edition-gaddis-solutions-
manual/
https://testbankdeal.com/product/principles-of-foundation-
engineering-8th-edition-das-solutions-manual/
TEACH 2nd Edition Janice Koch Solutions Manual
https://testbankdeal.com/product/teach-2nd-edition-janice-koch-
solutions-manual/
https://testbankdeal.com/product/information-technology-auditing-4th-
edition-hall-solutions-manual/
https://testbankdeal.com/product/concepts-of-genetics-2nd-edition-
brooker-solutions-manual/
https://testbankdeal.com/product/legal-environment-of-business-8th-
edition-kubasek-solutions-manual/
https://testbankdeal.com/product/payroll-accounting-2018-28th-edition-
bieg-solutions-manual/
Nursing research methods and critical appraisal for
evidenced based practice 8th Edition Wood Test Bank
https://testbankdeal.com/product/nursing-research-methods-and-
critical-appraisal-for-evidenced-based-practice-8th-edition-wood-test-
bank/
CHAPTER 6
6.2
6.3 The result of three deleteMins, starting with both of the heaps in Exercise 6.2, is as follows:
6.4 (a) 4N
(b) O(N2)
(c) O(N4.1)
(d) O(2N)
©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
// Percolate up
int hole = + + currentSize;
for ( ; hole > 1 && x.compareTo( array[ hole / 2 ] ) < 0; hole
/ = 2)
array[ hole ] = array[ hole/2 ];
array[ 0 ] = array[ hole ] = x;
}
6.6 225. To see this, start with i = 1 and position at the root. Follow the path toward the last node, doubling i
when taking a left child, and doubling i and adding one when taking a right child.
6.7 (a) We show that H(N), which is the sum of the heights of nodes in a complete binary tree of N nodes, is
N − b(N), where b(N) is the number of ones in the binary representation of N. Observe that for N = 0 and
N = 1, the claim is true. Assume that it is true for values of k up to and including N − 1. Suppose the left and
right subtrees have L and R nodes, respectively. Since the root has height log N , we have
H (N ) = log N + H (L) + H (R )
= log N + L − b(L) + R − b(R)
= N − 1 + ( Log N − b(L) − b(R) )
The second line follows from the inductive hypothesis, and the third follows because L + R = N − 1. Now the
last node in the tree is in either the left subtree or the right subtree. If it is in the left subtree, then the right
subtree is a perfect tree, and b(R) = log N − 1 . Further, the binary representation of N and L are identical,
with the exception that the leading 10 in N becomes 1 in L. (For instance, if N = 37 = 100101, L = 10101.) It
is clear that the second digit of N must be zero if the last node is in the left subtree. Thus in this case,
H(N) = N − b(N)
If the last node is in the right subtree, then b(L) = log N . The binary representation of R is identical to
N, except that the leading 1 is not present. (For instance, if N = 27 = 101011, L = 01011.) Thus
H(N) = N − b(N)
(b) Run a single-elimination tournament among eight elements. This requires seven comparisons and
©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
The eighth comparison is between b and c. If c is less than b, then b is made a child of c. Otherwise, both
(c) A recursive strategy is used. Assume that N = 2k. A binomial tree is built for the N elements as in part (b).
The largest subtree of the root is then recursively converted into a binary heap of 2 k − 1 elements. The last
element in the heap (which is the only one on an extra level) is then inserted into the binomial queue
consisting of the remaining binomial trees, thus forming another binomial tree of 2 k − 1 elements. At that
point, the root has a subtree that is a heap of 2 k − 1 − 1 elements and another subtree that is a binomial tree of
2k−1 elements. Recursively convert that subtree into a heap; now the whole structure is a binary heap. The
running time for N = 2k satisfies T(N) = 2T(N/2) + log N. The base case is T(8) = 8.
6.9 Let D1, D2, . . . ,Dk be random variables representing the depth of the smallest, second smallest, and kth
smallest elements, respectively. We are interested in calculating E(Dk). In what follows, we assume that the
heap size N is one less than a power of two (that is, the bottom level is completely filled) but sufficiently
large so that terms bounded by O(1/N) are negligible. Without loss of generality, we may assume that the kth
smallest element is in the left subheap of the root. Let pj, k be the probability that this element is the jth
Lemma.
k −1
For k > 1, E (Dk ) = p j ,k (E (D j ) + 1) .
j =1
Proof.
An element that is at depth d in the left subheap is at depth d + 1 in the entire subheap. Since
©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Since by assumption, the bottom level of the heap is full, each of second, third, . . . , k − 1th smallest
elements are in the left subheap with probability of 0.5. (Technically, the probability should be half − 1/(N −
1) of being in the right subheap and half + 1/(N − 1) of being in the left, since we have already placed the kth
smallest in the right. Recall that we have assumed that terms of size O(1/N) can be ignored.) Thus
1 k − 2
p j ,k = pk − j ,k = k −2
2 j −1
Theorem.
E(Dk) log k.
Proof.
The proof is by induction. The theorem clearly holds for k = 1 and k = 2. We then show that it holds for
arbitrary k > 2 on the assumption that it holds for all smaller k. Now, by the inductive hypothesis, for any
1 j k − 1,
Thus
k −1
E (Dk ) = p j , k (E (D j ) + 1)
j =1
k −1
=1+ p j, k E(D j )
j =1
Thus
©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
k −1
E ( Dk ) 1 + p j , k log ( k 2)
j =1
k −1
1 + log ( k 2) p j , k
j =1
1 + log ( k 2)
log k
(b) Works for leftist and skew heaps. The running time is O(Kd) for d-heaps.
6.12 Simulations show that the linear time algorithm is the faster, not only on worst-case inputs, but also on
random data.
6.13 (a) If the heap is organized as a (min) heap, then starting at the hole at the root, find a path down to a leaf by
taking the minimum child. The requires roughly log N comparisons. To find the correct place where to move
the hole, perform a binary search on the log N elements. This takes O(log log N) comparisons.
(b) Find a path of minimum children, stopping after log N − log log N levels. At this point, it is easy to
determine if the hole should be placed above or below the stopping point. If it goes below, then continue
finding the path, but perform the binary search on only the last log log N elements on the path, for a total of
log N + log log log N comparisons. Otherwise, perform a binary search on the first log N − log log N
elements. The binary search takes at most log log N comparisons, and the path finding took only log N − log
log N, so the total in this case is log N. So the worst case is the first case.
(c) The bound can be improved to log N + log*N + O(1), where log*N is the inverse Ackerman function (see
6.14 The parent is at position (i + d − 2) d . The children are in positions (i − 1)d + 2, . . . , id + 1.
(d) d = max(2, M/N). (See the related discussion at the end of Section 11.4.)
©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
6.16 Starting from the second most signficant digit in i, and going toward the least significant digit, branch left for
6.17 (a) Place negative infinity as a root with the two heaps as subtrees. Then do a deleteMin.
(b) Place negative infinity as a root with the larger heap as the left subheap, and the smaller heap as the right
(c) SKETCH: Split the larger subheap into smaller heaps as follows: on the left-most path, remove two
subheaps of height r − 1, then one of height r, r + 1, and so one, until l − 2. Then merge the trees, going
smaller to higher, using the results of parts (a) and (b), with the extra nodes on the left path substituting for
6.19
6.20
6.21 This theorem is true, and the proof is very much along the same lines as Exercise 4.20.
6.22 If elements are inserted in decreasing order, a leftist heap consisting of a chain of left children is formed. This
6.23 (a) If a decreaseKey is performed on a node that is very deep (very left), the time to percolate up would be
prohibitive. Thus the obvious solution doesn’t work. However, we can still do the operation efficiently by a
combination of remove and insert. To remove an arbitrary node x in the heap, replace x by the merge of its
left and right subheaps. This might create an imbalance for nodes on the path from x’s parent to the root that
©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
would need to be fixed by a child swap. However, it is easy to show that at most logN nodes can be affected,
6.24 Lazy deletion in leftist heaps is discussed in the paper by Cheriton and Tarjan [10]. The general idea is that if
the root is marked deleted, then a preorder traversal of the heap is formed, and the frontier of marked nodes is
removed, leaving a collection of heaps. These can be merged two at a time by placing all the heaps on a
queue, removing two, merging them, and placing the result at the end of the queue, terminating when only
6.25 (a) The standard way to do this is to divide the work into passes. A new pass begins when the first element
reappears in a heap that is dequeued. The first pass takes roughly 2*1*(N/2) time units because there are N/2
merges of trees with one node each on the right path. The next pass takes 2*2*(N/4) time units because of the
roughly N/4 merges of trees with no more than two nodes on the right path. The third pass takes 2*3*(N/8)
6.26
6.27
6.28 This claim is also true, and the proof is similar in spirit to Exercise 4.20 or 6.21.
©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
6.29 Yes. All the single operation estimates in Exercise 6.25 become amortized instead of worst-case, but by the
definition of amortized analysis, the sum of these estimates is a worst-case bound for the sequence.
6.30 Clearly the claim is true for k = 1. Suppose it is true for all values i = 1, 2, . . . , k. A Bk + 1 tree is formed by
attaching a Bk tree to the root of a Bk tree. Thus by induction, it contains a B0 through Bk − 1 tree, as well as the
6.31 Proof is by induction. Clearly the claim is true for k = 1. Assume true for all values i = 1, 2, . . . ,k. A Bk + 1
k
tree is formed by attaching a Bk tree to the original Bk tree. The original thus had nodes at depth d. The
d
k
attached tree had nodes at depth d−1, which are now at depth d. Adding these two terms and using a
d − 1
6.32
6.38 Don’t keep the key values in the heap, but keep only the difference between the value of the key in a node
6.39 O(N + k log N) is a better bound than O(N log k). The first bound is O(N) if k = O(N/log N). The second
bound is more than this as soon as k grows faster than a constant. For the other values (N/log N) = k = (N),
the first bound is better. When k = (N), the bounds are identical.
©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Another Random Scribd Document
with Unrelated Content
throwing away their idols and attending the church services, which
are thronged every Sabbath. The famous Juju temple, studded with
human skulls, is going to ruin. A village opposite Bonny has been
named “The Land of Israel” because there is not an idol to be found
in it. At an important market town thirty miles in the interior, the
chiefs and people, influenced by what they had seen at Bonny, and
without ever having been visited by a Christian teacher,
spontaneously built a church with a galvanized iron roof, and
benches to seat 300 worshipers, got a school-boy from Bross to read
the church services on Sundays, and then sent to ask the Bishop to
give them a missionary.
Then for years death-like quiet reigned in the city, and all signs
of commerce ceased. But this stagnation was not to last forever.
England and other commercial nations of Europe, in their efforts to
find markets for the sale of the products of their mills and
workshops, had established depots for trade at almost every
important place in the world. The eyes of European merchants were
turned towards the prolific field of southwest Africa.
Stories which told how great wealth was to be gained in African
trade began to be chronicled in the exchanges of all the great
commercial centres, and a wave of commercial endeavor was put in
motion, which carried with it many richly freighted barks to again fill
the harbor of the African city of St. Paul de Loanda. Since then
Loanda has improved beyond all expectation, and now the vessels of
four lines of steamers as well as many sailing craft are constantly in
the harbor loading and discharging their cargoes. Many large public
buildings have been built. Acres of flat and swampy shore have been
reclaimed and are now utilized for docks and wharfs. Ruins of
churches and monasteries have been cleared away and walks and
squares have been laid out and planted. There are many shops
supplied with all kinds of European goods. Pipes have been laid,
through which flows into the city sweet water from the river Bengo,
nine miles away, and when the railway, now in course of
construction, is in operation to bring the products of the farms,
plantations and rich forests of the interior to the city, Loanda will
have become a fair specimen of a thriving tropical town.
The city is situated on the shore of a large and beautiful bay
and is divided into a lower and an upper town. The “Cidade Buixa,”
or lower town, which is built on the flat shore which fringes the
water of the bay, nestles at the base of a hill and straggles up its
rising sides until it joins the “Cidade Alto.” The upper town stretches
along the brow of the elevation and sweeps outward towards the
ocean until it ends at a bold and rocky precipice where Fort St.
Miguels, a frowning sentinel, watches over the safety of the port.
The harbor is a bay where a thousand ships might at one time
ride at anchor and find secure protection from the severest storm. A
long, low and narrow neck of land, called Isle of Palms, leaves the
mainland about twelve miles to the south and runs north until it
reaches a point opposite the city, where it flattens out its surface of
sunlit sands to give protection to the harbor of which it forms the
southern boundary.
FOREST SCENE IN ANGOLA.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
testbankdeal.com