Sort by Distribution Counting - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Sort by Distribution Counting

Description:

Sort by Distribution Counting. special case with O(n) performance. Distribution Count ... 8,4,7,5,4,2,8,7,3,7,1,1,6,6,4,6,7,8,7,2,1. range: (1,8) Distribution ... – PowerPoint PPT presentation

Number of Views:1400
Avg rating:3.0/5.0
Slides: 6
Provided by: laurent192
Category:

less

Transcript and Presenter's Notes

Title: Sort by Distribution Counting


1
Sort by Distribution Counting
  • special case with O(n) performance

2
Distribution Count
  • required conditions
  • discrete values to sort
  • values in small range
  • example set
  • 8,4,7,5,4,2,8,7,3,7,1,1,6,6,4,6,7,8,7,2,1
  • range (1,8)

3
Distribution Count pseudocode
  • an array of integers, length n
  • tn
  • max max(a) min min(a)
  • range max min 1
  • countrange array of counts
  • for (i0 iltn i)
  • countai-min
  • count0--
  • for (j1 jltrange j)
  • countj countj-1
  • for (in-1 igt0 i--)
  • tcountai-min ai
  • countai-min--
  • for (i0 iltn i)
  • ai ti

4
Distribution Count example
14
16
21
21
14
20
17
20
16
19
20
15
16
19
17
14
a
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
8
(21 14 1)
range
counts of each value
3
1
3
2
0
2
3
2
count
0
1
2
3
4
5
6
7
last location of each value in sorted array
2
3
6
8
8
10
13
15
count
0
1
2
3
4
5
6
7
14
14
14
15
16
16
16
17
17
19
19
20
20
20
21
21
t
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
14
14
14
15
16
16
16
17
17
19
19
20
20
20
21
21
a
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
5
Distribution Count performance
  • O(max(n,range))
  • five for loops
  • four based on n
  • one based on range
  • constant factor is high (number of loops)
  • requires space for extra array (t)
Write a Comment
User Comments (0)
About PowerShow.com