In: Computer Science
1. Suppose you are implementing software to be used in a handheld device that checks whether event attendees are part of a group of people allowed access to a special session at the event. Guests can purchase access to the special session any time up to the instant the event begins, and the device receives updated records to ensure paying guests (only) are allowed in to the special session Would choosing a set data structure to manage the special session guests or a list be more efficient? Explain
Choosing a set data structure to manage the special session guests is more efficient than a list.Every guest data is unique hence we can store their data in a set. Checking for an item in a set is significantly faster than lists.So we can check whether the guest is allowed or not, faster with sets than lists .This is done by checking for guest data in set, if the guest is present in the set then he/she is allowed otherwise they are not allowed. Sets are implemented using hash tables,hence while searching for a member all it has to do is to check whether the member is present in the position determined by its hash. Here speed of operation does not depend on its size and elements in set are not stored in the order you add them. In case of lists if we want to search for an object we have to go through the entire list until we find the object,so it takes more time. Speed decreases as the size increases.