1 / 14

The Most Commonly-used Data Structures

The Most Commonly-used Data Structures. Terence Parr USF. Introduction. Abstract data types Data structures (implementations) Combinations. Abstract Data Types. List stack, queue, prioritized queue, … Set (unordered, unique) Dictionary (also called Map) Graph (directed or undirected)

jordanleon
Télécharger la présentation

The Most Commonly-used Data Structures

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. The Most Commonly-usedData Structures Terence Parr USF

  2. Introduction • Abstract data types • Data structures (implementations) • Combinations

  3. Abstract Data Types • List • stack, queue, prioritized queue, … • Set (unordered, unique) • Dictionary (also called Map) • Graph (directed or undirected) • Tree • Binary tree • Choose via: • access pattern, properties, element relationships • Implementations chosen to optimize time/space

  4. List • Operations: add, get, insert, delete, find • queue: add to tail, get only from head • stack: add to “top”, delete from “top” • Typical implementation: array or linked list • Examples: list of users, list of books

  5. Set • Operations: add, delete, contains • Typical implementation: bit vector (if elements are integers) or hash table • Examples: set of universities, set of students

  6. Dictionary • Operations: map x->y, get x, delete x • Typical implementation: hash table • Examples: • student -> userid • student -> list of classes

  7. Graph • Collection of nodes connected by directed or undirected edges with or without labels • Path==sequence of edges • Operations: add node, add edge x->y, delete node, delete edge • Typical implementation: node has list of edges that point to other nodes • Examples: network simulation, email trail between employees (social network), finite automata

  8. Tree • A kind of directed graph with unique edge path from node x to y • Children: emanating edges, Root: topmost node, Leaves: nodes w/o children • Operations: add child, delete a child • Typical implementation: node has list of children (again, a restricted graph) • Examples: organization chart, class hierarchy, expression tree • Binary tree: at most 2 children per node

  9. Implementations

  10. Linked list • head, tail pointers • wrapper to hold value and “next” • Operations: • get O(1) • others O(n)

  11. Hash table • Fast implementation of a dictionary; like an associative memory; maps key to value • Idea: break up large search space into many smaller spaces • “hash function” tells you which of the smaller spaces (“buckets”) has element of interest • search linearly within smaller space • simple hash of int: hash(x)=x; hash of string: sum of char values • Array of lists; each list is a bucket of key/value pairs • bucket index(key) = hash(key) % num_buckets

  12. Hash table 2

  13. Tree • Node has list of children; need root ptr CEO + 3 * President 4 5 VP Sales VP Eng.

  14. Graph • States or nodes have list of edges to other states Mary Jim Chris Tim Jen

More Related