插入排序之希尔排序

【排序】插入排序,希尔排序 以上是对插入排序和希尔排序的分析,是一种新的排序思想,其中的种种知识点也很碎很多,希望大家能够有所收获。 阅读详情
package demo4;

import java.util.Arrays;

public class ShellSort {

	public static void main(String[] args) {
		int[] arr = new int[] { 3, 5, 2, 7, 8, 1, 2, 0, 4, 7, 4, 3, 8 };
		System.out.println(Arrays.toString(arr));
		shellSort(arr);
		System.out.println(Arrays.toString(arr));
	}
	
	public static void shellSort(int[] arr) {
		int k = 1;
		// 遍历所有的步长
		for (int d = arr.length / 2; d > 0; d /= 2) {
			// 遍历所有有元素
			for (int i = d; i < arr.length; i++) {
				int count=0;
				count++;
				// 遍历本组中所有的元素
				for (int j = i - d; j >= 0; j -= d) {
					// 如果当前元素大于加上步长后的那个元素
					if (arr[j] > arr[j + d]) {
						int temp = arr[j];
						arr[j] = arr[j + d];
						arr[j + d] = temp;
					}
				}
				System.out.println(count);
			}
			System.out.println("第" + k + "次排序结果:" + Arrays.toString(arr));
			k++;
		}
	}

}

 

windows下玩转vllm:在wsl下安装vllm 当前,部署通义千问2.5-vl已经是一件箭在弦上,不得不发的事儿了。网上搜了一下,发现还是用vllm用的比较多。于是乎,这就开始尝试部署vllm。但是我们之前说了,vllm是不支持直接在windows上部署的,我们还得搞wsl或者docker。咱今天先尝试使用wsl进行安装哈。 阅读详情

相关推荐

视频帧插学习(三):ema-vfi代码拆解和分析

video interp EMA-VFI

mikhailbran的博客 708

数据结构——插入排序与希尔排序

数据结构——插入排序和希尔排序:干货十足,图文并茂,不容错过的优质好文,欢迎小伙伴们前来学习!!!

麦麦的博客 1904

Python遥感图像处理指南(2)-卫星影像分析MNDWI提取

在第一篇文章中,我们使用了我们导入的软件包中已定义的函数,如 rasterio 中的 open 和 read 以及 matplotlib 中的 imshow。现在,我们可以编写自己的函数了。函数是一段代码,它接收一些参数作为输入并返回输出(经过一些计算),可以在代码中多次重复使用,也可以被其他代码重用。在 Python 中定义一个新函数非常简单。return v在此语法示例中,arg1和arg2强制参数,应该传递给函数,否则会引发错误,而arg3是一个可选参数,如果是,则假定默认值 1从函数调用中省略。

gis收藏家的博客 1576

插入排序和希尔排序

今天给小伙伴们分享两个比较基础的排序算法,插入排序和希尔排序

Code_Allen的博客 1318

ConvLSTM时空预测实战代码详解

ConvLSTM代码复现

JaysonWong的博客 1万+

Cadence Orcad Capture原理图断线的检查与避免方法

在设计电路图中,尤其是直接借鉴别人的设计进行二次开发的过程中难免会遇到如下尴尬的情况。有没有眼神好的朋友发现图纸的哪里有不对劲的地方呢?

fydar的博客 3269

插入排序——希尔排序

希尔排序的实现,浅谈希尔排序的时间复杂度

m0_73693552的博客 1234

MATLAB代码转到FPGA代码

添加完文件之后,需要设置输入的数据类型,设置完之后点击Workflow Advisor。MATLAB文件包含一个功能实现文件和测试文件。对应FPGA中的功能文件和测试文件。然后,将功能文件和测试文件添加到相应位置。然后选择APP中的HDL Coder代码。首先需要编写好MATLAB文件。点击链接,就可以查看你看到的代码。可以自己生成代码的语言类型。

小柚子的博客 3062

排序——希尔排序、插入排序

本节复习排序中的希尔排序,希尔排序属于插入排序。希尔排序的代码和插入排序非常类似。思想却相对于插入排序来说复杂。在复习希尔排序之前, 我们需要先复习一下插入排序。

strive_mianyang的博客 1389

倍福--RS232自由口实现

RS232/485通信协议是在现场中常用到的,比如触摸屏、温控模块等设备控控制器做通信,会常用到此类协议,本文介绍RS232/485自由口通信的实现,并用PC调试助手进行测试。 目 录 软硬件版本 3 1.1. 倍福Beckhoff 3 1.1.1. 控制器硬件 3 1.1.2. 控制器软件 3 硬件连接 3 2.1. PC COM介绍 3 2.2. RS232/RS485连接 3 3.2.1. N030…………. 4 3.2.2. N031…………. 4 2.3. 实际线路连接 5 PLC程序 7 3

weixin_41883890的博客 3284

基于simulink的预测电流控制策略的三相逆变器仿真

本文详细介绍了在Simulink中实现基于预测电流控制策略的三相逆变器仿真方法。主要内容包括:准备工作(安装必要软件及工具箱)、构建三相逆变器基础模型、设计预测电流控制器(包含状态空间建模和控制器设计)、实现控制逻辑、添加示波器观察输出、配置仿真参数以及运行仿真分析结果。通过MATLAB代码示例和Simulink模块说明,展示了如何选择最优开关状态来最小化电流误差。该仿真方法为研究快速响应、高精度的逆变器控制提供了实用工具,但需注意实际应用中可能需要的调试工作。

amy_mhd的博客 274

【C语言】插入排序、希尔排序——动图展示

直接插入时间复杂度是ON2O(N^2)ON2,比如在排逆序数据的时候,但是在有序或接近有序的时间,效率很高,所以希尔排序就对这个缺陷进行了优化,预排序就可以很好解决的这个问题,希尔排序平均复杂度是ON1.3O(N^{1.3})ON1.3。

Eraser的博客 1577

【C语言】初识C语言(上篇)

初识C语言第一部分

StackFrame 4009

插入排序、希尔排序

这里定义一个gap,假设gap = 3,将降序序列{9,8,7,6,5,4,3,2,1,0} 按间隔为gap的 为一组进行插入排序,如9,6,3,0为一组,8,5,2为一组,7,4,1为一组,分成这样的三组插入排序,排完后序列变成{0,2,1,3,5,4,6,8,7,9} 将小的基本放在了前面,将大的基本放在了后面,实现了基本的有序,这就为最后一次的排序做了铺垫,这就是预排序。先排9,6,3,0这一组,再排8,5,2这一组,再排7,4,1这一组。因此,我们用数组个数n来控制gap,让它实现多组排序。

SAKURAjinx的博客 289

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

插入排序之折半插入排序、希尔排序

1.折半插入排序: 折半插入排序实际上是对直接插入排序的优化,通过折半查找来找到要插入的位置,再搬移元素,最后插入即可。 思路分析: 定义low为有序部分的第一个位置,high为有序部分的最后一个位置,通过折半查找的方法,不断更新low和high的位置,直到 low>high,此时high+1即为我们要插入的位置。 直接插入排序是在每一次比较时,就进行数据的搬移;而折半插入排序是在找到插入...

林林酱 636

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

c语言——插入排序与希尔排序

1.涉及知识点:基本输入输出,分支与循环语句。2.基本思想:将数组分为已排序区间和未排序区间,然后依次从未排序区间取出元素,插入到已排序区间的合适位置。基本思想:将待排序的数组分成若干个较小的子数组,对这些子数组进行插入排序,然后逐步缩小子数组的规模,直至最后整个数组有序。优化方向:希尔排序通过先使数组局部有序,再逐步扩大有序区域的方式,减少了元素的移动次数,从而提高了插入排序的效率。增量序列的选择和插入排序的实现方式对希尔排序的性能有影响,不同的增量序列可能导致不同的排序效果。例如这样的。

qq_34434522的博客 1382

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

插入排序,希尔排序

插入排序 插入排序是一种比较排序算法 核心思想 在每次遍历序列过程中,从序列中取出一个元素插入到有序序列中,形成新的有序序列,重复该过程,直到遍历完成,形成新的有序序列。 特点: 时间复杂度分析:O(N^2),如果序列在排序前已经是有序序列,则为O(N) 空间复杂度分析:O(1) 数据量较少时效率高。插入排序适合数据量少的情况 算法的实际运行效率优于选择排序和冒泡排序。 稳定排序 — 插入排序...

kevin的博客 640

从插入排序到希尔排序

从插入排序到希尔排序插入排序原理插入排序是一种简单直观的排序算法,其基本思想是通过将每个元素逐个插入到已排序的部分中,逐步构建一个有序序列。操作步骤初始化:将第 1 个元素视为已经有序的部分(初始时长度为 1)。遍历数组:从第 2 个元素开始,依次将其视为待插入的“新”元素。查找位置:在已排序部分中找到该元素的正确位置,并将其插入到适当的位置。从已排序部分的末尾向前查找,找到第 1 个小(大)于等...

不只会拍照的程序猿 1022

一种情况下插入排序比希尔排序要快

        我们都知道希尔排序是插入排序的优化。         希尔排序会在进行插入排序前把数列分组,然后会根据需要把数组内部的数字先进行顺序排列,最终减少插入排序时移动元素的次数,达到优化的目的。         但是我这边简化了部分插入排序的代码,结果在最后测试的时候,插入排序竟然会比希尔排序要快。这里似乎是说希尔排序的代码还能再继续优化?或者还有别的原因?这里我只能把该问题记录了。...

qq_35338695的博客 1437

插入排序与希尔排序

本文是插入排序和希尔排序的学习,本系列将逐步更新排序算法的学习,循序渐进的理解排序算法的精髓,所有的排序算法都介绍完之后,对实际使用中排序算法的最佳实践做一个总结,此后再深入jdk源码,看看jdk提供给我们的排序方法,都用到了怎样的实现...

coderZ666的博客 223

插入排序&希尔排序

【图文】插入排序 1.直接插入 2.希尔排序

TerryZjl的博客 1301

插入排序和希尔排序比较

今天六六给大家总结简单排序和复杂排序中的插入排序和希尔排序: 插入排序原理: a.把所有的元素分为两组,已经排序的和未排序的; b.找到未排序的组中的第一个元素,向已经排序的组中进行插入; c.倒叙遍历已经排序的元素,依次和待插入的元素进行比较,直到找到第一个元素小于等于待插入元素,那么就把待插入元素放到这个位置,其他的元素向后移动一位。 public class insert { public static void sort(Comparable[] a){ for(int i=1;i&lt

linpengwing的博客 1497
上一篇: 插入排序之直接插入排序
下一篇: 归并排序
小小哆啦的口袋
博客等级 码龄9年 33粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值