笔记_极客时间——算法面试通关40讲-第一章 02-04
数据结构
Sorting
Link list
List
Spanning tree
Tree
Graph
Stack
Hashing
Data structure
Array
Stack/Queue
PriorityQueue
LinkedList
Queue/Priority queue
Tree/Binary Search Tree
HashTable
Disjoint Set
Trie
BloomFilter
LRU Cache
Algorithm
Greedy
Recursion/Backtrace
Traversal
Breadth-first/Depth-first search
Divide and Conquer
Dynamic Programming
Binary Search
Graph
学习三要素:创建模型,即使反馈,刻意练习。
切题四件套
- Clarification
- Possible solutions
-compare(time/space)
-optimal(加强) - Coding(多写)
- Test cases
如何计算算法的复杂度
时间复杂度
Big O notation
- O(1):Constant Complexity:Constant常数复杂度 eg: int n = 1000
- O(log n):Logarithmic Complexity:对数复杂度
- O(n):Linear Complexity:线性时间复杂度
- O(n^2):N square Complexity 平方
- O(n^3):N square Complexity立方
- O(2^n):Exponential Growth 指数
- O(n!):Factorial 阶乘
Recurion
def fib(n):
if n == 0 or n ==1:
return n
return fib(n-1)+fib(n-2) #O(2^n)
master theorem
空间复杂度
Deliberate practicing
- 坚持、刻意练习
- 练习缺陷、弱点地方
- 不舒服、不爽、枯燥
LeetCode:https://leetcode.com/problemset/all/
class Solution:
def twoSum(self,nums,target):
hash_map=dict()
for i,x in enumerate(nums):
#enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中
if target-x in hash_map:
return [i,hash_map[target-×]
hash_map[x] = i
Feedback!!
参考
算法面试通关40讲 覃超
https://www.runoob.com/python/python-func-enumerate.html