Kth order statistcs
Selection:
selection is a trivial problem if the input numbers are sorted. If we use a sorting algorithm having O(nlgn) worst case running time, then the selection problem can be solved in O(nlgn) time. But using a sorting is more like using a cannon to shoot a fly since only one number needs to computed.
O(n) expected-time selection using the randomized partition.
Idea: In order to find the k-th order statistics in a region of size n, use the randomized partition to split the region into two subarrays. Let s-1 and n-s be the size of the left subarray and the size of the right subarray. If k=s, the pivot is the key that's looked for. If k<= s-1, look for the k-th element in the left subarray. Otherwise, look for the (k-s)-th one in the right subarray.
Kth order statistcs的更多相关文章
- POJ2104 K-th Number(主席树)
题目 Source http://poj.org/problem?id=2104 Description You are working for Macrohard company in data s ...
- POJ2104 K-th Number[主席树]【学习笔记】
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 51440 Accepted: 17594 Ca ...
- poj[2104]K-th Number
Description You are working for Macrohard company in data structures department. After failing your ...
- [划分树] POJ 2104 K-th Number
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 51732 Accepted: 17722 Ca ...
- [POJ2104]K-th Number
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 34048 Accepted: 10810 Ca ...
- poj 2104:K-th Number(划分树,经典题)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 35653 Accepted: 11382 Ca ...
- 【POJ2104/2761】K-th Number
Description You are working for Macrohard company in data structures department. After failing your ...
- POJ 2104 K-th Number(主席树——附讲解)
Description You are working for Macrohard company in data structures department. After failing your ...
- 【POJ】2104 K-th Number(区间k大+主席树)
http://poj.org/problem?id=2104 裸题不说.主席树水过. #include <cstdio> #include <iostream> #includ ...
随机推荐
- C语言的常用字符串操作函数(一)
一直做的是单片机相关的程序设计,所以程序设计上更偏向底层,对于字符串的操作也仅限于液晶屏幕上的显示等工作,想提高下字符串操作的水平,而不是笨拙的数组替换等方式,翻看帖子发现C语言的字符串操作函数竟然这 ...
- iOS学习笔记(01) - 泛型
决定新开一坑,在不断学习的同时分享自己的学习历程给大家,既是对自己学习的记录,又希望能对大家提供些微的帮助. 这一篇文章主要来介绍泛型的意义.使用与声明方法等. 1.泛型:限制类型 1.1.泛型使用场 ...
- C语言语法tips(不断更新)
语法虽然琐碎,犯了低级错误代价可就大了,列出一些容易混淆概念,避免以后出错 sizeof和strlen的区别在于:1.sizeof是运算符,语言支持的,strlen可以求malloc出来的字符串的长度 ...
- echarts图表里遇到的问题
1. 取消echarts的默认动画 : series:[{ animation:false }] 2. 控制散点图里散点的大小: series:[{ symbolSize:5 }] 3. 去除内部网格 ...
- HDU 5811 Colosseo
首先判断一下两个集合是否能够拓扑排序,顺便记录下每个节点的拓扑序. 然后看T2中每个点在T1中能够放在哪一个位置,记录下这个位置Pi. 然后T2中(按拓扑序排好),计算Pi的一个非严格递增的LIS.L ...
- POJ 2246 Matrix Chain Multiplication
用栈来处理一下就好了. #include<iostream> #include<algorithm> #include<cstdio> #include<cs ...
- ios简单实现如果没有开启定位,提示开启系统软件定位功能
if([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == ...
- JavaScript高级程序设计:第五章
引用类型 一.object类型: 创建object实例的方式有两种.第一种是使用new操作符后跟Object构造函数,如下所示: var person = new Object(): person ...
- thinkphp 实现微信公众号开发(一)
打算用php做一个微信公众号管理平台.用thinkphp框架 教程上面是是应用下面会自动生成Lib文件夹.但是我的3.2.3自动生成目录不一样 我修改了我项目文件夹下面的IndexController ...
- Win7 Cygwin环境试验Nutch tutorial遇到的异常解决方法
安装tutorial的步骤安装Nutch,当执行下面这条命令时出现异常 bin/nutch crawl urls - -topN Injector: starting at -- :: Injecto ...