Comments (2)
上述算法由于从start开始比较导致效率并不比楼主高,甚至在近乎有序的数组中排序效率和完全无序序列相同,改进后则可以通过System.arraycopy()方法提升性能
void insertSort(int[] data) {
int length = data.length;
for (int i = 1; i < length; i++) {
int tmp = data[i];
int j = i;
while (j > 0 && data[j-1] > tmp) j--;
System.arraycopy(data, j, data, j + 1, i - j);
data[j] = tmp;
}
}
但此时近乎有序的序列排序时效率正常,完全无序序列排序时长比楼主多了1/3,目前未找明原因,我个人认为可能是我的方法还存在一些影响性能的缺陷,使用System.arraycopy方法应该是有助于性能提升的。我会继续寻找原因
from play-with-algorithms.
非常赞!不过使用标准库函数带来的效率提升不是这个课程的重点,所以在这里并不采纳你的建议。敬请谅解:)
from play-with-algorithms.
Related Issues (20)
- 选择排序的优化。 HOT 1
- 5.4二分查找树的查找一节的Java源码问题 HOT 1
- js插入排序优化后反而变慢了,和语言底层实现有关吗? HOT 1
- C++生成随机数 HOT 1
- 最大堆的插入自动扩展容量补充 HOT 1
- 二分搜索树的查找后继的函数似乎有点问题(##后面的函数,应该是调用successorFromAncestor()) HOT 1
- some HOT 1
- 插入排序外层循环应该是i=1 HOT 1
- 讲的很好,建议整理出书 HOT 1
- LinkedList的add和pop方法不能实现队列的效果 HOT 1
- 索引堆的反向查找 HOT 1
- 快速排序的2个问题 HOT 1
- IndexMaxHeap问题 HOT 1
- find(p) HOT 1
- 5.8节二分搜索树remove操作部分代码优化 HOT 2
- BST后继的子函数递归时有笔误 HOT 1
- One link in readme is not valid anymore HOT 1
- 关于第二章选择排序优化的问题 HOT 6
- bug- binary-search-tree : levelOrder HOT 1
- 为什么在头文件中实现函数 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from play-with-algorithms.