You are on page 1of 11

Advanced Data Structures

An introduction

Cpt S 223. School of EECS, WSU 1


Topics
 Data structures
 (
(review)) stack,, list,, array,
y, BST
 (new) Trees, heaps, union-find, hash
tables, specialized (for spatial & strings)
 Algorithm design & analysis
 Sorting, graph algorithms
 Applications

Cpt S 223. School of EECS, WSU 2


So, what is a data structure?

A container for data that allows organized


access and manipulation

Cpt S 223. School of EECS, WSU 3


Why study data structures?
 Example problem
 Given: a set of N numbers
 Goal: search for number k
 Solution
 Store numbers in an array of size N
 Linearly scan array until k is found or array is
exhausted
 Number of checks 3 7 6 1 10 8 43
 Best case: 1
 Worst case: N
 Average case: N/2
Cpt S 223. School of EECS, WSU 4
Why study data structures?
 Solution #2
 Store numbers in a binary search tree
 Search tree until find k
7
 Number of checks
3 10
 Best case: 1
 Worst
o st case
case: log
og2N 1 6 8 43

 Average case: (log2N)/2

Cpt S 223. School of EECS, WSU 5


Analysis
 Does it matter?
 N vs
vs. log2N
N vs. Log N

120
linear (N)
100 Logarithmic (log N)

80

60

40

20

0
1 2 3 4 5 6 7 8 9 10
N

Cpt S 223. School of EECS, WSU 6


Analysis
 Assume
 N = 1,000,000,000
 1 billion (Walmart transactions in 100 days)
 1 GHz processor = 109 cycles per second
 1 cycle per transaction

 O(N) algorithm
 1 billion transactions = > 1 billion clock cycles
 O(lg N) algorithm
 1 billion transactions => 30 clock cycles
Cpt S 223. School of EECS, WSU 7
Example 2
 Scheduling job in a printer

 Write a code to manage the printer queue


 Functions to support
pp
 Insert, delete
 Special accommodations needed for:
 Priority
 Dynamic update
 Scheduling challenges

Cpt S 223. School of EECS, WSU 8


Example 3
 Exploring the Facebook connection network

 Write a code to tell who is connected to who


(directly or indirectly) through your Facebook
profile
fil

 Degrees of separation

Cpt S 223. School of EECS, WSU 9


Example 4
 Pattern matching

 Write a code to do Google search on your


web database

Cpt S 223. School of EECS, WSU 10


Summary
 Keep the data organized

 Ch i off d
Choice data
t structures
t t matters
tt

 Appropriate data structures ease design & improve


performance

 Ch ll
Challenge
 Design appropriate data structure & associated algorithms
for a problem
 A l
Analyze tto show
h iimproved
d performance
f

Cpt S 223. School of EECS, WSU 11

You might also like