SlideShare a Scribd company logo
第 9 章 排序
 9.1 排序的基本概念
 9.2 插入排序
 9.3 交换排序
 9.4 选择排序
 9.5 归并排序
 9.6 单链表的排序算法
目的和要求
 目的:排序算法研究。对于数据逻辑结构是线性表、存储
结构是顺序、操作是排序,体会各种不同算
法实现。
• 内容:介绍插入、交换、选择、归并等多种经典排序算法
, 讨论各种排序算法所适用的存储结构,以及比较各
排序算法的性能。
• 要求:掌握直接插入、冒泡、直接选择等排序算法及其性
能, 理解希尔、快速、堆、归并等排序算法的设
计思想及 算法实现,熟悉提高算法性能的各种手段。
• 重点:每种排序算法设计思想,算法表达,算法分析与性
能评 价。
• 难点:希尔、快速、堆、归并等排序算法,性能较高算法
的 共同特点。
• 实验:排序算法设计及分析。
《数据结构( Java 版)(第 3 版)》
9.1 排序的基本概念
1. 排序的数据序列与关键字
2. 排序算法的性能评价
排序算法的时间复杂度由算法执行中的元素比
较次数和移动次数决定。
1. 排序算法的稳定性
设有 ai 和 aj ( i<j ), ai 位于 aj 之前,它们的
关键字相等 ki =kj ;排序后,如果 ai 仍在 aj
之前,则称这样的排序算法是稳定的,否则是
不稳定的。
《数据结构( Java 版)(第 3 版)》
9.2 插入排序
9.2.1 直接插入排序和折半插入排序
9.2.2 希尔排序
《数据结构( Java 版)(第 3 版)》
9.2.1 直接插入排序
1. 直
接
插
入
排
序
算
法
《数据结构( Java 版)(第 3 版)》
2. 直接插入排序算法分析
<1> 数据序列已排序 {1,2,3,4,5,6} (最好情
况)的时间复杂度为 O(n) 。
<2> 数据序列反序排列 {6,5,4,3,2,1} (最坏
情况)的时间复杂度为 。
<3> 数据序列随机排列的时间复杂度为
。
)( 2
nO
∑=
≈++=
+
=
n
i
n
nn
i
C
1
2
2
4
1
4
3
4
1
2
1
∑=
≈
+
==
n
i
nnni
M
1
2
44
)1(
2
)( 2
nO
《数据结构( Java 版)(第 3 版)》
3. 折半插入排序
用折半查找代替直接插入排序中的顺序查
找
《数据结构( Java 版)(第 3 版)》
9.2.2 希尔排序
《数据结构( Java 版)(第 3 版)》
9.3 交换排序
9.3.1 冒泡排序
9.3.2 快速排序
《数据结构( Java 版)(第 3 版)》
9.3.1 冒泡排序
《数据结构( Java 版)(第 3 版)》
9.3.2 快速排序
《数据结构( Java 版)(第 3 版)》
快速排序过程
《数据结构( Java 版)(第 3 版)》
9.4 选择排序
9.4.1 直接选择排序
9.4.2 堆排序
《数据结构( Java 版)(第 3 版)》
9.4.1 直接选择排序
∑
−
=
≈
−
=−=
1
1
2
22
)1(
)(
n
i
nnn
inC
《数据结构( Java 版)(第 3 版)》
9.4.2 堆排序




−=≤≤ ++ 1
2
,,2,1,02212
n
ikkkk iiii 且
《数据结构( Java 版)(第 3 版)》
( 1 )创建最小堆
《数据结构( Java 版)(第 3 版)》
( 2
)堆
排序
《数据结构( Java 版)(第 3 版)》
9.5 归并排序
《数据结构( Java 版)(第 3 版)》
一次归并
《数据结构( Java 版)(第 3 版)》
9.6 单链表的排序算法
1. 单链表的直接插入排序
2. 单链表的直接选择排序
《数据结构( Java 版)(第 3 版)》
3. 单链表的归并算法

More Related Content

Viewers also liked

Squis hsquash presentation
Squis hsquash presentationSquis hsquash presentation
Squis hsquash presentation
cshopis
 
3di All Services Nz Jan2012
3di All Services Nz Jan20123di All Services Nz Jan2012
3di All Services Nz Jan2012
justinechevin01
 
Battle of Shiloh
Battle of ShilohBattle of Shiloh
Battle of Shiloh
jciszek0705
 
Wedding Invitation
Wedding InvitationWedding Invitation
Wedding Invitation
psychoticseph
 
Toàn cảnh văn hóa, thể thao va du lịch - Số 1004
Toàn cảnh văn hóa, thể thao va du lịch - Số 1004Toàn cảnh văn hóa, thể thao va du lịch - Số 1004
Toàn cảnh văn hóa, thể thao va du lịch - Số 1004
longvanhien
 
Swot Ideas Factory
Swot Ideas FactorySwot Ideas Factory
Swot Ideas Factory
ideasfactory
 
Enterprise reinsurance-solutions-an-idea-whose-time-has-come
Enterprise reinsurance-solutions-an-idea-whose-time-has-comeEnterprise reinsurance-solutions-an-idea-whose-time-has-come
Enterprise reinsurance-solutions-an-idea-whose-time-has-come
Rod Fox
 
A lista 2
A lista 2A lista 2
Senior Software Constanta
Senior Software ConstantaSenior Software Constanta
Senior Software Constanta
Senior Software
 
Charla dono
Charla donoCharla dono
Charla dono
Mauro Jakes
 
Pps super photos-1
Pps  super photos-1Pps  super photos-1
Pps super photos-1
canhthep
 
Brief into to WPC
Brief into to WPCBrief into to WPC
Brief into to WPC
jd4est
 
Interlinking credit and insurance
Interlinking credit and insuranceInterlinking credit and insurance
Interlinking credit and insurance
ILRI
 

Viewers also liked (14)

Squis hsquash presentation
Squis hsquash presentationSquis hsquash presentation
Squis hsquash presentation
 
3di All Services Nz Jan2012
3di All Services Nz Jan20123di All Services Nz Jan2012
3di All Services Nz Jan2012
 
Battle of Shiloh
Battle of ShilohBattle of Shiloh
Battle of Shiloh
 
Wedding Invitation
Wedding InvitationWedding Invitation
Wedding Invitation
 
Toàn cảnh văn hóa, thể thao va du lịch - Số 1004
Toàn cảnh văn hóa, thể thao va du lịch - Số 1004Toàn cảnh văn hóa, thể thao va du lịch - Số 1004
Toàn cảnh văn hóa, thể thao va du lịch - Số 1004
 
Swot Ideas Factory
Swot Ideas FactorySwot Ideas Factory
Swot Ideas Factory
 
Benzine Prijs
Benzine PrijsBenzine Prijs
Benzine Prijs
 
Enterprise reinsurance-solutions-an-idea-whose-time-has-come
Enterprise reinsurance-solutions-an-idea-whose-time-has-comeEnterprise reinsurance-solutions-an-idea-whose-time-has-come
Enterprise reinsurance-solutions-an-idea-whose-time-has-come
 
A lista 2
A lista 2A lista 2
A lista 2
 
Senior Software Constanta
Senior Software ConstantaSenior Software Constanta
Senior Software Constanta
 
Charla dono
Charla donoCharla dono
Charla dono
 
Pps super photos-1
Pps  super photos-1Pps  super photos-1
Pps super photos-1
 
Brief into to WPC
Brief into to WPCBrief into to WPC
Brief into to WPC
 
Interlinking credit and insurance
Interlinking credit and insuranceInterlinking credit and insurance
Interlinking credit and insurance
 

Similar to 第09章 排序(java版)

排隊應用開發
排隊應用開發排隊應用開發
排隊應用開發建興 王
 
第04章 栈和队列(java版)
第04章  栈和队列(java版)第04章  栈和队列(java版)
第04章 栈和队列(java版)Yan Li
 
数据结构 总结与复习
数据结构 总结与复习数据结构 总结与复习
数据结构 总结与复习
Wang Yizhe
 
Spark tutorial
Spark tutorialSpark tutorial
Spark tutorial
Lin JiaMing
 
Java SE 7 技術手冊投影片第 09 章 - Collection與Map
Java SE 7 技術手冊投影片第 09 章 - Collection與MapJava SE 7 技術手冊投影片第 09 章 - Collection與Map
Java SE 7 技術手冊投影片第 09 章 - Collection與Map
Justin Lin
 
重构——关于可读性、原则和模式
重构——关于可读性、原则和模式重构——关于可读性、原则和模式
重构——关于可读性、原则和模式
cnfi
 
如何用 AngularJS 制作排序算法的动画
如何用 AngularJS 制作排序算法的动画如何用 AngularJS 制作排序算法的动画
如何用 AngularJS 制作排序算法的动画
Ken Chen
 

Similar to 第09章 排序(java版) (9)

排隊應用開發
排隊應用開發排隊應用開發
排隊應用開發
 
第04章 栈和队列(java版)
第04章  栈和队列(java版)第04章  栈和队列(java版)
第04章 栈和队列(java版)
 
数据结构 总结与复习
数据结构 总结与复习数据结构 总结与复习
数据结构 总结与复习
 
Spark tutorial
Spark tutorialSpark tutorial
Spark tutorial
 
No sql
No sqlNo sql
No sql
 
Java SE 7 技術手冊投影片第 09 章 - Collection與Map
Java SE 7 技術手冊投影片第 09 章 - Collection與MapJava SE 7 技術手冊投影片第 09 章 - Collection與Map
Java SE 7 技術手冊投影片第 09 章 - Collection與Map
 
重构——关于可读性、原则和模式
重构——关于可读性、原则和模式重构——关于可读性、原则和模式
重构——关于可读性、原则和模式
 
如何用 AngularJS 制作排序算法的动画
如何用 AngularJS 制作排序算法的动画如何用 AngularJS 制作排序算法的动画
如何用 AngularJS 制作排序算法的动画
 
Study research in April
Study research in AprilStudy research in April
Study research in April
 

More from Yan Li

Chapter 01 essentials final
Chapter 01 essentials finalChapter 01 essentials final
Chapter 01 essentials final
Yan Li
 
Chapter 05 essentials final
Chapter 05 essentials finalChapter 05 essentials final
Chapter 05 essentials final
Yan Li
 
Chapter 04 essentials final
Chapter 04 essentials finalChapter 04 essentials final
Chapter 04 essentials final
Yan Li
 
Chapter 02 essentials final
Chapter 02 essentials finalChapter 02 essentials final
Chapter 02 essentials final
Yan Li
 
Chapter 03 essentials final
Chapter 03 essentials finalChapter 03 essentials final
Chapter 03 essentials final
Yan Li
 
Introduction to om
Introduction to omIntroduction to om
Introduction to om
Yan Li
 
第10章 综合应用设计(java版)
第10章  综合应用设计(java版)第10章  综合应用设计(java版)
第10章 综合应用设计(java版)Yan Li
 
第06章 树和二叉树(java版)
第06章  树和二叉树(java版)第06章  树和二叉树(java版)
第06章 树和二叉树(java版)Yan Li
 
第05章 数组和广义表(java版)
第05章  数组和广义表(java版)第05章  数组和广义表(java版)
第05章 数组和广义表(java版)Yan Li
 
第03章 串(java版)
第03章  串(java版)第03章  串(java版)
第03章 串(java版)Yan Li
 
第02章 线性表(java版)
第02章  线性表(java版)第02章  线性表(java版)
第02章 线性表(java版)Yan Li
 
第01章 绪论(java版)
第01章  绪论(java版)第01章  绪论(java版)
第01章 绪论(java版)Yan Li
 
第07章 图(java版)
第07章  图(java版)第07章  图(java版)
第07章 图(java版)Yan Li
 

More from Yan Li (13)

Chapter 01 essentials final
Chapter 01 essentials finalChapter 01 essentials final
Chapter 01 essentials final
 
Chapter 05 essentials final
Chapter 05 essentials finalChapter 05 essentials final
Chapter 05 essentials final
 
Chapter 04 essentials final
Chapter 04 essentials finalChapter 04 essentials final
Chapter 04 essentials final
 
Chapter 02 essentials final
Chapter 02 essentials finalChapter 02 essentials final
Chapter 02 essentials final
 
Chapter 03 essentials final
Chapter 03 essentials finalChapter 03 essentials final
Chapter 03 essentials final
 
Introduction to om
Introduction to omIntroduction to om
Introduction to om
 
第10章 综合应用设计(java版)
第10章  综合应用设计(java版)第10章  综合应用设计(java版)
第10章 综合应用设计(java版)
 
第06章 树和二叉树(java版)
第06章  树和二叉树(java版)第06章  树和二叉树(java版)
第06章 树和二叉树(java版)
 
第05章 数组和广义表(java版)
第05章  数组和广义表(java版)第05章  数组和广义表(java版)
第05章 数组和广义表(java版)
 
第03章 串(java版)
第03章  串(java版)第03章  串(java版)
第03章 串(java版)
 
第02章 线性表(java版)
第02章  线性表(java版)第02章  线性表(java版)
第02章 线性表(java版)
 
第01章 绪论(java版)
第01章  绪论(java版)第01章  绪论(java版)
第01章 绪论(java版)
 
第07章 图(java版)
第07章  图(java版)第07章  图(java版)
第07章 图(java版)
 

第09章 排序(java版)