1 / 14

CS 330: Algorithms Elementary Data Structures, Dictionaries

CS 330: Algorithms Elementary Data Structures, Dictionaries. Gene Itkis. Primitive DS. Linked lists (singly- and doubly- linked) “Stretchable”, efficient, but… Sequential access Arrays Even more efficient, but not “stretchable” Random Access. Simple Data Structures. Methods for all:

Download Presentation

CS 330: Algorithms Elementary Data Structures, Dictionaries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 330: AlgorithmsElementary Data Structures,Dictionaries Gene Itkis

  2. Primitive DS • Linked lists (singly- and doubly- linked) • “Stretchable”, efficient, but… • Sequential access • Arrays • Even more efficient, but not “stretchable” • Random Access Gene Itkis

  3. Simple Data Structures Methodsfor all: • isEmpty() • size() • insert(elem) • remove() • which element? • Stacks • last inserted • Queues • first inserted • Priority Queues • highest priority Gene Itkis

  4. Dictionaries Search/Retrieve by key

  5. Dictionary Examples • Phone directory • Name is key; phone # is the info • Reverse lookup: phone # is key • Student records • Possible keys: name, ID# • Credit cards DB; PKI Certificate Revocation Lists (CRLs) • E.g. check that the given credit card / certificate is valid • Extra: “Authenticate” the result • ETC. Gene Itkis

  6. Dictionary Interface Dynamic • isEmpty() • size() • find(key) • insert(elem) • remove(key) Gene Itkis

  7. Implementations • Simple/naïve • Lists • Better implementations • Hash Tables • Probabilistic methods, Expected values • Ordered trees • “Good enough” approximations; Augmenting (order stats) • Other • Skip-lists Gene Itkis

  8. Naïve: Lists • Unordered List • insert & delete • O(1) – fast • find • O(n) – slow • Ordered list • Linked-List • find & insert • O(n) – slow • Array • find • Binary search: O(lg n) – pretty fast • insert • O(n) – slow Gene Itkis

  9. Ordered Trees x y z heap • Order • x< y, z : min at root – heap () • y < x < z : search • Depth • Shallow  Balanced • There might be exceptions: • e.g., Leftist heaps • “Strong” balance • Approximate  • E.g., depth of leaves within factor of 2(R-Btrees) Gene Itkis

  10. Ordered Trees • Searching • Easy • Insert/Delete • Naïve: destroys balance • Fix balance • How? • AVL trees • Nodes keep children heights • Rotate when needed: when children heights are >1 apart • Red-Black / 2-3-4 trees • “Almost balanced” Gene Itkis

  11. Hash tables • Example • Find professors by office number • Find tools in a tool-box • Might not work for everyone • Idea • “Figure” info location from the key Gene Itkis

  12. Hash Tables: Idea Hash table • Hash function • H(key)=i • If it works… • find • O(1) • insert & delete • O(1) • Problem? • Collisions: • H(key’)=H(key) key’ key … H i keyinfo … Gene Itkis

  13. Hash Table: Issues Hash table key’ key H … d d … key” • Good Hash functions • Minimize collision chances • “Random looking” • Collision Resolution • Chaining • Open Addressing • Linear Probing: d=1 • Quadratic Probing: d=i2 • Double Hashing: d=H2(key’) keyinfo keyinfo key’info key’info key”info Gene Itkis

  14. Collision Resolution Methods Comparison • Chaining • Requires extra space • As with linked list • Stretchable • Can degenerate to linked-list search • Open Addressing • No extra space needed • Has size limit • Also can degenerate to unordered list search • Perfect Hashing Gene Itkis

More Related