Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

choose the best collection for each situation. you need to keep a recor…

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.

Explanation:

Brief Explanations
  1. 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.
  2. 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.
  3. 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.

Answer:

  1. Queue
  2. k - D tree
  3. Array/List