QUESTION IMAGE
Question
choose the best collection for each situation. you need to keep a record of the ages of the last 50 customers visit a restaurant. as new customers come in you delete the age that has been in the list the longest. you need to store the gps coordinates of the hospitals in a state in order to find the nearest hospital for ambulance helicopters. you write a loop to save anywhere from 10 to 100 values from a user. you will pass the collection to a function to find the average.
Brief Explanations
- For the first situation, a queue is suitable as it follows the First - In - First - Out (FIFO) principle. As new customers come in, the oldest record (the one that has been in the list the longest) can be removed easily, similar to how a queue works.
- For the second situation, a data structure like a k - D tree (a type of tree data structure) can be used to store GPS coordinates as it is efficient for nearest - neighbor search problems, which is required to find the nearest hospital for ambulance helicopters.
- For the third situation, an array or a list can be used to store the values entered by the user as they are simple data structures that can hold a collection of values and can be easily passed to a function to calculate the average.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
- Queue
- k - D tree
- Array/List