lab1sol - - 1 - Part 1 . The source code for this part...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: - 1 - Part 1 . The source code for this part appears below. Dheap.h (with unchanged parts omitted) ... class Dheap { public: ... // stats methods void clearStats(); string& stats2string(string&) const; private: ... // statistics counters int changekeyCount; int siftupCount; int siftdownCount; ... }; Dheap.cpp ... void Dheap::siftup(item i, int x) { int px = p(x); while (x > 1 && kee[i] < kee[h[px]]) { h[x] = h[px]; pos[h[x]] = x; x = px; px = p(x); siftupCount++; } h[x] = i; pos[i] = x; } ... void Dheap::siftdown(item i, int x) { int cx = minchild(x); while (cx != 0 && kee[h[cx]] < kee[i]) { h[x] = h[cx]; pos[h[x]] = x; x = cx; cx = minchild(x); siftdownCount += D; } h[x] = i; pos[i] = x; } ... void Dheap::changekey(item i, keytyp k) { changekeyCount++; CSE 542 Advanced Data Structures and Algorithms Lab 1 Solution Jon Turner - 2 - keytyp ki = kee[i]; kee[i] = k; if (k == ki) return; if (k < ki) siftup(i,pos[i]); else siftdown(i,pos[i]); } ... /** Clear the statistics counters */ void Dheap::clearStats() { siftupCount = siftdownCount = changekeyCount = 0; } /** Return a string representation of the statistics counters. * @param s is a string in which the result is returned * @return a reference to s */ string& Dheap::stats2string(string& s) const { string s1; s = "changekeyCount = " + Util::num2string(changekeyCount,s1) + " "; s += "siftupCount = " + Util::num2string(siftupCount,s1) + " "; s += "siftdownCount = " + Util::num2string(siftdownCount,s1); return s; }- 3 - Part 2 . The table below shows the counter values, the values of d for each case, the maximum depth of the heap and the upper bounds on the counter values. 4K 10K 20K 40K 100K 200K 400K changekeyCount 1,301 2,213 2,980 3,575 4,533 5,165 5,860 siftupCount 2,292 1,790 1,431 1,225 1,048 882 672 siftdownCount 18,798 29,592 44,352 75,852 170,952 297,950 486,018 d 6 12 22 42 102 202 402 heap depth 4 3 3 2 2 2 2 changekeyBound 4,000 10,000 20,000 40,000 100,000 200,000 400,000 siftupBound 20,000 33,000 63,000 82,000 202,000 402,000 802,000 siftdownBound 24,000 36,000 66,000 84,000 204,000 404,000 804,000 The changkeyBound is equal to the number of edges in the graph, the siftupBound is computed by multiplying ((# of inserts=1,000) + (the changekeyBound...
View Full Document

This note was uploaded on 03/08/2012 for the course CSE 542 taught by Professor Jonturner during the Spring '12 term at Washington State University .

Page1 / 7

lab1sol - - 1 - Part 1 . The source code for this part...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online