圖的搜索(遍歷)
DFS
寫法:遞歸或用 stack
求解那種所有滿足條件的路徑的問題,很容易想到 DFS,而且遍歷基本也是比不可少的。但是最優解問題,DFS 未必就是最好的算法了,畢竟遍歷的時間復雜度是 O(a^d)
BFS
寫法:用 queue
binary search
數組
用于在已排序的數組中搜索某個元素的位置
矩陣
This matrix has the following properties:
Integers in each row are sorted in ascending from left to right
Integers in each column are sorted in ascending from top to bottom