05demo-merge.ppt

Download Report

Transcript 05demo-merge.ppt

Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
smallest
A
G
A
smallest
L
O
R
H
I
M
S
T
auxiliary array
1
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
smallest
A
G
A
smallest
L
G
O
R
H
I
M
S
T
auxiliary array
2
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
smallest
A
G
A
L
G
smallest
O
H
R
H
I
M
S
T
auxiliary array
3
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
smallest
A
G
A
L
G
smallest
O
H
R
I
H
I
M
S
T
auxiliary array
4
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
smallest
A
G
A
L
G
smallest
O
H
R
I
H
L
I
M
S
T
auxiliary array
5
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
smallest
A
G
A
L
G
O
H
smallest
R
I
H
L
M
I
M
S
T
auxiliary array
6
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
smallest
A
G
A
L
G
O
H
smallest
R
I
H
L
M
I
O
M
S
T
auxiliary array
7
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
smallest
A
G
A
L
G
O
H
smallest
R
I
H
L
M
I
O
M
R
S
T
auxiliary array
8
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
first half
exhausted
A
G
A
L
G
O
H
R
I
smallest
H
L
M
I
O
M
R
S
S
T
auxiliary array
9
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
first half
exhausted
A
G
A
L
G
O
H
R
I
smallest
H
L
M
I
O
M
R
S
S
T
T
auxiliary array
10
Merging
Merge.
Keep track of smallest element in each sorted half.



Insert smallest of two elements into auxiliary array.
Repeat until done.
first half
exhausted
A
G
A
L
G
O
H
R
I
second half
exhausted
H
L
M
I
O
M
R
S
S
T
T
auxiliary array
11