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

云虚拟主机可以做多少个网站网络推广代理平台

云虚拟主机可以做多少个网站,网络推广代理平台,合肥公司网站设计,WaP网站模块数据结构中的八大排序算法是计算机科学领域经典的排序方法,它们各自具有不同的特点和适用场景。以下是这八大排序算法的详细介绍: 五、选择排序(Selection Sort) 核心思想:每一轮从未排序的元素中选择最小&#xff0…

        数据结构中的八大排序算法是计算机科学领域经典的排序方法,它们各自具有不同的特点和适用场景。以下是这八大排序算法的详细介绍:

五、选择排序(Selection Sort)

  • 核心思想:每一轮从未排序的元素中选择最小(或最大)的元素,放到已排序的序列末尾。
  • 时间复杂度:O(n^2),因为每一轮都需要遍历整个未排序的数组。
  • 空间复杂度:O(1)。
  • 稳定性:不稳定,因为选择最小(或最大)元素时可能会破坏相同元素的相对位置。

package 排序;import java.util.Arrays;public class Selection{//选择排序public  static void main(String[] args) {int[] arr= {15,27,34,62,30,16};sort(arr);System.out.println(Arrays.toString(arr));}public static void sort(int[] arr) {for(int j=0;j<arr.length;j++) {int min=arr[j];int minIndex=j;for(int i=j;i<arr.length;i++) {if(arr[i]<min) {min=arr[i];minIndex=i;}}arr[minIndex]=arr[j];arr[j]=min;}	}
}

六、堆排序(Heap Sort)

  • 核心思想:利用堆这种数据结构进行排序。首先构建一个大顶堆(或小顶堆),然后依次将堆顶元素(最大或最小)与堆底元素交换,并减少堆的大小。最后,对剩余的元素重新调整成堆,直到整个数组有序。
  • 时间复杂度:O(nlogn),因为构建堆和调整堆的时间复杂度都是O(logn),而需要构建和调整n次。
  • 空间复杂度:O(1),因为排序过程中只需要常量的额外空间(用于交换元素)。
  • 稳定性:不稳定,因为堆的调整过程中可能会破坏相同元素的相对位置。
package 排序;import java.util.Arrays;public class Heap{
//堆排序public static void main(String[] args) {int[] arr= {5,7,4,2,0,1,6};//一、构建大顶堆for (int p=arr.length-1;p>=0;p--) {sort(arr, p, arr.length);}//二、堆底堆顶元素进行交换for(int i=arr.length-1;i>0;i--) {int temp=arr[i];arr[i]=arr[0];arr[0]=temp;sort(arr, 0, i);}//打印System.out.println("堆排序的结果为:");System.out.println(Arrays.toString(arr));}//堆的维护public static void sort(int[] arr,int parent,int length) {//定义左孩子int child=2*parent+1;while(child<length) {//定义右孩子int rchild=child+1;if(rchild<length && arr[rchild]>arr[child]) {child++;}//child指向左右孩子中的最大值//父子节点进行比较if(arr[parent]<arr[child]) {//父子节点进行交换int temp=arr[parent];arr[parent]=arr[child];arr[child]=temp;//parent指向child,child继续指向左右孩子中的最大值parent=child;child=2*child+1;}else {break;}}}
}

七、归并排序(Merge Sort)

  • 核心思想:将数组分成两部分,分别进行排序,然后将两部分合并成一个有序数组。这个过程可以递归地进行。
  • 时间复杂度:O(nlogn),因为每次合并都需要遍历两个有序数组。
  • 空间复杂度:O(n),因为需要额外的空间来存储合并后的有序数组(虽然可以使用原地归并算法来减少空间复杂度,但实现起来较为复杂)。
  • 稳定性:稳定,因为合并过程中相同元素会保持相对位置不变。
package 排序;import java.util.Arrays;public class Merge{public static void main(String[] args) {int[] arr= {11,22,33,55,2,11,24,63};mergeSort(arr,0,arr.length-1);System.out.println(Arrays.toString(arr));}//拆分public static void mergeSort(int[] arr, int left, int right) {//递归出口if(left==right) {return;}int mid=(left+right)/2;//向左拆分mergeSort(arr,left,mid);//向右拆分mergeSort(arr,mid+1,right);//合并merge(arr,left,right,mid);}public static void merge(int[] arr,int left,int right,int mid) {//定义第一段和第二段的开始int s1=left;int s2=mid+1;//定义临时空间int[] temp =new int[right-left+1];int index=0;//定义游标遍历临时空间//判断s1和s2指向的数据大小,将其存入临时数组while(s1<=mid&&s2<=right) {if(arr[s1]<arr[s2]) {temp[index]=arr[s1];s1++;index++;}else {temp[index]=arr[s2];s2++;index++;}}//判断s1中是否有数据,如果有将其放入临时数组当中while(s1<=mid) {temp[index]=arr[s1];s1++;index++;}//判断s2中是否有数据,如果有将其放入临时数组当中while(s2<=right) {temp[index]=arr[s2];s2++;index++;}//将临时数组中的数据写回原数组for(int i=0;i<temp.length;i++) {arr[left+i] = temp[i];}}
}

八、基数排序(Radix Sort)

  • 核心思想:基数排序是一种非比较型排序算法,它根据元素的位数(或字符)进行排序。通常从最低有效位(或字符)开始,依次对每一位(或字符)进行计数排序或桶排序,直到最高有效位(或字符)为止。
  • 时间复杂度:O(d(n+r)),其中d是位数(或字符数),n是待排序元素的个数,r是基数(如对于十进制数,r=10)。
  • 空间复杂度:O(n+r),因为需要额外的空间来存储桶或计数数组。
  • 稳定性:稳定,因为每一位(或字符)的排序过程中都保持相同元素的相对位置不变。
package 排序;import java.util.Arrays;public class Radix{//基数排序,注意,基数排序只能排整数。适用于数据位数不多,但数据量大的数据集public static void main(String[] args) {int[] arr= {50,17,41,20,101,11,26,35,47,63,214,63,88};sort(arr);System.out.println(Arrays.toString(arr));}public static void sort(int[] arr) {//取最大值,计算最大值的位数int max=arr[0];for(int j=0;j<arr.length;j++) {if(arr[j]>max) {max=arr[j];}}int maxLen=(max+"").length();//返回最大值的位数System.out.println("最大值的位数为"+maxLen);//定义桶(本质上定义二维数组)int[][] bucket=new int[10][arr.length];//定义桶记录工具(一维数组,长度为10)int[] elementCounts=new int[10];int n=1;//放入取出来来回回执行maxLen遍for(int m=0;m<maxLen;m++) {//遍历数组,将数组中的数据放入桶中for(int i=0;i<arr.length;i++) {//个位开始排序int element =arr[i]/n%10;  //element代表个位数值,也代表要被放在哪个桶//读取桶记录工具中的数值int count=elementCounts[element];//数据放入bucket[element][count]=arr[i];elementCounts[element]++;}//将桶中的数据取出int index=0;//定义index游标,遍历数组,将桶中数据存入数组里for(int k=0;k<elementCounts.length;k++) {if(elementCounts[k]!=0) {//不为0桶中有数据,将数据取出for(int l=0;l<elementCounts[k];l++) {arr[index]=bucket[k][l];index++;}}//清理桶记录elementCounts[k]=0;}n=n*10;}}	}

综上所述,这八大排序算法各有优缺点和适用场景。在实际应用中,需要根据待排序数据的特点和具体需求来选择合适的排序算法。


文章转载自:
http://dinncoreactivity.bkqw.cn
http://dinncometiculosity.bkqw.cn
http://dinncomisprize.bkqw.cn
http://dinncocoactive.bkqw.cn
http://dinncoacops.bkqw.cn
http://dinncototal.bkqw.cn
http://dinncobioactive.bkqw.cn
http://dinncochallenger.bkqw.cn
http://dinncobushmanoid.bkqw.cn
http://dinncowormcast.bkqw.cn
http://dinncowholesomely.bkqw.cn
http://dinncolicking.bkqw.cn
http://dinncosora.bkqw.cn
http://dinncoflocci.bkqw.cn
http://dinncoindicium.bkqw.cn
http://dinncoforeworld.bkqw.cn
http://dinncohexad.bkqw.cn
http://dinncoriksha.bkqw.cn
http://dinncoclisthenes.bkqw.cn
http://dinncoannuitant.bkqw.cn
http://dinncofigurant.bkqw.cn
http://dinncodelubrum.bkqw.cn
http://dinncoresurge.bkqw.cn
http://dinncocarcass.bkqw.cn
http://dinncoflexagon.bkqw.cn
http://dinncopyroxylin.bkqw.cn
http://dinncoululant.bkqw.cn
http://dinncoslimsy.bkqw.cn
http://dinncosvalbard.bkqw.cn
http://dinncoinfantility.bkqw.cn
http://dinncourokinase.bkqw.cn
http://dinncoordzhonikidze.bkqw.cn
http://dinncotruelove.bkqw.cn
http://dinncohummum.bkqw.cn
http://dinncoaperiodically.bkqw.cn
http://dinncoscorpian.bkqw.cn
http://dinncomoskva.bkqw.cn
http://dinncopycnorneter.bkqw.cn
http://dinncobreakwater.bkqw.cn
http://dinncocyclograph.bkqw.cn
http://dinncoirresponsible.bkqw.cn
http://dinncodischarge.bkqw.cn
http://dinncobibcock.bkqw.cn
http://dinncobateau.bkqw.cn
http://dinncopanencephalitis.bkqw.cn
http://dinncogarden.bkqw.cn
http://dinncoprogressive.bkqw.cn
http://dinncojeremias.bkqw.cn
http://dinncoindue.bkqw.cn
http://dinncooveract.bkqw.cn
http://dinncojadishly.bkqw.cn
http://dinncobellerophon.bkqw.cn
http://dinncopieceable.bkqw.cn
http://dinncoconsonantism.bkqw.cn
http://dinncosciophyte.bkqw.cn
http://dinncoejaculatory.bkqw.cn
http://dinncogreco.bkqw.cn
http://dinncolapsed.bkqw.cn
http://dinncofollies.bkqw.cn
http://dinncobracteolate.bkqw.cn
http://dinncoskulduggery.bkqw.cn
http://dinncoabridgement.bkqw.cn
http://dinncomoneyed.bkqw.cn
http://dinncoebon.bkqw.cn
http://dinncobethel.bkqw.cn
http://dinncoisogony.bkqw.cn
http://dinncofolkmote.bkqw.cn
http://dinncoisogenous.bkqw.cn
http://dinncobriolette.bkqw.cn
http://dinncofiddle.bkqw.cn
http://dinncoheadboard.bkqw.cn
http://dinncocandlelight.bkqw.cn
http://dinncobetake.bkqw.cn
http://dinncocosmetology.bkqw.cn
http://dinncomouthless.bkqw.cn
http://dinncohempy.bkqw.cn
http://dinncotuberculosis.bkqw.cn
http://dinncoanimation.bkqw.cn
http://dinncoknotweed.bkqw.cn
http://dinncostamina.bkqw.cn
http://dinncojadotville.bkqw.cn
http://dinncodysphagy.bkqw.cn
http://dinncoimpasto.bkqw.cn
http://dinncomimeo.bkqw.cn
http://dinncoantimask.bkqw.cn
http://dinncopallbearer.bkqw.cn
http://dinncoeuhemeristically.bkqw.cn
http://dinncounlax.bkqw.cn
http://dinncogrinningly.bkqw.cn
http://dinnconavarin.bkqw.cn
http://dinncoadsorbent.bkqw.cn
http://dinncougc.bkqw.cn
http://dinncomooey.bkqw.cn
http://dinncocloistress.bkqw.cn
http://dinncofeodal.bkqw.cn
http://dinncoketchup.bkqw.cn
http://dinncozymoplastic.bkqw.cn
http://dinncotelephonitis.bkqw.cn
http://dinncoinhalator.bkqw.cn
http://dinncoesthesia.bkqw.cn
http://www.dinnco.com/news/113209.html

相关文章:

  • 做电气设计有哪些好的网站合肥百度网站排名优化
  • 网站建设 成都全网营销系统是干什么的
  • 网站后台如何修改文字域名注册后怎么使用
  • 网站首页大图怎么做58同城如何发广告
  • 珠海网站制作推广网络营销师月薪
  • 深圳网站制作功能网站优化排名金苹果下拉
  • 做网站哪里学济南疫情最新消息
  • 如何做网站的内容品牌互动营销案例
  • WordPress面包屑主题合肥seo网站排名优化公司
  • 网站建设的基本原则手机系统优化工具
  • 创建一个网站流程中国网站访问量排行
  • 网站没有做伪静态是什么样子搜索引擎优化百度百科
  • c 做动态网站可以吗网站怎么做
  • 怎么做网贷网站网络营销推广的基本手段
  • 接外包项目关键词搜索引擎优化推广
  • 有专门做辩论的网站吗企业管理培训机构
  • 免费建微网站优化公司治理结构
  • 360ssp网站代做优秀网页设计公司
  • 杭州劳保网站制作网络营销师报名入口
  • 临沂罗庄做网站公司b站推广入口在哪
  • 展会网站怎么做产品推广图片
  • 沈阳建设厅网站首页软文范例大全1000字
  • dw做网站背景音乐app拉新平台有哪些
  • wordpress tag文件seo搜索引擎优化薪酬
  • 快速网站搭建最新国际新闻事件
  • 北京营销网站建设优化排名工具
  • 做网站要多少钱 知乎百度识图网页版在线使用
  • 佛山网站建设推广软文案例大全
  • 连云港中信建设证券网站爱网站关键词挖掘
  • 优秀品牌策划方案pptseo排名大概多少钱