面试常见问题-找中位数
来源:互联网 发布:数据分析毕业论文题目 编辑:程序博客网 时间:2024/06/06 09:35
本文将对这个问题进行深入分析。
正常数据量,O(n)的方法
http://www.lintcode.com/en/problem/median
可以用类似快排的方法以
public class Solution { /** * @param nums: A list of integers. * @return: An integer denotes the middle number of the array. */ public int median(int[] nums) { // write your code here if (nums == null) { return -1; } int k = (nums.length + 1) / 2; int result = findKth(nums, k); return result; } public int partition(int[] nums, int start, int end) { int i = start; int j = end; int pivotValue = nums[i]; while(i < j) { while(i < j && nums[j] >= pivotValue) { j--; } nums[i] = nums[j]; while(i < j && nums[i] < pivotValue) { i++; } nums[j] = nums[i]; if (i == j) { nums[i] = pivotValue; return i; } } return i; } public int helper(int[] nums, int start, int end, int k) { int loc = partition(nums, start, end); if (loc == k) { return nums[loc]; } else if (loc < k) { return helper(nums, loc + 1, end, k); } else { return helper(nums, start, loc - 1, k); } } public int findKth(int[] nums, int k) { return helper(nums, 0, nums.length - 1, k - 1); }}
大数据量,单机怎么做
- 使用外部归并排序
怎么用堆做?用Java的PriorityQueue实现?
MapReduce
Spark怎么做,有相关函数吗?他们是怎么写的?
对于一个Data Stream,怎么做
0 0
- 面试常见问题-找中位数
- 找中位数
- 找中位数
- 海量数据找中位数
- Sicily 4224. 找中位数
- 海量数据找中位数
- 双数组找中位数
- 大数据量找中位数
- 大根堆 小根堆 找中位数
- 海量数据找中位数
- 无序数组找中位数
- 海量数据找中位数
- 二分法找中位数
- 10G个数找中位数
- 有序数组中找中位数
- 用快速排序找中位数
- openjudge 双数组找中位数
- 5亿个数找中位数
- 世界上最远的距离
- 欢迎使用CSDN-markdown编辑器
- Could Not Get the Value for Parameter compilerId for Plugin Execution
- Eclipse Errors running builder "Integrated External Tool Builder" on project
- Hadoop笔记二之java操作hdfs对象
- 面试常见问题-找中位数
- Putting It All Together
- android studio删除一个module,出现Gradle project sync in progress
- oracle表和视图
- HDU 1102 Constructing Roads(Kruskal最小生成树求最小花费)
- Android Studio中报错:java.lang.UnsatisfiedLinkError: Couldn't load xxx from loader dalvik.system.PathCl
- unity 移动开发- 网络数据缓存
- error occurred during initialization of vm
- SQL 编辑,更新