当前位置:网站首页>Quick sort, cluster index, find the k-largest value in the data
Quick sort, cluster index, find the k-largest value in the data
2022-06-30 02:57:00 【Ppdy bud】
List of articles
Quick sort code
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);
}
}
The difference between clustered index and non clustered index
Cluster index : An index that has the same sort of index entries as the data records in the table ( Look up Chinese characters with Pinyin in the dictionary )innodb
Nonclustered indexes : The index order is different from the physical storage order ( Look up Chinese characters with the partial radicals in dictionary )myisam
The leaf node of cluster index is the data node , Index and data together .
Dense index and sparse index
Dense index : Each index key value pair corresponds to an index entry ;
Sparse index : Only some search code values are indexed ;
The advantages of sparse indexing are : Smaller footprint , And the maintenance cost is small when inserting and deleting .
Looking for the third in the data k Big value ( Based on fast scheduling )
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;
}
}
边栏推荐
- [Postgres] Postgres database migration
- Network neuroscience -- a review of network Neuroscience
- Distributed file system fastdfs
- JMeter obtains cookies across thread groups or JMeter thread groups share cookies
- How do I enable assembly binding logging- How can I enable Assembly binding logging?
- Xunwei enzhipu ITop - imx6 Development Platform
- What is the difference between a layer 3 switch and a layer 2 switch
- Redis+AOP怎么自定义注解实现限流
- Pytoch learning (II)
- Hands on in-depth learning notes (XV) 4.1 Multilayer perceptron
猜你喜欢

Raki's notes on reading paper: Leveraging type descriptions for zero shot named entity recognition and classification

Use compose to realize the effect of selecting movie seats by panning tickets

Unity3D UGUI强制刷新Layout(布局)组件

Two methods of SSL certificate format conversion

How to prevent duplicate submission under concurrent requests

What is a self signed certificate? Advantages and disadvantages of self signed SSL certificates?

Cmake tutorial series -02- generating binaries using cmake code

Summary of knowledge points about eigenvalues and eigenvectors of matrices in Chapter 5 of Linear Algebra (Jeff's self perception)

怎么利用Redis实现点赞功能

uniapp 地址转换经纬度
随机推荐
Template parameter package and function parameter package
NLP text summary: data set introduction and preprocessing [New York Times annotated corpus]
Implementation of Sanzi chess with C language
High paid programmers & interview questions series 63: talk about the differences between sleep (), yield (), join (), and wait ()
Raki's notes on reading paper: neighborhood matching network for entity alignment
三层交换机和二层交换机区别是什么
Multi card server usage
Jvxetable sub table record loading completion event
Global and Chinese market of mobile commerce solutions 2022-2028: Research Report on technology, participants, trends, market size and share
Pytoch learning (II)
A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022
List of development tools
Intel-Hex , Motorola S-Record 格式详细解析
Wechat applet page Jump and parameter transfer
CMake教程系列-02-使用cmake代码生成二进制
Intel hex, Motorola S-Record format detailed analysis
迅为恩智浦iTOP-IMX6开发平台
How can redis+aop customize annotations to achieve flow restriction
Some technology sharing
FDA ESG regulation: digital certificate must be used to ensure communication security