算法导论 课后题答案

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Partial Solutions for Introduction to algorithms second edition

Professor: Song You

TA: Shao Wen

ACKNOWLEDGEMENT

CLASS ONE: JINZI

CLASS TWO: LIUHAO, SONGDINMIN, SUNBOSHAN, SUNYANG

CLASS FOUR:DONGYANHAO, FANSHENGBO, LULU, XIAODONG,

CLASS FIVE:GAOCHEN, WANGXIAOCHUAN, LIUZHENHUA, WANGJIAN, YINGYING CLASS SIX: ZHANGZHAOYU, XUXIAOPENG, PENGYUN, HOULAN

CLASS: LIKANG,JIANGZHOU, ANONYMITY

The collator of this Answer Set, SHAOWen, takes absolutely no responsibility for the contents. This is merely a vague suggestion to a solution to some of the exercises posed in the book Introduction to algorithms by Cormen, Leiserson and Rivest. It is very likely that there are many errors and that the solutions are wrong. If you have found an error, have a better solution or wish to contribute in some constructive way please send an Email to

shao_wen_buaa@

It is important that you try hard to solve the exercises on your own. Use this document only as a last resort or to check if your instructor got it all wrong.

Have fun with your algorithms and get a satisfactory result in this course.

Best regards,

SHAOWen

Exercises 1.1-2

Other than speed, what other measures of efficiency might one use in a real-world setting? 空间,硬件资源等

Exercises 1.1-4 (class two 刘浩)

How are the shortest-path and traveling-salesman problems given above similar? How are they different?

相似点:找出最短路径

不同点:shortest-path 不一定经过所有点,而traveling-salesman得经过所有点

Exercises 1.2-2

Suppose we are comparing implementations of insertion sort and merge sort on the same machine. For inputs of size n, insertion sort runs in 8n2 steps, while merge sort runs in 64n lg n steps. For which values of n does insertion sort beat merge sort?

插入排序的性能优于合并排序也就是:插入排序所用的步数少:

所以有:8n2≤64nlgn⇒n<8ln n需要解一下这个超越方程,

编个程序很容易得到:

2≤n≤43

Exercises 1.2-3

What is the smallest value of n such that an algorithm whose running time is 100n2 runs faster than an algorithm whose running time is 2n on the same machine?

原理同上题,可列出如下不等式:

100n2≤2n解这个不等式(代数法),可求出最小的整数n=15

Problems 1-1: Comparison of running times

For each function f(n) and time t in the following table, determine the largest size n of a problem that can be solved in time t, assuming that the algorithm to solve the problem

Exercises 2.1-1 (class four 匿名)

Using Figure 2.2 as a model, illustrate the operation of INSERTION-SORT on the array A = 〈31, 41, 59, 26, 41, 58〉.

代码:

INSERTION-SORT(A)

1for j ← 2 to length*A+

2do key ← A*j+

3△Insert A[j] into the sorted sequence A[1..j-1]

4i ← j – 1

5While I > 0 and A[i] > key

6d o A*i+1+ ← A*i+

7i ← j – 1

8A*i+1+ ← key

图解:

Exercises 2.3-1 (class five 高晨)

Using Figure 2.4 as a model, illustrate the operation of merge sort on the array A = 〈3, 41, 52, 26, 38, 57, 9, 49〉.

如下所示:

3,9,26,38,41,49,52,57

3,26,41,52 9,38,49,57

3,41 26,52 38,57 9,49

3 41 52 26 38 57 9 49

相关文档
最新文档