Data Structures And Algorithm Analysis In Java 3rd Edition Weiss Solutions Manual pdf download
Data Structures And Algorithm Analysis In Java 3rd Edition Weiss Solutions Manual pdf download
https://testbankdeal.com/product/data-structures-and-algorithm-
analysis-in-java-3rd-edition-weiss-solutions-manual/
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.
Other documents randomly have
different content
"Onko tämä Yrjö ennenkin jo ollut tukinajossa?"
"En oikein pannut merkille, mutta nyt, kun sitä alan tarkemmin
muistella, johtuu mieleeni, että sillä oli pitkät viikset, jotka olivat
jäätyneet kahdeksi suoraksi puikoksi molemmin puolin naamaa",
muisteli mies.
"Se rietas se on ollut", sanoi Vänttinen. "Entä näitkö muuta?"
tiedusteli hän lisää. "Näkyikö Hyrränperässä… oliko siellä
juopuneita?"
"Minä arvelin, että mikä hullu tuo on, että ei se kyllä tukinajajalta
näytä, vaan ei herraksikaan sovi… Ajelin eteenpäin — noin kilometrin
verran — niin jo ajaa vastaani vinhaa kyytiä, hevonen höyryten,
kolme poliisia… jo aloin hoksata, mikä se äskeinen vastaantulija
oli…"
"En ostanut", vastasi mies, "ja muut, jotka olivat samalla kertaa
Hyrränperässä olleet, sanoivat, että se kauppias oli vain
laukkukauppias."
Jos semmoisia olisivat muutkin miehet kuin Antti, niin vähän niitä
viinakauppiaita pääsisi tänne sydänmaalle, mietti hän ja päätti
jollakin hyvällä työllä muistaa Anttia.
"Viepä nuo tuliaisiksi Antille, niin saapi iltasella savut vetää", hän
Syrjäselle sanoi.
4.
Kolme viikkoa olivat Antti ja Yrjö tukkeja ajaneet, reilusti oli käynyt
työ. Puut olivat kyllä suuria, mutta hyvin olivat jaksaneet, ja vankka
oli läjä, jonka he metsäjoen varteen olivat saaneet.
"Pyörtynyt oli, ja kova oli työ, ennenkuin sain tukin sen verran
siirtymään, jotta sai rutistuneen jalan irti", selitteli hän läsnäoleville.
"Niinkuin kuollut retkotti siinä, mutta virkosi sitten vähitellen ja
ymmärsi kaikki, miten hänelle oli käynyt."
"Jos sairas tuntuu kestävän, niin anna mennä hyvää kyytiä, sillä ei
ole tämmöisessä tilanteessa aikaa vitkastella. Verenmyrkytys voipi
tulla hyvin äkkiä, ja siinä se sitten on miehen elämän loppu."
"Jaa… eipä niitä ole näkynyt. Mutta minulle on kerrottu, että Pirtu-
Santeri on täälläpäin nähty… että on nähty tässä likelläkin
hiihtelevän."
Niin hän lauleli, mutta muuta hän ajatteli. Pitkin matkaa hän oli
kuulevinaan milloin perästä, milloin sivulta, kuin joku olisi suksilla
hiihtänyt. Kerran tuntui kuin hiihtäjä olisi hyvin likellä. Yrjö lakkasi
laulannasta, nousi reessä seisomaan ja huusi:
Yrjö kertoi mitä oli kirjoittanut ja että Vänttinen oli luvannut rahat
kirjeeseen panna.
5.
*****
Lauantaipäivä oli.
"Hiihdä sinä nyt suoraan kodalle ja pane keitto tulelle… minä vien
kuorman rantaan ja tulen sitten…"
Siitä oli suksilla metsän läpi puolta lyhempi matka heidän
kodalleen, ja Yrjö lähti suoraan siitä hiihtämään.
Aika kului.
Lapin päivä on niin lyhyt, että kun luulet sen alkavan valjeta,
ojentaakin jo iltahämy aamuhämylle kättään ja odottamasi päivä on
mennyt, ja raukea sarastus katoaa tunturien taakse.
"Ei kuulunut. En ymmärrä, mitä hän niin kauan viipyy. Olisi pitänyt
jo ehtiä…"
Roope selitti, kuinka olivat ensin alkaneet oudoksua, kun Antti niin
kauan viipyi kuormaa purkamassa, ja vihdoin lähteneet Yrjön kanssa
katsomaan plassille. Hän ja Yrjö olivat saaneet sen käsityksen, että
tukkikanki oli kuormaa purkaessa singahtanut ohimoon…
"Mikäpä sen tietää, kun sattui aivan yksin olemaan", arveli Roope.
"Mutta niin minusta näytti, että kanki oli jotenkin singahtanut ja
paukahtanut suoraan otsaan… Vaikka en minä sen tarkemmin osaa
selittää…"
*****
Hän tuli kuin raivoihinsa, puri hammasta ja pui nyrkkiä. Hän käski
valjastaa heti hevosen, otti molemmat poliisit matkaansa ja läksi
kiireesti ajamaan sille kodalle, jossa Antti poikineen oli asunut.
6.
testbankdeal.com