1. If X has m symbols and Y has n symbols, then X and Y have 2^m and 2^n possible subsequences.
Question: 有n个元素的集合A具有多少个不同的子集?
Answer:2^n.
Solution:空集也是任何集合的一个子集。由排列组合可知,n个元素的集合A具有C(n,0)+C(n,1)+……+C(n,n)=(1+1)^n=2^n.
Relative:
二项式定理公式:http://baike.baidu.com/link?url=d5ns14eokwyhYwKR3iT6-TTYz_WgENwaJMqx4nmDIM0Y7SwGdfS1z2EloGoQ3FlL
2. Having a solid base of algorithmic knowledge and technique is one characteristic that separates the truly skilled programmers from the novices.
3. Exercise 1.2-2:
Question: Suppose we are comparing implementations of insertion sort and merge sort on the same machine. For inputs of sizen, insertion sort runs in
8n^2 steps, while merge sort runs in 64nlgn steps. For which values of n does insertion sort beat merge sort?
Answer: 2 <= n <= 43
Source code:
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[])
{
int n=2,max=0;
while(pow(2,n/8.0) < n) {
max = n;
n++;
}
printf("When 8n^2 < 64nlg(n),it is true for 2 <= n <= %d\n", max);
return 0;
}
4. Exercise 1.2-3:
Question: What is the smallest value of n such that an algorithm whose running time is 100n^2 runs faster than an algorithm whose running time is 2^n
on the same machine?
Answer: n = 15.
Source code:
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[])
{
int n = 1;
while(100*n*n > pow(2.0,n)) {
n++;
}
printf("The minimum number making 100n^2 < 2^n true is %d\n", n);
return 0;
}