26 Matching Annotations
  1. Last 7 days
    1. Before a client and server can exchange an HTTP request/response pair, they must establish a TCP connection, a process which requires several round-trips.

      Before a client and server can exchange … they must establish a TCP connection」 → client(瀏覽器)跟 server 要交換 HTTP 請求 / 回應之前,先要做 TCP 三次握手,這會多幾個 RTT(round-trip)

    1. Pre-order Traversal

      Pre-order traversal(先序走訪) 是另一種走二元樹的順序:對每個節點照 自己 → 左子樹 → 右子樹 這個順序處理。

    2. In-order Traversal

      In-order traversal(中序走訪) 是一種走二元樹的順序:對「每一個節點」,都照這個順序處理:左子樹 → 自己 → 右子樹。

  2. Nov 2025
    1. Reverse Polish Notation

      Polish notation 中文意思是「波蘭表示法」。

      如果是「Reverse Polish Notation」,則是「逆波蘭表示法」。

      常見於數學、程式,大陸常翻譯為「逆波蘭記法」,台灣通常說「逆波蘭表示法」或「逆波蘭式」。

      主要指一種寫數學運算式的方法,不用括號,依照演算法設計,方便由 stack 處理。

    1. Try It Yourself

      def contains_duplicate(nums: list[int]) -> bool: nums_length = len(nums) if nums_length == 0: return False unique_length = len(set(nums)) return unique_length != nums_length

      🎯 建議你面試時這樣做: 寫解答版這個: def contains_duplicate(nums: list[int]) -> bool: seen = set() for num in nums: if num in seen: return True seen.add(num) return False 然後主動講(超加分): 「時間複雜度是 O(n),空間是 O(n)。」 「底層用 hash set 做 membership check,平均 O(1)。」 「也可以用 len(set(nums)) != len(nums) 寫得更短,但這樣不能 early exit。」

    1. Why not shift all items forward to reclaim the space? You could move everything from position 95 onward back to position 0. But this requires copying every single item in the queue to a new position. With 1,000 items in the queue, you'd need 1,000 copy operations. This takes too much time for every dequeue operation, which should be quick and simple.

      很直觀想:「把所有剩下的資料直接往前搬,把 slot 0~4(最前端)都填回來,這樣空間就都可重用。」

      但這有超重的負擔:如果 queue 還有 1000 個資料,每個 dequeue 都要把 1000 個元素整個搬來搬去,非常慢!

      queue 最期待的就是 "dequeue 很快"(O(1)),但如果每次都要 copy 很多資料,就變成 O(n),效率低、設計不合格。

    1. amortized

      amortized(攤提、平攤)**在演算法分析中表示:「把偶爾出現的高成本操作,平均分配到每一步的成本上,算出真正每次操作的平均開銷。」

    2. Memory Access Patterns

      cache locality 與 cache miss 是什麼意思? cache locality(快取區域性) 定義:

      「區域性」指的是資料在記憶體中“集中擺放”的性質。

      現代電腦 CPU 有 L1/L2/L3 cache(小但極快的記憶體),每次會「一整塊」把附近的資料載入。

      Array(陣列)特點:

      Array 資料在記憶體中連續,一讀取時能把一大片資料一併存進 cache。

      這樣連續存取速度超快,因為 cache 一次就 cover 多個 element。

      應用:

      For 迴圈逐一走訪 array 時,一開始就把大部分都預先載入,後面不用再慢慢等主記憶體。

      cache miss(快取失誤/失命中) 定義:

      當 CPU 要存取的資料不在 cache 裡,就叫 cache miss。

      這時 CPU 必須到主記憶體(RAM)讀資料,速度慢得多。

      Linked list 特點:

      每個 node 在記憶體裡位置是分散的(不是一條龍排),下一個 node 可能離現在很遠。

      每經過一個 pointer,常常到新地址,cache 裡沒預先載到 → cache miss。

      遍歷 linked list 時經常 cache miss,所以實際速度慢。

    1. Traversing

      “Traversing” 在中文中通常翻译为“遍历”。

      在计算机科学中,遍历指的是按照一定的顺序访问数据结构中的每一个元素,比如遍历数组、链表、树或图等。常见的遍历操作包括计数、查找、求和等。

    1. Anagram

      Anagram(变位词)是指通过重新排列一个单词或短语中的字母,形成的另一个有意义的单词或短语。也就是说,两个单词如果包含完全相同的字母,只是顺序不同,那么它们就是 anagram。

    1. Palindrome

      Palindrome 的中文意思是“回文”或“回文词”。

      回文是指正着读和反着读都一样的单词、短语、数字或其他序列。