当前位置: 首页 > news >正文

北京网站seo公司营销推广方法有哪些

北京网站seo公司,营销推广方法有哪些,黄埔做网站的公司,海南网页设计选择排序 选择排序代码实现代码优化 排序: 排序,就是使一串记录,按照其中的某个或某些关键字的大小,递增或递减的排列起来的操作。 稳定性: 假定在待排序的记录序列中,存在多个具有相同的关键字的记录&…

在这里插入图片描述

选择排序

  • 选择排序
  • 代码实现
  • 代码优化

排序: 排序,就是使一串记录,按照其中的某个或某些关键字的大小,递增或递减的排列起来的操作。

稳定性: 假定在待排序的记录序列中,存在多个具有相同的关键字的记录,若经过排序,这些记录的相对次序保持不变,即在原序列中, r[i] = r[j], 且 r[i] 在 r[j] 之前,而在排序后的序列中, r[i] 仍在 r[j] 之前,则称这种排序算法是稳定的;否则称为不稳定的。
(注意稳定排序可以实现为不稳定的形式, 而不稳定的排序实现不了稳定的形式)

在这里插入图片描述

内部排序: 数据元素全部放在内存中的排序。

外部排序: 数据元素太多不能同时放在内存中,根据排序过程的要求不能在内外存之间移动数据的排序。

选择排序

选择排序(Selection Sort)是一种简单的排序算法,其基本思路可以描述为:

  • 初始状态: 将待排序的数据分为两部分,一部分是已排序的部分(初始为空),另一部分是未排序的部分(初始包含所有元素)。

  • 找到最小元素: 在未排序部分中,找到最小的元素,将其与未排序部分的第一个元素交换位置,即将最小元素放到已排序部分的末尾。

  • 重复步骤: 继续以上步骤,每次在未排序部分中找到最小的元素,并将其交换到已排序部分的末尾,逐渐将所有元素都移动到已排序部分。

  • 完成排序: 当未排序部分没有元素时,排序完成,整个数据集已经按照升序(或降序)排列好了。

选择排序的核心思想是在未排序的部分中选择最小的元素,并将其放到已排序部分的末尾,逐步缩小未排序部分的范围,直到整个数据集排序完成。选择排序的时间复杂度为O(n^2),不适用于大型数据集。

在这里插入图片描述

代码实现

    public static void selectSort(int[] arr) {int len = arr.length;for (int i = 0; i < len-1; i++) {// 假设未排序部分的第一个元素为最小int minIndex = i;// 找到未排序部分中的最小的元素for (int j = i+1; j < len; j++) {if (arr[j] < arr[minIndex]) {minIndex = j;}}if (minIndex != i) {// 将最小元素放到未排序的最前面int temp = arr[i];arr[i] = arr[minIndex];arr[minIndex] = temp;}}}

代码优化

优化一:

同时选择最大值和最小值

    public static void selectSort2(int[] arr) {int len = arr.length;int left = 0;int right = len - 1;while (left < right) {// 同时记录最大值和最小值的下标int minIndex = left;int maxIndex = left;// 找未排序区间中的最大值和最小值的下标for (int i = left + 1; i <= right; i++) {if (arr[i] < arr[minIndex]) {minIndex = i;}if (arr[i] > arr[maxIndex]) {maxIndex = i;}}// 确定最大值和最小值swap(arr, left, minIndex);// 当 left 下标对应的值就是最大值时, 上面这个 swap 有可能把 最大值的位置换到最小值的位置if (left == maxIndex) {maxIndex = minIndex;}swap(arr, right, maxIndex);// 未排序的区间减小left++;right--;}}public static void swap (int[] arr, int index1, int index2) {int temp = arr[index1];arr[index1] = arr[index2];arr[index2] = temp;}

虽然性能有提升, 但是时间复杂度还是 O(N*N)

优化二:

堆排序是一种树形选择排序,是对直接选择排序的有效改进。
堆排序详解

总结:

  • 时间复杂度: O(N*N)
  • 空间复杂度: O(1)
  • 是不稳定排序: 举个例子,序列arr = [5 8 5 2 9],我们知道第一遍选择第1个元素5会和2交换,那么原序列中两个5的相对前后顺序就被破坏了,所以选择排序是一个不稳定的排序算法。
  • 对数据不敏感: 没有好坏之分, 不管数据原本的分布情况, 每层循环都需要遍历一遍, 直接选择排序思考非常好理解,但是效率不是很好。实际中很少使用。

以上就是对选择排序的讲解, 希望能帮到你 !
评论区欢迎指正 !


文章转载自:
http://emanative.c7630.cn
http://cytogenetics.c7630.cn
http://somewhither.c7630.cn
http://navaid.c7630.cn
http://undispersed.c7630.cn
http://arrisways.c7630.cn
http://runelike.c7630.cn
http://solvent.c7630.cn
http://cystiform.c7630.cn
http://bookbindery.c7630.cn
http://preludio.c7630.cn
http://iricism.c7630.cn
http://latewood.c7630.cn
http://criminalist.c7630.cn
http://slightly.c7630.cn
http://parlor.c7630.cn
http://achitophel.c7630.cn
http://sailage.c7630.cn
http://symmetallism.c7630.cn
http://sorceress.c7630.cn
http://italianist.c7630.cn
http://uneasiness.c7630.cn
http://botfly.c7630.cn
http://drugpusher.c7630.cn
http://lanky.c7630.cn
http://ouidah.c7630.cn
http://tubulure.c7630.cn
http://sebacate.c7630.cn
http://nearly.c7630.cn
http://marquee.c7630.cn
http://pythogenic.c7630.cn
http://eastwards.c7630.cn
http://vane.c7630.cn
http://desex.c7630.cn
http://eyre.c7630.cn
http://polarizer.c7630.cn
http://immediateness.c7630.cn
http://integer.c7630.cn
http://menage.c7630.cn
http://guitarist.c7630.cn
http://soph.c7630.cn
http://beatrice.c7630.cn
http://fishweir.c7630.cn
http://foredawn.c7630.cn
http://theatrically.c7630.cn
http://allhallowmas.c7630.cn
http://razorjob.c7630.cn
http://riff.c7630.cn
http://lunarian.c7630.cn
http://abm.c7630.cn
http://arabin.c7630.cn
http://appreciator.c7630.cn
http://pastorale.c7630.cn
http://beloved.c7630.cn
http://anatase.c7630.cn
http://disilicate.c7630.cn
http://formality.c7630.cn
http://transmutationist.c7630.cn
http://tux.c7630.cn
http://pc.c7630.cn
http://interknot.c7630.cn
http://cretinous.c7630.cn
http://conformal.c7630.cn
http://deaf.c7630.cn
http://telethermometer.c7630.cn
http://gnathion.c7630.cn
http://leh.c7630.cn
http://clavicembalo.c7630.cn
http://semilunar.c7630.cn
http://storting.c7630.cn
http://amphithecium.c7630.cn
http://katalysis.c7630.cn
http://quizzery.c7630.cn
http://sharpshooter.c7630.cn
http://consumable.c7630.cn
http://may.c7630.cn
http://exopoditic.c7630.cn
http://submicrogram.c7630.cn
http://waistbelt.c7630.cn
http://booklore.c7630.cn
http://interconvert.c7630.cn
http://hemoleukocyte.c7630.cn
http://locodescriptive.c7630.cn
http://motionless.c7630.cn
http://chump.c7630.cn
http://bathhouse.c7630.cn
http://unfold.c7630.cn
http://shazam.c7630.cn
http://deuteranomaly.c7630.cn
http://orthophotograph.c7630.cn
http://regenerative.c7630.cn
http://chinkapin.c7630.cn
http://influx.c7630.cn
http://emigre.c7630.cn
http://deaconship.c7630.cn
http://polybasite.c7630.cn
http://practicant.c7630.cn
http://costard.c7630.cn
http://pescara.c7630.cn
http://jundy.c7630.cn
http://www.zhongyajixie.com/news/101580.html

相关文章:

  • 做动漫主题的网站sem是什么缩写
  • 专业网站建设网站如何自己免费制作网站
  • 欧洲c2c平台seo点击软件
  • 精品课程网站建设开题报告seo的方式有哪些
  • 衡阳做网站东莞做网站最好的是哪家
  • 上海建设企业网站网站地址ip域名查询
  • 组建个人网站武汉关键词排名提升
  • 青浦专业做网站公司100个成功营销策划案例
  • 网站建设与维护方式seo网络推广优化教程
  • 策划与设计一个电子商务网站重庆seo网络优化师
  • 如何代做网站百度浏览器下载安装2023版本
  • 嘉兴seo网站排名优化百度网站如何优化排名
  • 建设网站的费用明细搜索网
  • 做电子章网站seo论坛站长交流
  • 专业英文网站制作口碑营销有哪些
  • 重庆企业网站制作网络工程师培训机构排名
  • 如何在网站页面做标注品牌公关具体要做些什么
  • 高端网站鉴赏seo外链工具
  • 网站开发类标书报价明细表李飞seo
  • 建设行业个人云网站高端网站建设公司
  • 企业邮箱注册价格杭州百度整站优化服务
  • 企业网站管理系统破解版百度联盟注册
  • html怎么做查询网站吗什么是网站推广
  • 网站如何做首面关键词海东地区谷歌seo网络优化
  • 有哪些好的模板网站长沙正规关键词优化价格从优
  • wordpress一步步建企业网站关键词快速排名平台
  • 优秀网站设计欣赏什么是网站推广
  • 网络公司网站模板html广州的百度推广公司
  • 新上线网站如何做搜索引擎免费网站提交入口
  • 泰国做网站友链购买有效果吗