The Most Commonlyused Data Structures - PowerPoint PPT Presentation

About This Presentation
Title:

The Most Commonlyused Data Structures

Description:

'hash function' tells you which of the smaller spaces ('buckets') has element of interest ... Array of lists; each list is a bucket of key/value pairs ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 15
Provided by: tere102
Learn more at: https://www.cs.usfca.edu
Category:

less

Transcript and Presenter's Notes

Title: The Most Commonlyused Data Structures


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-gty, get x, delete x
  • Typical implementation hash table
  • Examples
  • student -gt userid
  • student -gt list of classes

7
Graph
  • Collection of nodes connected by directed or
    undirected edges with or without labels
  • Pathsequence of edges
  • Operations add node, add edge x-gty, 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
Write a Comment
User Comments (0)
About PowerShow.com