1 / 14

ADTs so far

Explore different levels of Abstract Data Types (ADTs) from lower to higher, including Linked Lists, Arrays, Vectors, Stacks, Dictionaries, Hash Tables, and Ordered Trees. Learn about implementation strategies, collision resolution methods, and comparison of data structures for efficient operations. Discover the balance between efficiency and flexibility in data handling.

Download Presentation

ADTs so far

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. ADTs so far

  2. Lower level ADTs • Linked lists (singly- and doubly- linked) • “Stretchable”, efficient, but… • Sequential access • Arrays • Even more efficient, but not “stretchable” • Random Access • Vectors, Sequences, Lists • All the features, but pay in efficiency • Really, implemented with the above Gene Itkis; cs112

  3. Higher Level ADTs For all: • isEmpty() • size() • insert(elem) • remove() • Stacks • last inserted • Queues • first inserted • Priority Queues • highest priority Gene Itkis; cs112

  4. Dictionaries Retrieve by key

  5. Dictionary Examples • Phone directory • Name is key; phone # is the info • Reverse lookup: phone # is key • Student records • Credit cards DB • E.g. check that the given credit card is valid • Extra:“Authenticate” the result • ETC. Gene Itkis; cs112

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

  7. Simple Implementations • Unordered List • insert • O(1) – fast (delete: the same) • find • O(n) – slow • Ordered list • Linked list implementation – same as unordered • Array • find • Binary search: O(lg n) – pretty fast • insert • O(n) – slow (delete: the same) Gene Itkis; cs112

  8. Better Implementations • Ordered trees • Hash tables • Other • Skip-lists Gene Itkis; cs112

  9. x y z heap Ordered Trees • 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-B trees) Gene Itkis; cs112

  10. Ordered Trees • Searching • Easy • Insert/Delete • 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 Gene Itkis; cs112

  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; cs112

  12. Hash Tables: Idea Hash table key’ • Hash function • H(key)=i • If it works… • Find – O(1) • Insert/Delete – O(1) • Problem? • Collisions: • H(key’)=H(key) key … H i keyinfo … Gene Itkis; cs112

  13. Hash table key’ key H … d d … Hash Table: Issues 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; cs112

  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 Gene Itkis; cs112

More Related