Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i Problem 3: 25 pts) Let A be an array of n elements. A heavy element of A is any element that appears more than

image text in transcribed

i Problem 3: 25 pts) Let A be an array of n elements. A heavy element of A is any element that appears more than 2n/5 times, i.e., is more than 40% of the items. For example, if n = 11 then a heavy element must appear at least 5 times. Note that an array might contain no heavy items, one heavy item or two heavy items. It can not contain more. As examples, consider the arrays A, B and C below: 1234567891011 Ad 3 635 6383 674 123456 7 | 8 | 9 | 10 | 11 Bil 3335 6383 674 1 2 3 4 5 6 7 8 9 10 11 Ci 33366383 666 A contains no heavy items. B contains the unique heavy item 3. C contains the two heavy items 3 and 6. Design an O(n logn) time divide-and-conquer algorithm for finding the heavy items in an array. Your solution should be split into the following three parts. Write the answer to each part separately. (a) (i) Write documented pseudocode for a procedure Heavy(i,j) that returns the set of heavy items in subarray Ali...;). (ii) Below the pseudocode, provide a description in words (as opposed to code) of what your algorithm is doing. (b) Explain (prove) why your algorithm is correct. (c) Let T(n) be the worst case number of total operations of all types performed by your algorithm. Derive a recurrence relation for T(n) (explain how you derived the recurrence relation). Show that T(n) = (n logn). Note: If the recurrer rrence relation is in the form In > 1, T(m) ST (6) +1 () +cin and f(1) = c2 (5) for some c1, c2 > 0 you may immediately conclude that T (n) = O(n logn) without providing any further explanation. This is is essentially what you proved in Problem (1) part (6). Otherwise, you must prove from first principles that whatever recurrence relation you derived implies T(n) = O(n log n) for all values of n. i Problem 3: 25 pts) Let A be an array of n elements. A heavy element of A is any element that appears more than 2n/5 times, i.e., is more than 40% of the items. For example, if n = 11 then a heavy element must appear at least 5 times. Note that an array might contain no heavy items, one heavy item or two heavy items. It can not contain more. As examples, consider the arrays A, B and C below: 1234567891011 Ad 3 635 6383 674 123456 7 | 8 | 9 | 10 | 11 Bil 3335 6383 674 1 2 3 4 5 6 7 8 9 10 11 Ci 33366383 666 A contains no heavy items. B contains the unique heavy item 3. C contains the two heavy items 3 and 6. Design an O(n logn) time divide-and-conquer algorithm for finding the heavy items in an array. Your solution should be split into the following three parts. Write the answer to each part separately. (a) (i) Write documented pseudocode for a procedure Heavy(i,j) that returns the set of heavy items in subarray Ali...;). (ii) Below the pseudocode, provide a description in words (as opposed to code) of what your algorithm is doing. (b) Explain (prove) why your algorithm is correct. (c) Let T(n) be the worst case number of total operations of all types performed by your algorithm. Derive a recurrence relation for T(n) (explain how you derived the recurrence relation). Show that T(n) = (n logn). Note: If the recurrer rrence relation is in the form In > 1, T(m) ST (6) +1 () +cin and f(1) = c2 (5) for some c1, c2 > 0 you may immediately conclude that T (n) = O(n logn) without providing any further explanation. This is is essentially what you proved in Problem (1) part (6). Otherwise, you must prove from first principles that whatever recurrence relation you derived implies T(n) = O(n log n) for all values of n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

ISBN: 9810234368, 978-9810234362

More Books

Students also viewed these Databases questions