b[k]insertlast((k.ppt


文档分类:建筑/环境 | 页数:约9页 举报非法文档有奖
1/9
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/9
文档列表 文档介绍
Part-G4 Bucket-Sort and Radix-Sort
0
1
2
3
4
5
6
7
8
9
B
1, c
7, d
7, g
3, b
3, a
7, e







程序设计网络课件教学设计多媒体课件 PPT文档
Bucket-Sort (§ )
Let S be a sequence of n (key, element) entries with keys in the range [0, N - 1]
Bucket-sort uses the keys as indices into an auxiliary array B of sequences (buckets)
Phase 1: Empty sequence S by moving each entry (k, o) into its bucket B[k]
Phase 2: For i = 0, …, N - 1, move the entries of bucket B[i] to the end of sequence S
Analysis:
Phase 1 takes O(n) time
Phase 2 takes O(n + N) time
Bucket-sort takes O(n + N) time
Algorithm bucketSort(S, N)
Input sequence S of (key, element) items with keys in the range [0, N - 1] Output sequence S sorted by increasing keys
B  array of N empty sequences
while ()
f  ()
(k, o)  (f)
B[k].insertLast((k, o))
for i  0 to N - 1
while B[i].isEmpty()
f  B[i].first()
(k, o)  B[i].remove(f)
((k, o))
程序设计网络课件教学设计多媒体课件 PPT文档
Example
Key range [0, 9]
7, d
1, c
3, a
7, g
3, b
7, e
1, c
3, a
3, b
7, d
7, g
7, e
Phase 1
Phase 2
0
1
2
3
4
5
6
7
8
9
B
1, c
7, d
7, g
3, b
3, a
7, e







程序设计网络课件教学设计多媒体课件 PPT文档
Properties and Extensions
Key-type Property
The keys are used as indices into an array and cannot be arbitrary objects
No parator
Stable Sort Property
The relative order

b[k]insertlast((k 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数9
  • 收藏数0 收藏
  • 顶次数0
  • 上传人cai.li.bin
  • 文件大小227 KB
  • 时间2018-09-30