Академический Документы
Профессиональный Документы
Культура Документы
Data Structures
Review 3
Tianming Liu
Department of Computer Science & Bioimaging Research Center
The University of Georgia
Priority Queues
5
8
16
18
12 10 56
20
Heaps: Insert
16
20 18
12
22
10
44
13
56
7
Heaps: Insert
16
20
12
18
22
7
44
13 10
8
56
16
20
7
12
18
22 44
9
13
56
10
Heaps: DeleteMin
Given the tree below
13
16
20
12
18
22
10
44
13
8
56
16
20
12
18
22
10
44
56
Heaps: DeleteMin
13
16
20
12
18
22
10
44
12
56
16
20
13
18
22
10
44
56
Sorting
Sorting
Selection Sort
Bubble Sort
Insertion Sort
Shellsort
Mergesort
Mergesort
(divide-and-conquer)
divide
sort
merge
Merging
Merge.
smallest
G
A
smallest
T
auxiliary array
Merging
Merge.
smallest
G
A
L
G
smallest
T
auxiliary array
Quicksort
Divide step:
Pick any element (pivot) v in S
Partition S {v} into two disjoint groups
S1 = {x S {v} | x <= v}
S2 = {x S {v} | x v}
S1
S2
A better partition
swap
5
pivot
3 12 19
4 19 3 12
Pseudo-code
Input: an array a[left, right]
QuickSort (a, left, right) {
if (left < right) {
pivot = Partition (a, left, right)
Quicksort (a, left, pivot-1)
Quicksort (a, pivot+1, right)
}
}
Sets
Collection of objects
MultiSet
Union
Intersection
Difference
Containment
Merge
Disjoint Sets
Disjoint Sets
head
tail
Set {f, g} head
tail
UNION of
two Sets
head
tail
Bit vectors
Trie
Patricia Tree
de la Briandais trees
Bit Vector
Bits[i] == 1 if ui S
Bits[i] == 0 if ui S
6 -- student number
1 = present
0 = absent
Hash Tables
Hash Tables solve these problems by using a much smaller array and mapping keys
with a hash function.
Let universe of keys U and an array of size m. A hash function h is a function from U
to 0m, that is:
h:U
k1
k2
k 3 k4
k6
(universe of keys)
0m
0
1
2
3
4
5
6
7
h (k2)=2
h (k1)=h (k3)=3
h (k6)=5
h (k4)=7
Insert 54
0
1
2
Insert 101
other
key key data
0
1
21
2
3
4
21
2
101
54
34
3
54
34
CHAIN
SAMs: solutions
K-d trees
point quadtrees
MX-quadtrees
K-d tree
A
D
B
B
C
C
D
A
The End