Skip to content

Commit

Permalink
fix heap cheatsheet, templeate, add pq cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 5, 2023
1 parent eb7ef40 commit 2a6a62d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doc/cheatsheet/00_template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cheatsheet template

## 0) Concept
## 0) Concept

### 0-1) Types

Expand Down
15 changes: 10 additions & 5 deletions doc/cheatsheet/heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- https://leetcode.com/explore/learn/card/heap/
- In many CS applications, we only need to `access the largest or smallest element` in the dataset. We DO NOT care about `the order of other data in the data set`. How do we efficiently access the largest or smallest element in the current dataset? The answer would be `Heap`.

- Priority Queue
- Priority Queue (PQ)
- Priority queue is one of the imeplementations of heap
- a priority queue is an `abstract data type` similar to a regular queue or stack data structure in which each element additionally has a `"priority"` associated with it. In a priority queue, an element with high priority is served before an element with low priority.
- `Heap != Priority Queue`
- Priority Queue is a abstract data type
Expand All @@ -21,12 +22,14 @@
- The maximum/minimum value in the Heap can be obtained with `O(1)` time complexity.
<p align="center"><img src ="https://github.com/yennanliu/CS_basics/blob/master/doc/pic/type_of_heap.png" ></p>

- Definition : given a tree, if P is C's parent node -> P always `<=` or `>=` C.
- Definition : if P parent node, C is child node -> P always `<=` or `>=` C.
- Types
- min heap
- given a tree, if P is C's parent node -> P always `<=` C.
- if P parent node, C is child node -> P always <= C
- 父節點總是 <= 子節點的值 (不需 右子節點 <= 父節點 <= 左子節點)
- max heap
- given a tree, if P is C's parent node -> P always `>=` C.
- if P parent node, C is child node -> P always >= C
- 父節點總是 >= 子節點的值 (不需 右子節點 <= 父節點 <= 左子節點)
- was invented for `heap sort`
- a heap is a specialized tree-based data structure which is essentially an almost completed tree that satisfies the heap property:
- In a max heap
Expand All @@ -51,7 +54,9 @@
### 1-0) Basic OP

- V1
- build
- build heap
- upHeap
- downHeap
- insert
- update
- get
Expand Down
15 changes: 15 additions & 0 deletions doc/cheatsheet/priority_queue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Priority Queue (PQ)

## 0) Concept

- Priority queue is one of the imeplementations of heap

### 0-1) Types

### 0-2) Pattern

## 1) General form

### 1-1) Basic OP

## 2) LC Example

0 comments on commit 2a6a62d

Please sign in to comment.