当前位置:网站首页>快速排序、聚簇索引、寻找数据中第k大的值
快速排序、聚簇索引、寻找数据中第k大的值
2022-06-30 02:52:00 【PPDY小芽】
快速排序代码
public class Quick {
public static void main(String[] args) {
int [] nums = {
4,2,4,4,5,1,10,8,6,5,7,100};
System.out.println(Arrays.toString(nums));
QuickSort(nums,0,nums.length-1);
System.out.println(Arrays.toString(nums));
}
private static void QuickSort(int[] nums, int beigin, int end) {
if(beigin > end){
return ;
}
int i = beigin;
int j = end;
int v = nums[beigin];
while(i < j ){
while(i < j && nums[j]> v){
j--;
}
while(i < j && nums[i] <= v){
i++;
}
int temp = nums[j];
nums[j] = nums[i];
nums[i] = temp;
}
nums[beigin] = nums[i];
nums[i] = v;
QuickSort(nums,beigin,i-1);
QuickSort(nums,i+1,end);
}
}
聚簇索引和非聚簇索引的区别
聚簇索引:索引项的排序方式和表中数据记录排序方式一致的索引(字典中的拼音查找汉字)innodb
非聚集索引:索引顺序与物理存储顺序不同(字典中的偏旁部首查找汉字)myisam
聚簇索引的叶子节点就是数据节点,索引和数据在一起。
稠密索引和稀疏索引
稠密索引:每个索引键值对都对应一个索引项;
稀疏索引:只为某些搜索码值建立索引记录;
稀疏索引的优点是:所占用的空间更小,且插入和删除时维护开销也小。
寻找数据中第k大的值(基于快排)
public class Quic4 {
public int findKthLargest(int[] nums, int k) {
return getKth(nums, 0, nums.length - 1, nums.length - k);
}
public int getKth(int[] nums, int start, int end, int k) {
int pivot = nums[start];
int left = start;
int right = end;
while (left < right) {
while (left < right && nums[right] > pivot) {
right--;
}
while (left < right && nums[left] <= pivot) {
left++;
}
swap(nums, left, right);
}
swap(nums, left, start);
if (k == left) {
return pivot;
} else if (k < left) {
return getKth(nums, start, left - 1, k);
} else {
return getKth(nums, left + 1, end, k);
}
}
public void swap(int[] nums, int n1, int n2) {
int tmp = nums[n1];
nums[n1] = nums[n2];
nums[n2] = tmp;
}
}
边栏推荐
- 可视化HTA窗体设计器-HtaMaker 界面介绍及使用方法,下载 | HTA VBS可视化脚本编写
- Azure 开发者新闻快讯丨开发者6月大事记一览
- 外汇交易平台哪个好?有监管的资金就安全吗?
- Call collections Sort() method, compare two person objects (by age ratio first, and by name ratio for the same age), and pass lambda expression as a parameter.
- Detailed explanation of minimum stack
- What is a self signed certificate? Advantages and disadvantages of self signed SSL certificates?
- CMake教程系列-02-使用cmake代碼生成二進制
- How can redis+aop customize annotations to achieve flow restriction
- oracle怎么设置密码复杂度及超时退出的功能
- Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)
猜你喜欢

prompt learning 一个空格引发的血案

Welfare lottery | what are the highlights of open source enterprise monitoring zabbix6.0

自定义JvxeTable的按钮及备注下$set的用法

CMake教程系列-02-使用cmake代碼生成二進制

在php中字符串的概念是什么

Steam elements hidden in science and Technology Education

How to modify and add fields when MySQL table data is large

What is certificate transparency CT? How to query CT logs certificate logs?

FDA ESG regulation: digital certificate must be used to ensure communication security

Visual HTA form designer htamaker interface introduction and usage, Download | HTA VBS visual script writing
随机推荐
Recursion frog jumping steps problem
Redis+AOP怎么自定义注解实现限流
迅為恩智浦iTOP-IMX6開發平臺
[Postgres] Postgres database migration
SQLite use
怎么利用Redis实现点赞功能
Xunwei NXP itop-imx6 development platform
Azure developer news flash list of events of developers in June
Heavy attack -- ue5's open source digital twin solution
IBM WebSphere channel connectivity setup and testing
Five cheapest wildcard SSL certificate brands
原生JS怎么生成九宫格
2.8 【 weight of complete binary tree 】
FAQs for code signature and driver signature
Uniapp address translation latitude and longitude
What kind of foreign exchange trading platform is regulated and safe?
Servlet面试题
Three solutions to forced hibernation of corporate computers
Steam elements hidden in science and Technology Education
How vscode debugs into standard library files / third-party package source code