Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose we want to maintain a dynamic set S of n distinct numbers so as to support the following two operations: ( 1 ) Insert

Suppose we want to maintain a dynamic set S of n distinct numbers so as to support the following two operations: (1) Insert a number x into S, and (2) Report the minimum difference between two numbers in S. For example, if S={1,5,7,8,12}, then if we perform the report operation, the answer would be 1(where the minimum difference is from 7 and 8).
a. Describe a data structure that supports each insert in O(logn) time, so that each report can be performed in O(1) time. Also, briefly explain why the claimed time complexities are correct.
b.(Challenging) Suppose we now need an extra operation, which deletes a number x from S. For example, we may delete 7 from the previous S so that S becomes {1,5,8,12}. At this point, if we perform the report operation, we should answer 3. Describe a data structure that supports each insert or delete in Ologn time, while each report can still be performed in O(1) time. Also, briefly explain why the claimed time complexities are correct.
image text in transcribed

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

The Power Of Numbers In Health Care A Students Journey In Data Analysis

Authors: Kaiden

1st Edition

8119747887, 978-8119747887

More Books

Students also viewed these Databases questions