Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The median of a set of n distinct integers is the middle element whenthe integers are sorted. For simplicity, we will assume that n is

The median of a set of n distinct integers is the middle element whenthe integers are sorted. For simplicity, we will assume that n is odd, i.e., the medianis at position (n + 1)/2 in sorted order.Example:{−4, 1, 3, 5, 7}, median is 3.

In this problem, we are interested in finding the median of a set of distinct integers stored in two AVL trees. You cannot assume anything about how the integers aredistributed between the two trees (e.g. one might contain n − 1 elements and theother only 1). In addition to the standard pointers to the parent and two children,and the integer itself, each node of the trees also stores the size of the subtree rootedat it. Your task is to design an algorithm that takes these two trees as input andreturns the median of the elements stored in them. For full marks, your algorithm needs to run in O(log n) time.

a) Design an algorithm that solves the problem.

b) Briefly argue the correctness of your algorithm.

c) Analyze the running time of your algorithm.

Step by Step Solution

3.54 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

If you modify the AVL tree by storing the size of the sub tree at each node ... 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

A First Course In Probability

Authors: Sheldon Ross

9th Edition

978-9332519077, 9332519072

More Books

Students also viewed these Algorithms questions

Question

Present a combinatorial explanation of why Ft r, n

Answered: 1 week ago

Question

Prove the multinomial theorem.

Answered: 1 week ago