Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose we we are reading an input stream of N numbers, and after reading the stream, we want to report the M largest numbers. Suppose

Suppose we we are reading an input stream of N numbers, and after reading the stream, we want to report the M largest numbers. Suppose M is big, but relatively small compared to N: M N/ lg N. For both parts, describe how to solve the problem using a binary heap. (One of these is TopM in the book, for the other you need the linear-time heap construction method of Section 2.4, part of the discussion of heapsort.)

3(a). Solve the problem in O(N) time and O(N) space.

3(b). Solve the problem in O(N lg M) time and O(M) space. Remarks: In both parts, space counts words of memory. A word is large enough to store an input number, an index,

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

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

Students also viewed these Databases questions

Question

8. Managers are not trained to be innovation leaders.

Answered: 1 week ago