Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Most Commonly-used Data Structures

Similar presentations


Presentation on theme: "The Most Commonly-used Data Structures"— Presentation transcript:

1 The Most Commonly-used Data Structures
Terence Parr USF

2 Introduction Abstract data types Data structures (implementations)
Combinations

3 Abstract Data Types List Set (unordered, unique)
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, 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


Download ppt "The Most Commonly-used Data Structures"

Similar presentations


Ads by Google