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的更多相关文章

  1. POJ2104 K-th Number(主席树)

    题目 Source http://poj.org/problem?id=2104 Description You are working for Macrohard company in data s ...

  2. POJ2104 K-th Number[主席树]【学习笔记】

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 51440   Accepted: 17594 Ca ...

  3. poj[2104]K-th Number

    Description You are working for Macrohard company in data structures department. After failing your ...

  4. [划分树] POJ 2104 K-th Number

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 51732   Accepted: 17722 Ca ...

  5. [POJ2104]K-th Number

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 34048   Accepted: 10810 Ca ...

  6. poj 2104:K-th Number(划分树,经典题)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 35653   Accepted: 11382 Ca ...

  7. 【POJ2104/2761】K-th Number

    Description You are working for Macrohard company in data structures department. After failing your ...

  8. POJ 2104 K-th Number(主席树——附讲解)

    Description You are working for Macrohard company in data structures department. After failing your ...

  9. 【POJ】2104 K-th Number(区间k大+主席树)

    http://poj.org/problem?id=2104 裸题不说.主席树水过. #include <cstdio> #include <iostream> #includ ...

随机推荐

  1. 【ADT】链表的基本C语言实现

    什么是抽象数据类型?首先,这一概念是软件开发人员在力求编写的代码健壮.易维护且可以复用的过程中产生的.英文是AbstractData Type.有人将其比作"抽象"的墙壁,&quo ...

  2. iOS中的项目新特性页面的处理

    一般项目中都会出现新特性页面,比如第一次使用应用的时候,或者在应用设置里查看新特性的时候会出现. 这里,选择新建一个专门处理项目新特性的控制器,来完成功能. 首先是 NewFeaturesViewCo ...

  3. python模拟登录知乎

    # -*- coding:utf-8 -*- import urllib import urllib2 import cookielib import sys from bs4 import Beau ...

  4. Flask -- 静态文件 和 模板渲染

    静态文件 一般用于存放图片,样式文件(css, js等) 保存位置:包中或者文件所在目录创建一个 static 目录 访问:在应用中使用 /static/...即可访问 , 更好的方式是使用url_f ...

  5. Windows API 之 VirtualAlloc

    Reserves, commits, or changes the state of a region of pages in the virtual address space of the cal ...

  6. 无法识别的配置节 system.serviceModel

    也是从网上四处搜来的答案,的确是解决了问题 不知道是不是补丁更新的原因,之前运行好的程序,突然就不行了, 一开始,运行直接就闪退了,在事件查看器里,也看不到具体的错误信息,幸亏是cmd的程序,所以 , ...

  7. android抓日志

    1. adb logcat -c 清楚以前的日志 adb logcat -s 过滤 adb logcat -s *:E adb logcat -v 指定输出的格式 adb logcat -v brie ...

  8. 用Py2exe打包Python脚本简单介绍

    一.简述      Py2exe,从这个名字上就可以理解,把Python脚本转换为windows平台上面可以运行的可执行程序(*.exe)的工具.经过转换后,你可以不 用安装Python的执行环境就可 ...

  9. hdu_4714_Tree2cycle(树形DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4714 题意:给你N个点N-1条边,形成一个树,让你拆树,并连接成一个环,每拆一次,连接一次,消耗1,问 ...

  10. Debian安装autoconf

    ###安装autoconf wget http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz \ && tar -xzv ...