- 浏览: 57233 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (117)
- RPC相关 (4)
- mvc_controller (3)
- mvc_model (3)
- maven (4)
- mvc_view (5)
- IO (2)
- 业务相关 (2)
- MQ (7)
- 搜索引擎 (3)
- zookeeper (2)
- 工具相关 (4)
- 编辑错误 (1)
- tomcat (1)
- 单元测试 (1)
- 负载均衡 (1)
- ubuntu (1)
- nginx (1)
- dubbo (2)
- 网络站点分发 (1)
- 电商-支付相关 (10)
- 电商订单业务相关 (3)
- Core java1 (3)
- Core Java (12)
- 多线程高并发(并发包/线程/锁) (10)
- 数据库+缓存 (17)
- springcloud (2)
- jvm (5)
- 日志相关 (1)
- 算法 (3)
- spring (2)
- 分布式一致性算法 (1)
最新评论
1.选择排序:不稳定,时间复杂度 O(n^2)
2.插入排序:稳定,时间复杂度 O(n^2)
3.冒泡排序:稳定,时间复杂度 O(n^2)
4.堆排序:不稳定,时间复杂度 O(nlog n)
5.归并排序:稳定,时间复杂度 O(nlog n)
6.快速排序:不稳定,时间复杂度 最理想 O(nlogn) 最差时间O(n^2)
7.希尔排序:不稳定,时间复杂度 平均时间 O(nlogn) 最差时间O(n^s) 1<s<2
快速排序:
采用递归,第一次以第一位作为中轴,高位放中轴右边(高位与地位置换),低位放中轴左边,再递归左边,递归右边。
https://www.cnblogs.com/0201zcr/p/4763806.html
二分法查找:
插入排序:
http://blog.csdn.net/booirror/article/details/45339387
两层循环,第一层顺序循环,第二层在未排序序列从后向前比较置换值,直到未排序序列最后值置替换为此次值。
插入排序原理:它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。
插入排序核心:假设第一个元素排好,之后的元素对排好的部分从后向前比较并逐一移动。
8 2 4 9 3 6 首先我们考虑数字2,假设后面的数字不存在(手中只有一张8,又抓来了2),那么显然2应该放在8的前面。
2 8 4 9 3 6 又抓来了一张4,现在大家都知道应该怎么办了吧?
2 4 8 9 3 6 又来了个9,没错,正好不用换顺序
2 4 8 9 3 6 同样的道理,考虑3该放的位置,显然放在2和4的中间
2 3 4 8 9 6 最后一个也是一样,最后得到从小到大的序列
2 3 4 6 8 9 完成排序
选择排序:
从左到右边一个一个区比较,左边已排序越来越多,右边未排序越来越少
冒泡排序:
原理:比较两个相邻的元素,将值大的元素交换至右端。
归并排序:
https://www.cnblogs.com/chengxiao/p/6194356.html
堆排序:
https://www.cnblogs.com/jingmoxukong/p/4303826.html
https://www.cnblogs.com/chengxiao/p/6129630.html
股票最佳买入时机:
二叉树层次遍历:借助队列Queue
二个数组怎样找出公共部分,两个数组的交集
整数数组按照绝对值排序
快速排序比较时用Math.abs()
2.插入排序:稳定,时间复杂度 O(n^2)
3.冒泡排序:稳定,时间复杂度 O(n^2)
4.堆排序:不稳定,时间复杂度 O(nlog n)
5.归并排序:稳定,时间复杂度 O(nlog n)
6.快速排序:不稳定,时间复杂度 最理想 O(nlogn) 最差时间O(n^2)
7.希尔排序:不稳定,时间复杂度 平均时间 O(nlogn) 最差时间O(n^s) 1<s<2
快速排序:
采用递归,第一次以第一位作为中轴,高位放中轴右边(高位与地位置换),低位放中轴左边,再递归左边,递归右边。
https://www.cnblogs.com/0201zcr/p/4763806.html
二分法查找:
package test_yhl.thread; public class MinAbsTest{ private static int findLocation(int[] testInt, int value) { int left = 0; int right = testInt.length-1; int LocationValue = 0; while(left<= right) {//= int middle = (right+left)/2;//+,放在while里面 if (value < testInt[middle]) { right = middle-1;//-1 }else if(value > testInt[middle]){ left = middle+1;//+1 } else{ LocationValue= middle; break;//break; } } return LocationValue; } public static void main(String[] args) throws InterruptedException{ int[] testInt = new int[]{3,10,29,43,48,74,86,300};//new int[]{} System.out.println(findLocation(testInt,300)); } }
插入排序:
http://blog.csdn.net/booirror/article/details/45339387
两层循环,第一层顺序循环,第二层在未排序序列从后向前比较置换值,直到未排序序列最后值置替换为此次值。
插入排序原理:它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。
插入排序核心:假设第一个元素排好,之后的元素对排好的部分从后向前比较并逐一移动。
package test_yhl.thread; import java.util.Arrays; public class MinAbsTest{ public static void main(String[] arg) { int[] testInts = new int[]{6,7,112,7,12,34}; int y = 0;// y在for外 for (int x=0; x<testInts.length; x++) { int tem = testInts[x]; //必须定义临时testInts[x] for (y=x; y>0 && tem < testInts[y-1]; y--) { testInts[y] = testInts[y-1];//[y] [y-1] } testInts[y] = tem;// [y] } System.out.println(Arrays.toString(testInts)); } }
8 2 4 9 3 6 首先我们考虑数字2,假设后面的数字不存在(手中只有一张8,又抓来了2),那么显然2应该放在8的前面。
2 8 4 9 3 6 又抓来了一张4,现在大家都知道应该怎么办了吧?
2 4 8 9 3 6 又来了个9,没错,正好不用换顺序
2 4 8 9 3 6 同样的道理,考虑3该放的位置,显然放在2和4的中间
2 3 4 8 9 6 最后一个也是一样,最后得到从小到大的序列
2 3 4 6 8 9 完成排序
选择排序:
从左到右边一个一个区比较,左边已排序越来越多,右边未排序越来越少
package test_yhl.thread; import java.util.Arrays; public class MinAbsTest{ static int z; public static void main(String[] arg) { int[] a = new int[]{16,7,338,12,34,112}; int n=a.length; int i,j,k; for(i=0; i<n; i++){ k=i; for(j=i+1; j<n;j++){ if(a[k] > a[j]){// [k] [j] k=j; } } if(a[k]!=a[i]) { int tem = a[i]; a[i] = a[k]; a[k] = tem; } } System.out.printf(Arrays.toString(a)); } }
冒泡排序:
原理:比较两个相邻的元素,将值大的元素交换至右端。
package test_yhl.thread; import java.util.Arrays; public class MinAbsTest{ static int z; public static void main(String[] arg) { int[] a = new int[]{-13,-32,-8,5512,6,34,7,338,112}; int i,j; for(i =0;i<a.length-1;i++) { for(j=0; j<a.length-1-i; j++) { // -1-i if(a[j]>a[j+1]) { //如果是绝对值排序 if(Math.abs(a[j])>Math.abs(a[j+1])) { // Math.pow(b,2);表示b的平方 int tem = a[j]; a[j] = a[j+1]; a[j+1] = tem; } } } System.out.println(Arrays.toString(a)); } }
归并排序:
https://www.cnblogs.com/chengxiao/p/6194356.html
package org.xdemo.example.SpringActivemq.service.consumer; import java.util.Arrays; public class ConsumerTest { public static void main(String[] args) throws Exception { int []arr = {9,8,7,6,5,4,3,2,1}; int []temp = new int[arr.length];//在排序前,先建好一个长度等于原数组长度的临时数组,避免递归中频繁开辟空间 sort(arr,0,arr.length-1,temp); System.out.println(Arrays.toString(arr)); } private static void sort(int[] arr,int left,int right,int []temp){ if(left<right){ int mid = (left+right)/2; sort(arr,left,mid,temp);//左边归并排序,使得左子序列有序 sort(arr,mid+1,right,temp);//右边归并排序,使得右子序列有序 merge(arr,left,mid,right,temp);//将两个有序子数组合并操作 // 第一个子组合式,left到mid;第二个子组合是mid+1到right。 } } private static void merge(int[] arr,int left,int mid,int right,int[] temp){ int i = left;//左序列指针 int j = mid+1;//右序列指针 int t = 0;//临时数组指针 while (i<=mid && j<=right){ // <= if(arr[i]<=arr[j]){ temp[t++] = arr[i++]; }else { temp[t++] = arr[j++]; } } while(i<=mid){//将左边剩余元素填充进temp中 <= temp[t++] = arr[i++]; } while(j<=right){//将右序列剩余元素填充进temp中<= temp[t++] = arr[j++]; } t = 0; //将temp中的元素全部拷贝到原数组中 while(left <= right){ //<= arr[left++] = temp[t++]; } } }
堆排序:
https://www.cnblogs.com/jingmoxukong/p/4303826.html
https://www.cnblogs.com/chengxiao/p/6129630.html
股票最佳买入时机:
int aa[] = {1,8,6,3,5,9,11,10,6}; int min = aa[0]; int max = 0; // 最大收益 for (int i =0; i<aa.length; i++) { if(aa[i] < min) { min = aa[i]; } if(aa[i] - min > max) { max = aa[i] - min ; } } System.out.println(max); //10
二叉树层次遍历:借助队列Queue
VacantCountVo vacantCountVo2 = new VacantCountVo(); vacantCountVo2.setValue(9); VacantCountVo vacantCountVo3 = new VacantCountVo(); vacantCountVo3.setValue(20); VacantCountVo vacantCountVo1 = new VacantCountVo(); vacantCountVo1.setValue(3); vacantCountVo1.setLeft(vacantCountVo2); vacantCountVo1.setRight(vacantCountVo3); Queue<VacantCountVo> queue = new LinkedList<>(); queue.add(vacantCountVo1); List<List<Integer>> listList = new ArrayList<>(); while (!queue.isEmpty()) { List<Integer> list = new ArrayList<>(); int count = queue.size(); while(count > 0) { VacantCountVo vacantCountVo4 = queue.poll(); if (vacantCountVo4.getLeft() != null) { queue.add(vacantCountVo4.getLeft()); } if (vacantCountVo4.getRight() != null) { queue.add(vacantCountVo4.getRight()); } list.add(vacantCountVo4.getValue()); count --; } listList.add(list); } System.out.println(JSON.toJSONString(listList)); // [[3],[9,20]]
二个数组怎样找出公共部分,两个数组的交集
class Solution { public int[] intersection(int[] nums1, int[] nums2) { HashSet<Integer> set = new HashSet<>(); int c[] = null; for(int i = 0;i<nums1.length;i++) { for(int j=0; j<nums2.length;j++){ if(nums1[i] == nums2[j]) { set.add(nums1[i]); } } } Iterator<Integer> iterator = set.iterator(); int []a = new int[set.size()]; int z = 0; while (iterator.hasNext()){ a[z++] = iterator.next(); } return a; } }
class Solution { public int[] intersection(int[] arrayA, int[] arrayB) { Set<Integer> intersectionSet = new HashSet(); Arrays.sort(arrayA); Arrays.sort(arrayB); int indexArrayA = 0; int indexArrayB = 0; int sizeArrayA = arrayA.length; int sizeArrayB = arrayB.length; while (indexArrayA < sizeArrayA) { for (int i = indexArrayB; i < sizeArrayB; i++) { if (arrayA[indexArrayA] == arrayB[i]) { intersectionSet.add(arrayA[indexArrayA]); indexArrayA++; indexArrayB++; break; } else if (arrayA[indexArrayA] < arrayB[i]) { indexArrayA++; break; } else if (i == sizeArrayB - 1) { indexArrayA++; } } } Iterator<Integer> iterator = intersectionSet.iterator(); int []a = new int[intersectionSet.size()]; int i = 0; while (iterator.hasNext()){ a[i++] = iterator.next(); } return a; } }
整数数组按照绝对值排序
快速排序比较时用Math.abs()
相关推荐
PID算法相关资料数字PID控制算法C语言实现PID算法等源码及技术文档资料合集: 51单片机PID算法程序_三_增量式PID控制算法.pdf AN_SPMC75_0012 ARDUINO C语言PID算法.pdf C语言实现PID算法-27.pdf C语言实现PID算法-28...
1、 复习有关算法的基本原理,明确实验目的和要求; 2、 依据算法思想,绘制程序流程图; 3、 设计程序界面,要求操作方便; 4、 用C/C++语言编写源程序并调试、执行; 5、 分析实验结果 6、 对程序设计过程中出现...
SSD算法相关合集,收纳了以SSD算法为基础的改进目标检测算法
搜索算法 acm 相关 搜索算法 acm 相关 搜索算法 acm 相关
1. 复习有关算法,明确实验目的和要求; 2. 依据算法思想,绘制程序流程图(指定填充多边形); 3. 设计程序界面,要求操作方便; 4. 用C/C++语言编写源程序并调试、执行(最好能用动画显示填充过程); 5. 分析...
1) 用DLX汇编语言编写代码文件*.s(程序中应包括指令的数据相关、控制相关以及结构相关),以及相关的初始化寄存器文件*.i和数据文件*.d; 2) 观察程序中出现的数据相关、控制相关、结构相关,并指出三种相关的指令...
银行家算法pdf文献打包 共9篇 解晨,王瑜.多资源银行家算法研究与实现[J].电脑知识与技术,2013,9(18):4229-4233. 摘要:在通常情况下,计算机的资源有限,比如只有一台打印机或者只有有限的内存,并且很多资源是独占性...
算法详解系列图书共有4卷,本书是第1卷——算法基础。本书共有6章,主要介绍了4个主题,它们分别是渐进性分析和大O表示法、分治算法和主方法、随机化算法以及排序和选择。附录A和附录B简单介绍了数据归纳法和离散...
代码 去趋势互相关分析的DCCA算法代码 去趋势互相关分析的DCCA算法代码 去趋势互相关分析的DCCA算法代码 去趋势互相关分析的DCCA算法代码 去趋势互相关分析的DCCA算法代码 去趋势互相关分析的DCCA算法代码 去趋势互...
期望最大化算法,可以拆分为2个算法,1个E-Step期望化步骤,和1个M-Step最大化步骤。他是一种算法框架,在每次计算结果之后,逼近统计模型参数的最大似然或最大后验估计。详细介绍链接 Apriori Apriori算法是关联...
LMS算法的优点是收敛速度较快,且计算量小,但它也存在一些缺点,如收敛速度慢、要求元素必须是彼此独立的向量序列、信号的自相关矩阵的特征值大小相差较大时收敛速度较慢等。 二、RLS算法 RLS算法(Recursive ...
(填写要求:根据国家相关法律法规及政策要求,结合算法推荐服务提供者实际情况,制定完备的算法安全管理制度,相关制度应作为约束算法推荐服务提供者自身行为、规范算法研发和管理工作流程的重要依据。制度文件应...
应用马尔科夫链模型证明了遗传禁忌搜索算法是以概率1收敛到全局最优解的,并应用求解随机算法时间复杂度的方法,即求解算法的期望收敛时间,估算了该算法的时间复杂度,结果证明该算法的时间复杂度与所得解的多样性、...
基于遗传算法的BP神经网络优化算法,便于相关研究人员理解
十大算法各种算法
BM算法和sunday算法相关的原始论文
自己总结的有关遗传算法和神经网络算法的相关知识附-遗传算法与神经网络相结合的算法集合.rar 大家好: 这里有我自己总结搜集到的一些相关资料,希望对大家有所帮助。
Java数据挖掘18大算法实现和10大常见排序算法以及其他相关经典DM算法集合。 18大数据挖掘的经典算法以及代码实现,涉及到了决策分类,聚类,链接挖掘,关联挖掘,模式挖掘等等方面,后面都是相应算法的文章,希望能够...
对具有良好匹配特性的...K× K的处理元阵列 ( N= BK , K= M , B> 1) ,通过将参考图像分成 B× B个图像块就可利用该算法实现归一化积相关 图像分块匹配并行算法 .应用实验表明 ,本文设计的并行算法具有很好的并行效率
修订了动态规划和贪心算法相关内容。 流网络相关材料现在基于边上的全部流。 由于关于矩阵基础和strassen算法的材料移到了其他章,矩阵运算这一章的内容所占篇幅更小。 修改了对knuth-morris-pratt字符串...