1.
Asume you have an object to describe customer data:{ ID(7 digit numeric) Family Name(string) Account Balance(currency) } If you have 500,000 Chinese customers records represented by instances of this object type , what set of data structures is best to get fast retrieval of customers (1) get IDs from Name and (2) get Name from ID?
Name -> ID 就是 string -> int,字符串最好用 Hash 或 Tree 来索引,不过由于 Name 不是唯一的,一个 Name 可能对应多个 ID,要用 Linked List 做对应过来的结构。所以可以是 Hash + Linked List 或 Tree + Linked List。(Tree 可以用 Trie,复杂度是 O(length(name)),其实 Hash 会更好,理论上复杂度是 O(1))。
ID -> Name 就是 int(7 digit) -> string,7 位数也就是 1000 w,可以开得下(人家机子好),所以就可以随机查了。