Elementary Symbol Tables

33 阅读1分钟

・Method put() overwrites old value with new value.

・Method get() returns null if key not present.

Sequential search in a linked list

  • Data structure. Maintain an (unordered) linked list of key–value pairs.

  • Search. Scan through all keys until finding a match.

  • Insert. Scan through all keys until finding a match; if no match add to front.

Binary search in a sorted array

  • Data structure. Maintain parallel arrays for keys and values, sorted by key.

  • Search. Use binary search to find key.

  • Insert. Use binary search to find place to insert; shift all larger keys over.

image.png