I have a list of student names and their id. Sometimes I need to search name using id, sometimes I need to search id using name.
- If using
array[id] = name
, then it is quick to find a name using an id but slow to find the id using a name. - If using
hash{name} = id
, then it is quick to find the id using a name but slow to find the name from an id.
What is the best data structure to represent student a name ↔ id relation? Note: the student name is a string while id is a sequential integer from 1 to the total number of these students.
Thanks.