Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a java code that will take user input and find the median using two heaps (max and min heap). The two heap must sort

Create a java code that will take user input and find the median using two heaps (max and min heap). The two heap must sort the elements from small to large. Running time must be efficient and below O(n^2). The algorithm must support the following methods:

- insert(b): insert a given element b in O(logn) time

- getMedian(): return the median in O(1) time

- removeMedian(): remove and return the median in O(logn) time

Note: The median will return the element that exist in the list, for example an even number of elements <9, 9, 1, 2> will return 2 instead of 5 which doesn't exist in the list.

Odd list exp <4, 8, 2> will return 4 (sorting <2,4,8>). Another even exp <15, -2, 10, -5, 11, 18, 5, 1> will return 5 (sorting <-5, -2, 1, 5, 10, 11, 15, 18>)

Answer with java or pseudo code and analyse the running time.

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions