Skip to content

Commit

Permalink
add note
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbreathing committed Feb 25, 2024
1 parent 65083b5 commit 7346d72
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions _posts/2024-02-25-cs-6006.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ title: CS 6.006 笔记
### Master Theorem

The Master Theorem provides a way to solve recurrence relations in which recursive calls decrease problem size by a constant factor. Given a recurrence relation of the form $T(n) = aT(n/b)+ f(n)$ and $T(1) = Θ(1)$, with branching factor $a ≥ 1$, problem size reduction factor $b > 1$, and
asymptotically non-negative function $f(n)$, the Master Theorem gives the solution to the recurrence by comparing $f(n)$ to $a^{log_bn} = n^{log_b a}$, the number of leaves at the bottom of the recursion
asymptotically non-negative function $f(n)$, the Master Theorem gives the solution to the recurrence by comparing $f(n)$ to $a^{log_bn} = n^{log_b a}$, the number of leaves at the bottom of the recursion
tree. When $f(n)$ grows asymptotically faster than $n^{log_b a}$, the work done at each level decreases
geometrically so the work at the root dominates; alternatively, when $f(n)$ grows slower, the work
done at each level increases geometrically and the work at the leaves dominates. When their growth
Expand Down Expand Up @@ -398,7 +398,7 @@ def direct_access_sort(A):
- Idea! Represent each key $k$ by tuple $(a, b)$ where $k = an + b$ and $0 ≤ b < n$
- Specifically $a = bk/nc < n$ and $b = (k mod n)$ (just a 2-digit base-n number!)
- This is a built-in Python operation (a, b) = divmod(k, n)
- Example: $[17, 3, 24, 22, 12] \rightarrow [(3,2), (0,3), (4,4), (4,2), (2,2)] \rightarrow \[32, 03, 44, 42, 22\](n = 5)$
- Example: [17, 3, 24, 22, 12] [(3,2), (0,3), (4,4), (4,2), (2,2)] [32, 03, 44, 42, 22\](n=5)
- How can we sort tuples?

### Tuple Sort
Expand All @@ -408,7 +408,7 @@ def direct_access_sort(A):
- How to sort? **Idea**! Use other **auxiliary sorting algorithms** to separately sort each key
- (Like sorting rows in a spreadsheet by multiple columns)
- What order to sort them in? Least significant to most significant!
- Exercise: $[32, 03, 44, 42, 22] =⇒ [42, 22, 32, 03, 44] =⇒ \[03, 22, 32, 42, 44\](n=5)$
- Exercise: [32, 03, 44, 42, 22] =⇒ [42, 22, 32, 03, 44] =⇒ [03, 22, 32, 42, 44\](n=5)
- **Idea**! Use tuple sort with auxiliary direct access array sort to sort tuples (a, b).
- **Problem**! Many integers could have the same a or b value, even if input keys distinct
- Need sort allowing **repeated keys** which preserves input order
Expand Down
1 change: 1 addition & 0 deletions t.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7346d72

Please sign in to comment.