Question

Selecting an Implementation We have studied arrays, vectors, and linked lists. Say which you would use...

Selecting an Implementation

We have studied arrays, vectors, and linked lists. Say which you would use to implement each situation below. Defend every answer by saying why the answer you chose is better than the other two possibilities.

  1. A list of participants at a large public hearing. As each person arrives, their name is entered into the system, where it is appended to the end of the list.
  2. Thermometer readings at a weather station. The temperature is recorded every 5 minutes for 24 hours. Once each day, the data is written to a file.
  3. A waiting line of people at Subway shop. At the busiest times of day, there are frequent arrivals at the end of the line and customers frequently pay and leave.

Homework Answers

Answer #1

1. We have unknown number of participants at a public hearing. As each person arrives, name is entered into the system.
In this case, vector is the best to use as it can grow in size, when needed.

Vector

2. Temperature is recorded for every 5 mins for 24 hrs. That means, we need to record total 288 times in a day. Since we have a fixed number, we can use an array. It provides advantages of being able to access any element immediately and it is best for performing Sorting.

Array

3. At the subway shop, people come and go. We need to be able to keep track of arrivals and departures. In this case, it's best to use a linked list, as Linked list can dynamically grow in size. Arrivals happen at one end and departures at another end. This case can easily be handled by a Linked List in constant time.

Linked List

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions