Question: Suppose a used car dealer, Jalopy Joe, has asked you to build a website for his car dealership. He wants this website to allow users

Suppose a used car dealer, Jalopy Joe, has asked you to build a website for his car dealership. He wants this website to allow users to be able to search for a set of cars on his lot that are in their price range. That is, viewed abstractly, he would like you to build a system that can maintain an ordered collection, D, of key-value pairs, such that, in addition to the standard insert and removal methods, the implementation for D can support the following operation: 

findAllInRange(k1, k2): 

Return all the elements in D with key k such that k1 ≤ k ≤ k2

In this case, of course, the keys are car prices. Describe an algorithm to implement this method in O(log n + s) time, where n is the number of cars in D and s is the number of cars returned by an instance of this range query.

Step by Step Solution

3.44 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Search for k 1 and then k 2 each while marking the path down to that ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Data Structures Algorithms Questions!