# code kata NO.3 - Kata Three: How Big, How Fast?

kata3的主题是 how big ,how fast，以下提供的解答参考自回复者szeryf，我基本是拾人牙慧+翻译，呵呵

## How big

Q1.roughly how many binary digits (bit) are required for the unsigned representation of:

A1. 2^10=1024,所以1000需要10个bit，1000000是1000*1000，对于2进制数，乘法就是向左移动多少位的问题，

1000是10bit，那么乘以1000就需要移动10位，那么1000000就是在10位基础上左移10位，也就是20位。

同理 1,000,000,000需要30位 ，1,000,000,000,000需要40位，8,000,000,000,000是乘以2^3=8，因此是40+3 = 43位

验证，使用计算机计算2^43 = 8796093022208 ，2^42 = 4398046511104 ，8,000,000,000,000应该是43位

Q2.My town has approximately 20,000 residences. How much space is required to store the names, addresses, and a phone number for all of these (if we store them as characters)

A2.跟设定的每条记录的最大长度有关，答案不确定

Q3. I’m storing 1,000,000 integers in a binary tree. Roughly how many nodes and levels can I expect the tree to have? Roughly how much space will it occupy on a 32-bit architecture?

A3.

## How Fast

Q1. My copy of Meyer’s Object Oriented Software Construction has about 1,200 body pages. Assuming no flow control or protocol overhead, about how long would it take to send it over an async 56k baud modem line?

A1. 1200page * 每页多少行 * 每页多少字 得出大概的字，然后根据字的编码占用的空间大小得出bit总数，比如ASCII就是*8

Q2. My binary search algorithm takes about 4.5mS to search a 10,000 entry array, and about 6mS to search 100,000 elements. How long would I expect it to take to search 10,000,000 elements (assuming I have sufficient memory to prevent paging).

A2. 10000 最糟情况需要二分14次，100,000 最糟情况需要二分17次

则 4.5ms/14 = 每次需 0.32ms ,6ms/17 = 每次需要 0.35ms

10,000,000  最糟情况需要二分24次 ，24次*0.35ms = 8.4 ms