Socratic Mirror
Compression Digest
compression/_posts/2014-05-11-search-algorithms-binary-search.md

Symbol Tables Implemented with Binary Search on Ordered Arrays

[Literal] A symbol table is a data structure for key-value pairs supporting insert and search operations. [AI Synthesis] Binary search on an ordered array is presented as a method to implement this API. [Literal] The implementation uses two parallel arrays, with keys maintained in sorted order. [Literal] Java code examples demonstrate get() and put() methods, utilizing a rank() helper function to find the position of a key. [Literal] get() returns the value if the key is found, while put() updates the value if the key exists or inserts a new key-value pair, resizing the array if necessary. [Literal] The performance analysis highlights that binary search requires at most lgN + 1 compares for search, but insertion can take up to ~2N array accesses in the worst case, leading to ~$N^2$ accesses for inserting N keys. [AI Synthesis] This makes it efficient for static tables but problematic for dynamic scenarios with frequent intermixed searches and inserts. [Literal] The text concludes that for efficient insertion alongside search, more complex data structures like binary search trees or hash tables are needed, as linked structures alone prevent binary search's indexing advantage.

Key points

Patterns / reminders

Sources