Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this part you have to come up with an algorithm to answer a more complicated range query, namely, given an array A as above,

In this part you have to come up with an algorithm to answer a more complicated range query, namely, given an array A as above, a range query [a, b] now requires you to actually list all of the A[i]s in the range a . . . b. Using the same array A as above, the range query [2, 7] asks which numbers from A are there in the array A are between 2 and 7, so the answer should be 3,5,5,6,7 (it doesnt matter in what order the numbers are outputted). Your algorithm should work within the following time bounds:

The one time preprocessing step should take O(n + k) time (the preprocessing here will be different from that in the first part).

Given a range query [a, b], the time taken to answer this query should not depend on k or on n or on the quantity b a; instead, the query should be answered in time O(t) where t is the number of elements in the output (the number of A[i]s in the range [a, b]). For example, if we consider two range queries, [a1, b1] and [a2, b2], [a1, b1] leads to an output of 500 elements, and [a2, b2] leads to an output of 100 elements, then answering [a1, b1] should take approximately 5 times as much time as answering [a2, b2]. Or consider another example, where k = 106 , n = 105 , a = 2000, b = 3000, and there are only three elements in the range [2000, 3000]. If you look at every entry in C between 2000 and 3000 i.e. you look at C[2000], C[2001], C[2002], . . . , C[3000], you are looking at b a = 1001 entries which is too expensive since t = 3 is much smaller than b 1 i.e. there are only three elements in the range [2000, 3000].

(a) Give a clear description of your algorithm for the above problem. This description should include both how the preprocessing step is carried out, and then how the range queries are answered.

(b) Trace your algorithm on the above example i.e. for the array A as above, show what will happen in the preprocessing step. Then show how the algorithm will answer the range query [2, 7]. Also show how the algorithm will answer the range query [1, 9].

(c) Do a worst case time analysis (use big O notation) of your algorithm i.e. answer the two questions: how much time does the preprocessing step take and how much time does answering the range query take. Hint: You will need to keep one or more auxillary arrays; what these are going to be, you need to figure out. You should show how to fill these auxillary array(s) in time O(n + k) (this is the preprocessing step), and once these auxillary array(s) are available, you have to figure out how they can be used to quickly answer the range queries.

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

What is behavioral persuasion in advertising designed to do?

Answered: 1 week ago