设为首页 加入收藏

TOP

算法笔试题
2014-11-24 01:01:24 来源: 作者: 【 】 浏览:8
Tags:算法 试题

1. [25 points] A binary tree is full if all of its vertices have either zero or two children. Let Bn
denote the number of full binary trees with n vertices.
(a) By drawing out all full binary trees with 3, 5, and 7 vertices, determine the exact values
of B3 , B5 , and B7 .
(b) Why have we left out full binary trees with even number of vertices, like B4, in part (a)
(c) For general n, derive a recurrence relation for Bn .
(d) Show by induction (substitution) that Bn is 2
(n) .
2. [25 points] Consider the problem of merging two sorted arrays A and B of n elements each
into one sorted array C of 2n elements. This problem asks you to prove that the minimum
number of comparisons to perform this task is 2n 1. The problem is split into two parts:
a) Show that if two elements x ∈ A and y ∈ B are consecutive in C, then they must be
compared.
b) Given the result from part (a), show that the lower bound on the number of comparisons
for merging A and B is 2n 1.


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇一网友自己设计的面试题 下一篇湖南科创面试题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: