由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教MapReduce怎么找median
相关主题
F家onsite面经Apple 数据科学家面经
请教可以在线练习 map reduce 的地方?电话面试一个design问题,看看怎么做
mapreduce 初级问题,请各位大牛指点关于mahout的一些问题
median of N^2 numbers across N machineshadoop的combiner和partitioner的顺序是什么呢?
一道大数据题,求最优解。电面被问到hadoop了
简单map reduce mean median, 傻逼回答问一个大数据 处理问题
map reduce word count写一段如何准备large-scale system design的面试吧
MapReduce的面试题请问有朋友了解Continuuity这家公司么
相关话题的讨论汇总
话题: pivot话题: map话题: array话题: than话题: mapreduce
进入JobHunting版参与讨论
1 (共1页)
b*****s
发帖数: 36
1
比如给1 billion的整数,怎么用map reduce找median,mapper和reducer函数该怎么写?
能给个思路吗,谢谢了。
l****p
发帖数: 397
2
刚写了一个O(lg N)的算法:
import math
import random
NUM_MAP_TASKS = 3000
NUM_REDUCE_TASKS = 2
def select(array, order = (len(array)+1)/2):
pivot = array.pop(random.random()*len(array))
length = math.floor(len(array)/NUM_MAP_TASKS)
map_results = {'less than or equal to pivot': [], 'greater than pivot':
[]}
for i in range(0, NUM_MAP_TASKS):
r = map(array[length*i:length*(i+1)], pivot)
map_results['less than or equal to pivot'] += r['less than or equal
to pivot']
map_results['greater than pivot'] += r['greater than pivot']

# when all map tasks are done
candidate1 = reduce(map_results['less than or equal to pivot'], math.
floor(order), pivot)
candidate2 = reduce(map_results['greater than pivot', math.ceiling(order
- len(map_results['less than or equal to pivot'])-1)], pivot)
return candidate1 or candidate2

def map(array, pivot):
result = {'less than or equal to pivot': [], 'greater than pivot': []}
for n in array:
if n > pivot:
result['greater than pivot'].append(n)
else:
result['less than or equal to pivot'].append(n)

return result
def reduce(array, order, pivot):
if order == len(array) + 1:
return pivot
elif order <= len(array) and order > 0:
return select(array, order)
else:
return None
l*******b
发帖数: 2586
3
嗯,和quick sort 是不是类似?大牛指教

【在 l****p 的大作中提到】
: 刚写了一个O(lg N)的算法:
: import math
: import random
: NUM_MAP_TASKS = 3000
: NUM_REDUCE_TASKS = 2
: def select(array, order = (len(array)+1)/2):
: pivot = array.pop(random.random()*len(array))
: length = math.floor(len(array)/NUM_MAP_TASKS)
: map_results = {'less than or equal to pivot': [], 'greater than pivot':
: []}

l****p
发帖数: 397
4


【在 l*******b 的大作中提到】
: 嗯,和quick sort 是不是类似?大牛指教
b*****s
发帖数: 36
5
thanks!
1 (共1页)
进入JobHunting版参与讨论
相关主题
请问有朋友了解Continuuity这家公司么一道大数据题,求最优解。
发现一个单独测试Mapper和reducer的方式简单map reduce mean median, 傻逼回答
职位和 candidate 数量的关系map reduce word count
个人生涯中最独特的电话面试MapReduce的面试题
F家onsite面经Apple 数据科学家面经
请教可以在线练习 map reduce 的地方?电话面试一个design问题,看看怎么做
mapreduce 初级问题,请各位大牛指点关于mahout的一些问题
median of N^2 numbers across N machineshadoop的combiner和partitioner的顺序是什么呢?
相关话题的讨论汇总
话题: pivot话题: map话题: array话题: than话题: mapreduce