Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question is from algorithams analysis & design course 6. In this part you have to come up with an algorithm to answer a more complicated

Question is from algorithams analysis & design course

6. 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 dierent from that in the rst 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 ba; 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 ba = 1001 entries which is too expensive since t = 3 is much smaller than b1 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 gure out. You should show how to ll 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 gure 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

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

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions