Try   HackMD

2018q1 Homework3 (list)

contributed by < BroLeaf>

tags BroLeaf

生日悖論

  • 自我檢查事項

如何透過近似的運算式,估算上述機率計算呢?附上有效的 LaTeX 算式

有 n 個人生日不重複的機率

P(X)=365365×364365×363365×362365××366n365
=1×(11365)×(12365)×(13365)××(1n1365)

引入Talor series
ex=1+x+x22!+

 X<<1ex1+x

原式變為
1×e1365×e2365×e3365××en1365

=en(n1/2)365=en(n1)730

則有 n 個人生日會重複的機率為
1P(n)=1en(n1)730

Linux 風格的 linked list

  • 自我檢查事項:
  • 為何 Linux 採用 macro 來實作 linked list?一般的 function call 有何成本?

  • Advantages

    • Time efficiency.
    • Not need to pass arguments like function.
    • It's preprocessed.
    • Easier to Read.
  • Disadvantages

    • Very hard to debug in large code.
    • Take more memory in stack compare to function. Suppose in the program that there a Macro which used 50 times that means it will consume memory 50 times but in function if a function is called 50 times it will take single memory every time because every time it deallocate that memory
  • C 語言對於 macro 的處理是在 preprocessed 這個解段,基本上可以當做是在 compile time 完成的,所以比起在 run time 才處理 function 的 push、pop 自然會更有時間上的效率,而這些勢必要多犧牲一些在 memory 的空間來達到這樣的效果