1. (20 points) Let A[1..n] be an array that stores n possibly non-distinct numbers. (a) (10...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. (20 points) Let A[1..n] be an array that stores n possibly non-distinct numbers. (a) (10 points) A range query specifies two integers à and y that form an interval (x, y]. The answer to a range query is the number of elements in A that are greater than x and less than or equal to y. There is NO requirement that x and y are elements of A. As an example if A = [4, 5, 2, 6, 8, 3, 4, 4], the range query for the interval (3, 6] would return 5 because there are five elements in A that lie in (3,6], namely A[1], A[2], A[4], A[7], and A[8]. Similarly, the range query for the interval (7, 10] would return 1. Describe an algorithm that generates a data structure C such that uses O(n) space and you can use C to answer any range query in O(log n) time. Explain the running time of your algorithm for constructing C. Describe in detail how you use C to answer a range query and explain why it takes O(logn) time. (b) (10 points) Suppose that the numbers in A[1..n] come from the range [1..k] for some positive integer k given to you. A range-sum query specifies two integers x and y in the range [1, k] that form an interval (x, y]. The answer to a range-sum query is the sum of elements in A that are greater thanx and less than or equal to y. As an example if k = 9 and A = [4, 5, 2, 6, 8, 3, 4, 4], the range-sum query for the interval (3, 6] would return 23 . The interval (7, 10] does not define a range-sum query because 10 is outside the range [1,9]. Describe in detail how you would organize the data structure C and con- struct C so that each range-sum query can be answered in O(1) time. Explain the running time of your algorithm for constructing C. Explain why a range-sum query can be answered in O(1) time. 1. (20 points) Let A[1..n] be an array that stores n possibly non-distinct numbers. (a) (10 points) A range query specifies two integers à and y that form an interval (x, y]. The answer to a range query is the number of elements in A that are greater than x and less than or equal to y. There is NO requirement that x and y are elements of A. As an example if A = [4, 5, 2, 6, 8, 3, 4, 4], the range query for the interval (3, 6] would return 5 because there are five elements in A that lie in (3,6], namely A[1], A[2], A[4], A[7], and A[8]. Similarly, the range query for the interval (7, 10] would return 1. Describe an algorithm that generates a data structure C such that uses O(n) space and you can use C to answer any range query in O(log n) time. Explain the running time of your algorithm for constructing C. Describe in detail how you use C to answer a range query and explain why it takes O(logn) time. (b) (10 points) Suppose that the numbers in A[1..n] come from the range [1..k] for some positive integer k given to you. A range-sum query specifies two integers x and y in the range [1, k] that form an interval (x, y]. The answer to a range-sum query is the sum of elements in A that are greater thanx and less than or equal to y. As an example if k = 9 and A = [4, 5, 2, 6, 8, 3, 4, 4], the range-sum query for the interval (3, 6] would return 23 . The interval (7, 10] does not define a range-sum query because 10 is outside the range [1,9]. Describe in detail how you would organize the data structure C and con- struct C so that each range-sum query can be answered in O(1) time. Explain the running time of your algorithm for constructing C. Explain why a range-sum query can be answered in O(1) time.
Expert Answer:
Answer rating: 100% (QA)
a To generate a data structure C for the range query you can use a binary search tree BST augmented ... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
as at 1 July 2022, Winki company enters into a 10 year lease contract for building. Lease payments are $400,000 per year, starting on 30June 2023 and there is no purchase option or residual value...
-
A cross-sectional study was carried out to assess the relationship of alcohol and smoking to blood pressure in 2,500 men ages 20 years or older in four North American population groups, each group...
-
Data visualization can help Broadway theatre analysts to understand ticket pricesExample: Recall the Service Company Insight box How Much Did You Pay for That Seat? presented in the chapter. As...
-
Watch the video interview with Robert L. Johnson titled "Origins" above, or at https://www.kaltura.com/tiny/rqtxv. Then, think of an innovative idea, which you could use to start a business. Next,...
-
Fill in the blank(s) to correctly complete each sentence. Any line perpendicular to the graph of 6x + 7y = 9 must have slope ________.
-
One critical-thinking skill is a heightened awareness of the danger of reaching a conclusion prior to acquiring missing information that were it known would have a reasonable probability of altering...
-
Perdue Company purchased equipment on April 1, 2012, for $270,000. The equipment was expected to have a useful life of three years, or 18,000 operating hours, and a residual value of $9,000. The...
-
3. Find the regular expression for the language accepted by the following automaton. b
-
Alpha Software Ltd. (ASL) maintains a team of ten (10) high quality resource professionals called warriors. They are multi-skilled individuals who can be deployed on any client engagement as critical...
-
Trey will receive $7,500 at the end of Year 2. At the end of the following two years, he will receive $9,000 and $12,500, respectively. What is the future value of these cash flows at the end of Year...
-
In Illinois, when does a judgment become a general lien on a defendant's real and personal property?
-
B24&Co stock has a beta of 1.66, the current risk-free rate is 3.16 percent, and the expected return on the market is 10.66 percent. What is B24&Co's cost of equity?
-
Josh and his friend Kim leave his house at 11:00 am, Josh heads north at 40mph and Kim heads west at 50mph. What is the rate that the distance between them is increasing at noon?
-
under which law is an audit client most likely to sue its audit firm for an audit that the client believes was performed with ordinary neglicence? Explain.
-
What type of building will be suitable for a school? What will be the main consideration in building the rooms of a school? Explain.
-
Q1) What is the a3 Value Q2) What is the a7 Value Q3) What is the a4 Value Q4) What is the b3 Value Q5) What is the b2 Value Q6) What is the sign of 2nd constraint? A pastry chef at a bakery wants to...
-
Select a data structure that you have seen previously, and discuss its strengths and limitations.
-
Prove that the subset relation on all subsets of is a partial order but not a total order.
-
Suppose that we have a linear program that is not in standard form. We could produce the dual by first converting it to standard form, and then taking the dual. It would be more convenient, however,...
-
Why is the analyzing step of the process crucial to the success of a MedImmune proposal? In the discussion, draw students attention to the intersection of medical, legal, and social issues. Why is...
-
How does the Clinical Trial Application guide described in the example make the composing process for a new document easier? How is it informed by the evaluation process? What metaphors or analogies...
-
Review how the ACE process led to the improved message by answering the following questions. 1. What information in the revised version addresses the need for persuasion? 2. How does the email...
Study smarter with the SolutionInn App