网上的一些it面试题

题目来源[http://google-interview.com/google-interview/post/2009/08/01/Real-interview-questions.aspx]

 

1. Please describe a data structure that accomplishes the functions INSERT and FIND EDIAN in the best possible asymptotic time.

 

两个堆。一个大顶堆,一个小顶堆。满足:1、大顶堆中所有数小于小顶堆中所有数;2、大顶堆中数字的个数大于等于小顶堆中数字的个数,且相差小于等于1。则,查找中位数时,取大顶堆的最大数。复杂度O(1)Insert时,先根据大小,插入相应的堆中;然后,若大顶堆中数字的个数比小顶堆多2,则从大顶堆中取最大数,放入小顶堆中。复杂度O(lgn)


2. Given a circularly sorted array, describe the fastest way to locate the largest element.

 

circularly sorted5 6 7 1 2 3 4。折半查找.find(left, right),算法复杂度O(lgn)Cur=(left+right)/2. left<cur,则left=cur;否则right=cur


3. Given a binary search tree and an integer k, describe the most efficient way to locate two nodes of the tree that sum to k.

 

类似已排序的数组,在其中寻找x+y=k。算法复杂度O(lgn)

 

4. Given an arbitrarily connected graph, explain how to ascertain the reachability of a given node.

 

 

5. If you have one billion numbers and one hundred computers, what is the best way to locate the median of the numbers?

 

划分区间,计算每个居间中的数字个数。不断缩小区间。因为有100台计算机,因此每台每次计算10millian个数。

复杂度O(lgn)/100 n为区间个数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值