Recursive Data Structures - PowerPoint PPT Presentation

1 / 68
About This Presentation
Title:

Recursive Data Structures

Description:

To save a tree between uses. e.g. An AVL dictionary used for spelling ... Written in preorder on a sequential file. Rebuild with a straight building program ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 69
Provided by: dtwma
Category:

less

Transcript and Presenter's Notes

Title: Recursive Data Structures


1
Chapter 3.4
  • Recursive Data Structures
  • Part 3
  • Storing Trees on Disk

2
Trees on Disk
  • To save a tree between uses
  • e.g. An AVL dictionary used for spelling
  • Saving pointer values is useless
  • Tree has to be
  • Written in preorder on a sequential file
  • Rebuild with a straight building program
  • Because central memory isn't large enough
  • Beware of virtual memory
  • Use multiway BTrees

3
Storing a Tree on diskWrite in PreOrder on
sequential file
h
l
d
f
root (left subtree) (right subtree) hdbacfegljikn
mo
4
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
5
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
d
6
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
d
b
7
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
d
b
a
8
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
d
b
a
c
9
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
d
b
f
a
c
10
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
d
b
f
a
c
e
11
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
d
f
12
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
l
d
f
13
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
l
d
b
f
j
a
c
e
g
14
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
l
d
b
f
j
a
c
e
g
i
15
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
l
d
f
16
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
l
d
b
f
j
n
e
g
17
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
h
l
d
b
f
j
n
a
c
e
g
i
k
m
18
Restoring a Tree from diskUse ordinary binary
tree building
hdbacfegljiknmo
19
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
h
20
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
h
d
21
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
h
d
b
22
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
h
b
23
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
h
b
a
24
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
h
b
a
c
25
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
h
b
a
c
f
26
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
h
b
a
c
f
e
27
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
f
b
a
c
e
h
28
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
f
b
a
c
e
h
g
29
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
f
b
a
c
e
h
g
l
30
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
f
b
a
c
e
h
g
l
j
31
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
h
b
a
c
f
l
e
g
j
32
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
h
b
a
c
f
l
e
g
j
i
33
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
h
b
a
c
f
j
e
g
i
l
34
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
d
h
b
a
c
f
j
e
g
i
l
k
35
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
h
j
d
b
f
i
l
a
c
e
g
k
36
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
h
j
d
b
f
i
l
a
c
e
g
k
n
37
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
h
j
d
b
f
i
l
a
c
e
g
k
n
m
38
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
h
l
d
b
f
j
n
a
c
e
g
i
k
m
39
Restoring a Tree from diskWhy not AVL tree
building ???
hdbacfegljiknmo
h
l
d
b
f
j
n
a
c
e
g
i
k
m
o
40
Storing a Tree on diskWhy not use InOrder or
PostOrder ?
h
l
d
f
InOrder (left subtree) root (right
subtree) abcdefghijklmno
41
Restoring a Tree from disk Why not use InOrder
???
abcdefghijklmno
a
b
42
Restoring a Tree from disk Why not use InOrder
???
abcdefghijklmno
a
b
c
43
Restoring a Tree from disk Why not use InOrder
???
abcdefghijklmno
a
b
c
d
44
Trees on Disk
  • To save a tree between uses
  • e.g. An AVL dictionary used for spelling
  • Saving pointer values is useless
  • Tree has to be
  • Written in preorder on a sequential file
  • Rebuild with a straight building program
  • Because central memory isn't large enough
  • Beware of virtual memory
  • Use multiway BTrees

45
BTrees
  • Objectives
  • Build well balanced trees
  • take properties of disk into account
  • space inexpensive
  • access time very long
  • data transfers by entire sectors or tracks
  • Minimize number of disk accesses
  • one node of the tree sector or track
  • leave spare space to minimize rebalancing

46
BTrees
  • Definitions
  • A node contains k ordered data items
  • n is a system dependant constant such that a
    sector or a track of the disk can hold 2n data
    items and 2n1 pointers
  • In the root 0 lt k lt 2n
  • In all other nodes n lt k lt 2n
  • A node has 0 or k1 successors
  • All nodes with 0 successors are at the same level

47
Multiway Trees
a
b
c
d
48
BTree Growth

XX
49
BTrees
Example n 2.
Insertion 25
50
BTrees
Insertion 25, 36
51
BTrees
Insertion 25, 36, 15
52
BTrees
Insertion 25, 36, 15, 31
53
BTrees
Insertion 25, 36, 15, 31, 18
54
BTrees
Insertion 25, 36, 15, 18, 31, 43
55
BTrees
Insertion 25, 36, 15, 18, 31, 43, 51
56
BTrees
Insertion 25, 36, 15, 18, 31, 43, 51, 66
57
BTrees
Insertion 25, 36, 15, 18, 31, 43, 51, 66, 42
58
BTrees
Insertion 25, 36, 15, 18, 31, 43, 51, 66, 42, 75
59
BTrees
Insertion 25, 36, 15, 18, 31, 43, 51, 66, 42,
75, 81
60
BTrees
Insertion 25, 36, 15, 18, 31, 43, 51, 66, 42,
75, 81
61
BTrees
Removal 75
15
18
51
66
75
81
62
BTrees
Removed 75
15
18
51
66
81

63
BTrees
Removal 15
15
18
64
BTrees
Removal 15
18

65
BTrees
Removed 15
18
25
66
BTrees
Removal 43
31
43


18
25
67
BTrees
Removal 43
31
42


18
25
36



68
BTrees
Removed 43
42



18
25
Write a Comment
User Comments (0)
About PowerShow.com