当前位置:网站首页>Exchange sort method
Exchange sort method
2022-06-22 11:01:00 【Short section senior】
Bubble sort ( Adjacency comparison method )
Bubbling
Exchange through adjacent records , The process of gradually changing the sequence to be sorted into an ordered sequence .
Algorithmic thought
The first 1 Trip to : From 1 A record begins , Scan the sequence of records to be sorted , If two adjacent records are in reverse order , Then switch places ( Eliminate a reverse order ), Last n A record is the record with the largest keyword .
The first 2 Trip to : Same as above , To the front n-1 Bubble sort of elements , Last n-1 A record is the record with the largest secondary key .
And so on , Until the first n-1 After the trip is completed ; Or if no reverse order is found during a certain bubble sorting process, it can be ended .








Algorithm analysis
The best situation : Orderly . Comparison times n-1 Time , Number of moves 0 Time , The time complexity is O(n).
The worst : The reverse . Comparison times n(n-1)/2 Time , Number of moves 3n(n-1)/2 Time , The time complexity is O(n2).
notes : Swap a move 3 Time .
Spatial complexity :O(1).
stability : Stable .
Quick sort
Key points of algorithm improvement
Bubbling : Exchanging adjacent elements can only eliminate one reverse order .
Quick typesetting : Exchange nonadjacent elements , Multiple reverse orders can be eliminated .
The basic idea
A quick line : Divide the sequence to be arranged into two sub tables , The keywords of the left table are smaller than those of the right table .
repeat , Until all sub tables are single records .
Pivot element : Boundary records of the left and right sub tables .
Benchmark records : The pivot element should be placed in the middle of the left and right child tables ( Reference position ), So the datum record is the same as the pivot element .
A quick line 













Selection of pivot elements : The first record 、 The last record 、 Intermediate records 、 Record of intermediate values 、 Random recording .
Algorithm analysis
The best situation : The length of the left and right sub tables after each division is the same , The time complexity is O(nlog2n), Call it the best average performance .
The worst : It's in order , The total number of comparisons n(n-1)/2, The time complexity is O(n2).
On average :Tavg(n)=klog2n, The time complexity is O(nlog2n).
Spatial complexity :O(log2n).
stability : unstable .
Welcome to join me for wechat exchange and discussion ( Please note csdn Add )
边栏推荐
- Start from the principle of MVC and knock on an MVC framework to bring you the pleasure of being a great God
- 今天,SysAK 是如何实现业务抖动监控及诊断?&手把手带你体验Anolis OS|第25-26期
- 定金预售的规则思路详解
- 机器人强化学习——Sim-to-Real Robot Learning from Pixels with Progressive Nets (2017)
- 线程常用调度方法
- Super simple C language Snake does not flash screen double buffer
- LeetCode Algorithm 剑指 Offer 24. 反转链表
- 2022 Shaanxi Provincial Safety Officer B certificate operation certificate examination question bank and online simulation examination
- Community article | mosn building subset optimization ideas sharing
- MySQL uses SQL statements to modify field length and field name
猜你喜欢

iNFTnews | 观点:市场降温或是让NFT应用走向台前的机会

CVPR 2022 oral | a new motion oriented point cloud single target tracking paradigm

On the routing tree of gin

解决win7任务栏谷歌浏览器chrome图标丢失、异常空白的问题

【直播回顾】战码先锋第六期:共建测试子系统,赋能开发者提高代码质量

Batch create / delete files, folders, modify file name suffixes

将有色液体图像转换成透明液体,CMU教机器人准确掌控向杯中倒多少水

Denso China adopts Oracle HCM cloud technology solution to accelerate the digital transformation of human resources

普乐蛙5d飞行影院5d动感影院体验馆设备7d多人互动影院

高考生父亲深夜自述,最在意的不是孩子成绩,转折点一点都不假
随机推荐
CVPR 2022 oral | a new motion oriented point cloud single target tracking paradigm
Redis common commands
普乐蛙5d飞行影院5d动感影院体验馆设备7d多人互动影院
How harmful is the code signature certificate once it is leaked
Laravel development article URL generator
高考生父亲深夜自述,最在意的不是孩子成绩,转折点一点都不假
6-9 应用间通信 - 子应用通信
Super simple C language Snake does not flash screen double buffer
laravel 开发 文章URL 生成器
2022陕西省安全员C证考试题库模拟考试平台操作
Reopen the terminal after NVM use or display the version before modification
微软 Edge 浏览器 Dev 104 发布,深 / 浅主题切换更加顺畅
MySQL每日面经【02】
学会用VisualStudio开发人员工具查看对象模型
iNFTnews | 观点:市场降温或是让NFT应用走向台前的机会
Investment transaction management
普乐蛙VR台风逃生体验VR灾害自救模拟系统VR科普知识设备
The data intelligence infrastructure upgrade window is approaching? See Chapter 9 how Yunji dingodb breaks through data pain points
2022 Shaanxi Provincial Safety Officer C certificate examination question bank simulated examination platform operation
云端极简部署Svelte3聊天室