一些简单但是常见的算法题目(笔记类)

(1) Let A1, A2, and A3 be three sorted arrays of n real numbers (all distinct). In the comparison  model, constructing a balanced binary search tree of the set A1 UA2 U A3 

需要时间O(n),首先对A1 A2 A3进行Merge,这里需要O(n),然后构建平衡二叉树时,简单地选取中位数,然后插入到树中,然后递归调用这个过程来构建左子树和右子树。 T(n)=2T(n/2)+O(1) =O(lgn),所以总的时间是O(n)。

(2) Given an unsorted array A[1  .  . n] of n integers, building a max-heap out of the elements of  A can be performed asymptotically faster than building a red-black tree out of the elements of A.

这里想记录的是红黑数的构建时间是Ω(nlgn)。方法是首先排序,需要Ω(nlgn),然后用中序遍历的方法在O(n)的时间内构建红黑树。

(3)Suppose we use a hash function h  to hash n distinct keys  into an array T  of  length m. Assuming simple uniform hashing, the expected number of colliding pairs of elements is Θ(n的平方/m).

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值