Question: Writing an algorithm that will enable customers to search for the k stores closest to a particular location. You are working for a department store
Writing an algorithm that will enable customers to search for the k stores closest to a particular location.



You are working for a department store with hundreds of locations across the country. You're tasked with writing an algorithm that will enable customers to search for the k stores closest to a particular location. Eventually, we will want to call the algorithm as such: KCLOSESTSTORES(num-stores-to-find, customer-location, all-store-locations[]). (a) Begin by coming up with a divide and conquer algorithm to find the closest store to the customer's location. You can assume that a function, Dist, has already been written, which returns the distance between two zipcodes as a positive number. You can also assume that the company has an even number of stores. Describe your approach in a sentence or two, indicate the input and output of the algorithm, and provide the pseudocode. (b) Write a recurisve algorithm that will return the k nearest stores. This new algorithm can call the algorithm you wrote in part a. Describe your approach in a sentence or two, indicate the input and output of the algorithm, and provide the pseudocode. (c) Test that your algorithm from part b works as expected using the following inputs: k - 5 z = 20 (we're not using actual zipcodes so our test will be easy to verify) L - [10, 20, 30, 40, 1, 12, 34, 8). If your algorithm is working correctly, it should return the following list [8, 10, 12, 20, 30] You can assume that Dist will calculate the distance between z and L; as the absolute value of z - Li. For example Dist(20,8) would return 12. Write out each step for the algorithm you wrote in part b. You do not need to write out all the additional steps taken when the algorithm you wrote in part a is called
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
