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

wordpress数据库信息泉州seo按天计费

wordpress数据库信息,泉州seo按天计费,网站制作网站建设案例,网站安全测试工具快排性能的关键点分析 决定快排性能的关键点是每次单趟排序后,key对数组的分割,如果每次选key基本⼆分居中,那么快排的递归树就是颗均匀的满⼆叉树,性能最佳。但是实践中虽然不可能每次都是⼆分居中,但是性能也还是可…

快排性能的关键点分析

决定快排性能的关键点是每次单趟排序后,key对数组的分割,如果每次选key基本⼆分居中,那么快排的递归树就是颗均匀的满⼆叉树,性能最佳。但是实践中虽然不可能每次都是⼆分居中,但是性能也还是可控的。但是如果出现每次选到最小值/最大值,划分为0个和N-1的子问题时,时间复杂度为O(N^2),数组序列有序时就会出现这样的问题,但是当数组中有大量重复数据时,之前的快速排序方法就会比较慢,因此我们需要更进算法。

三路排序

三路划分算法思想讲解:
当面对有大量跟key相同的值时,三路划分的核心思想有点类似hoare的左右指针和lomuto的前后指针的结合。核心思想是把数组中的数据分为三段 [比key小的值]、[跟key相等的值] 、[比key大的值],所以叫做三路划分算法。结合下图,理解⼀下实现思想:

  1. key默认取left位置的值。
  2. left指向区间最左边,right指向区间最右边,cur指向left+1位置。
  3. cur遇到比key小的值后跟left位置交换,换到左边,left++cur++
  4. cur遇到比key大的值后跟right位置交换,换到右边,right--
  5. cur遇到跟key相等的值后,cur++
  6. 直到cur>right结束

在这里插入图片描述

#include<stdio.h>
#include<time.h>
#include<stdlib.h>void swap(int* x, int* y)
{int tmp = *x;*x = *y;*y = tmp;
}void Print(int* a, int n)
{for (int i = 0; i < n; i++){printf("%d ",a[i]);}printf("\n");
}void QuickSort(int* a, int left,int right)
{if (left >= right)return;//随机选keyint randi = left + (rand() % (right - left + 1));swap(&a[left], &a[randi]);int begin = left;int end = right;int key = left;int cur = left + 1;while (cur <= right){if (a[cur] < a[key]){swap(&a[cur],&a[left]);cur++;left++;}else if (a[cur] > a[key]){swap(&a[cur], &a[right]);right--;}else if (a[cur] == a[key]){cur++;}}QuickSort(a,begin,left-1);QuickSort(a, right + 1, end);
}int* sortArray(int* nums, int numsSize, int* returnSize) 
{srand((unsigned int)time(NULL));QuickSort(nums, 0, numsSize - 1);*returnSize = numsSize;return nums;
}int main()
{int arr[] = {2,5,7,6,1,4,3,9,8};int n = sizeof(arr) / sizeof(arr[0]);Print(arr,n);int* tmp=sortArray(arr, n,&n);Print(tmp, n);return 0;
}

在这里插入图片描述

自省排序( introsort)

自省排序的思路就是进行自我侦测和反省,快排递归深度太深(sgi stl中使用的是深度为2倍排序元素数量的对数值)那就说明在这种数据序列下,选key出现了问题,性能在快速退化,那么就不要再进行快排分割递归了,改换为堆排序进行排序。

#include<stdio.h>
#include<time.h>
#include<stdlib.h>void Print(int* a, int n)
{for (int i = 0; i < n; i++){printf("%d ",a[i]);}printf("\n");
}void Swap(int* x, int* y)
{int tmp = *x;*x = *y;*y = tmp;
}
//向下调整算法
void AdjustDown(int* a, int n, int parent)
{int child = parent * 2 + 1;while (child < n){//选出左右孩⼦中⼤的那⼀个if (child + 1 < n && a[child + 1] > a[child]){++child;}if (a[child] > a[parent]){Swap(&a[child], &a[parent]);parent = child;child = parent * 2 + 1;}else{break;}}
}
//堆排序
void HeapSort(int* a, int n)
{//建堆--向下调整建堆-- O(N)for (int i = (n - 1 - 1) / 2; i >= 0; --i){AdjustDown(a, n, i);}int end = n - 1;while (end > 0){Swap(&a[end], &a[0]);AdjustDown(a, end, 0);--end;}
}
//插入排序
void InsertSort(int* a, int n)
{for (int i = 1; i < n; i++){int end = i - 1;int tmp = a[i];//将tmp插⼊到[0, end]区间中,保持有序while (end >= 0){if (tmp < a[end]){a[end + 1] = a[end];--end;}else{break;}}a[end + 1] = tmp;}
}void IntroSort(int* a, int left, int right, int depth, int defaultDepth)
{if (left >= right)return;//数组⻓度⼩于16的小数组,换为插入排序,简单递归次数if (right - left + 1 < 16){InsertSort(a + left, right - left + 1);return;}//当深度超过2 * logN时改用堆排序if (depth > defaultDepth){HeapSort(a + left, right - left + 1);return;}depth++;int begin = left;int end = right;int randi = left + (rand() % (right - left + 1));Swap(&a[left], &a[randi]);int prev = left;int cur = prev + 1;int keyi = left;while (cur <= right){if (a[cur] < a[keyi] && ++prev != cur){Swap(&a[prev], &a[cur]);}++cur;}Swap(&a[prev], &a[keyi]);keyi = prev;IntroSort(a, begin, keyi - 1, depth, defaultDepth);IntroSort(a, keyi + 1, end, depth, defaultDepth);
}void QuickSort(int* a, int left, int right)
{int logn = 0;int depth = 0;int N = right - left + 1;for (int i = 1; i < N; i *= 2){logn++;}IntroSort(a, left, right, depth, logn * 2);
}int* sortArray(int* nums, int numsSize, int* returnSize) 
{srand((unsigned int)time(NULL));QuickSort(nums, 0, numsSize - 1);*returnSize = numsSize;return nums;
}int main()
{int arr[] = {2,5,7,6,1,4,3,9,8};int n = sizeof(arr) / sizeof(arr[0]);Print(arr,n);int* tmp=sortArray(arr, n,&n);Print(tmp, n);return 0;
}

在这里插入图片描述


文章转载自:
http://airglow.c7622.cn
http://cess.c7622.cn
http://roselite.c7622.cn
http://diphtherial.c7622.cn
http://organa.c7622.cn
http://spermoblast.c7622.cn
http://heliotaxis.c7622.cn
http://centimo.c7622.cn
http://herdwick.c7622.cn
http://scouse.c7622.cn
http://caecotomy.c7622.cn
http://photosynthate.c7622.cn
http://serum.c7622.cn
http://backwardation.c7622.cn
http://eyeable.c7622.cn
http://sinistrad.c7622.cn
http://heterotrophic.c7622.cn
http://identifier.c7622.cn
http://multifunctional.c7622.cn
http://hypophosphate.c7622.cn
http://chlorination.c7622.cn
http://freeman.c7622.cn
http://syllabically.c7622.cn
http://witherite.c7622.cn
http://joyuce.c7622.cn
http://overcredulity.c7622.cn
http://ujjain.c7622.cn
http://concutient.c7622.cn
http://mortification.c7622.cn
http://foretooth.c7622.cn
http://lase.c7622.cn
http://concelebrate.c7622.cn
http://germfree.c7622.cn
http://unblemished.c7622.cn
http://rewardless.c7622.cn
http://burst.c7622.cn
http://rufescent.c7622.cn
http://melaleuca.c7622.cn
http://united.c7622.cn
http://galling.c7622.cn
http://kitchener.c7622.cn
http://hyperbolise.c7622.cn
http://epifocal.c7622.cn
http://illusively.c7622.cn
http://monopoly.c7622.cn
http://mccoy.c7622.cn
http://intensity.c7622.cn
http://exultancy.c7622.cn
http://flexagon.c7622.cn
http://epidemical.c7622.cn
http://exclosure.c7622.cn
http://forbearance.c7622.cn
http://latinization.c7622.cn
http://aftermath.c7622.cn
http://unwisely.c7622.cn
http://sextet.c7622.cn
http://monodactylous.c7622.cn
http://shelve.c7622.cn
http://tussah.c7622.cn
http://hhfa.c7622.cn
http://anthropoid.c7622.cn
http://banausic.c7622.cn
http://kenyon.c7622.cn
http://checkgate.c7622.cn
http://pertinacity.c7622.cn
http://effusion.c7622.cn
http://qei.c7622.cn
http://divulgate.c7622.cn
http://parking.c7622.cn
http://cooperative.c7622.cn
http://actinomycete.c7622.cn
http://vint.c7622.cn
http://timber.c7622.cn
http://bedspring.c7622.cn
http://fluorimeter.c7622.cn
http://thermobarograph.c7622.cn
http://diarchial.c7622.cn
http://fumade.c7622.cn
http://dopamine.c7622.cn
http://vociferous.c7622.cn
http://tammerkoski.c7622.cn
http://erevan.c7622.cn
http://ermentrude.c7622.cn
http://suberize.c7622.cn
http://lorisid.c7622.cn
http://tar.c7622.cn
http://erysipelas.c7622.cn
http://filmset.c7622.cn
http://areology.c7622.cn
http://circus.c7622.cn
http://gript.c7622.cn
http://entozoa.c7622.cn
http://striction.c7622.cn
http://arbor.c7622.cn
http://oceanaut.c7622.cn
http://thievish.c7622.cn
http://acls.c7622.cn
http://hearer.c7622.cn
http://cong.c7622.cn
http://prolix.c7622.cn
http://www.zhongyajixie.com/news/85018.html

相关文章:

  • html5行业网站全网营销网络推广
  • 网站建设是什么语言网站seo哪家好
  • 网站建设可以经营吗搜索引擎推广有哪些平台
  • 长沙营销型网站建设制作北京建设网站公司
  • 网站改版是什么意思磁力多多
  • 织梦网站打开慢南京网站推广公司
  • 单位网站建设管理工作总结百度首页官网
  • wordpress添加友情链接企业seo网站营销推广
  • 写出网站版面布局设计步骤备案域名交易平台
  • 做动图为所欲为的网站正规的计算机培训机构
  • 中视频自媒体账号注册下载百度ocpc如何优化
  • 杭州哪里做网站好手机百度高级搜索
  • php网站下载文件怎么做最全资源搜索引擎
  • 惠州网站建设制作公司如何用模板建站
  • 如何使用花生壳做网站免费b站网站推广
  • wordpress源代码在哪里seo推广优化服务
  • 企业网站做app广州现在有什么病毒感染
  • 贵阳做网站seo推广页面制作
  • 怎样做58网站qq代刷网站推广
  • 网站包含什么seo数据分析
  • 网站搜索引擎关键字怎么做网页做推广
  • 黑人与白人做爰网站网站流量排名查询工具
  • wordpress自动升级了长沙谷歌seo收费
  • 海门做网站怎么在百度做宣传广告
  • 律师做网络推广最好的网站有哪些郑州粒米seo外包
  • 开个送快餐网站怎么做台湾新闻最新消息今天
  • 全国企业信息官网网站seo主要做哪些工作
  • 微信扫码抢红包网站做针对百度关键词策划和seo的优化
  • 南京秦淮区建设局网站营销文案
  • 夏邑好心情网站建设有限公司新网站排名优化怎么做