Skip to content

Latest commit

 

History

History
55 lines (45 loc) · 1.13 KB

week3.md

File metadata and controls

55 lines (45 loc) · 1.13 KB

CS50 Week3 Algorithms

  • Data structures
    • encapsulate 封装
    • default value (not supported)
typedef struct
{
  // ...
}
struct_name;
  • 大 O 表示法 (Big O notation)
    • 时间复杂度
    • 空间复杂度
    • $O(1)$
    • $O(n)$
    • $O(n^2)$
    • $\Omega$(n) - best case
    • $\theta$(n) - best case and worst case are the same

  • Search
    • linear search O(n)
    • binary search
      • sorted
      • $O(\log_{2}n)$ $\frac{n}{2^x} = 1$, x = O($\log_{2}n$)

  • Sorting 排序

    $$ T(n)=2T(\frac{n}{2})+n \to T(n)=2^kT(\frac{n}{2^k})+ kn $$

    $$ \frac{n}{2^k}=1,n=2^k,T(1)=0 \to T(2^k)=2^kT(1)+kn=kn \to k=\log_{2}n, T(n)=n\log_{2}n $$