Skip to content

Commit

Permalink
update readme, add code comment, rename script
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Feb 23, 2024
1 parent 551913c commit 25b9da4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@
||Bubble sort| [Python](./algorithm/python/bubble_sort.py), [JS](./algorithm/js/bubble_sort.js) , [C](./algorithm/c/bubble_sort.c)| | | | | OK* (3)|
||Insertion sort| [Python](./algorithm/python/insertion_sort.py), [JS](./algorithm/js/insertion_sort.js) |`stable` sort| work very fast for `nearly sorted` array| | | AGAIN|
||Bucket sort| [Python](./algorithm/python/bucket_sort.py) | | | | | AGAIN|
||Quick sort| [quick_sort.py](./algorithm/python/quick_sort.py), [quick_sort_v2.py](./algorithm/python/quick_sort_v2.py), [QuickSort.java](https://github.com/yennanliu/CS_basics/blob/master/leetcode_java/src/main/java/AlgorithmJava/QuickSort.java)| NOTE !!!, avg is NLogN, worst is N**2, [complexity ref](https://www.geeksforgeeks.org/time-and-space-complexity-analysis-of-quick-sort/) | `Best : O(N Log N), Avg : O(N Log N), Worst : O(N^2)` | | AGAIN***|
||Quick sort| [quick_sort.py](./algorithm/python/quick_sort.py), [quick_sort_v2.py](./algorithm/python/quick_sort_v2.py), [QuickSort.java](https://github.com/yennanliu/CS_basics/blob/master/leetcode_java/src/main/java/AlgorithmJava/QuickSort.java)| NOTE !!!, `avg is NLogN, worst is N**2`, [big O ref](https://www.geeksforgeeks.org/time-and-space-complexity-analysis-of-quick-sort/), [big O ref 2](https://rust-algo.club/sorting/quicksort/) | `Best : O(N Log N), Avg : O(N Log N), Worst : O(N^2)` | | AGAIN***|
||Heap sort| [Python](./algorithm/python/heap_sort.py)| | | AGAIN**|
||Merge sort|[merge_sort_topdown.py](./algorithm/python/merge_sort_topdown.py), [mergesort_bottomup.py](./algorithm/python/mergesort_bottomup.py), [MergeSortTopDown.java](https://github.com/yennanliu/CS_basics/blob/master/leetcode_java/src/main/java/AlgorithmJava/MergeSortTopDown.java), [SQL](./algorithm/sql/Mergesort.sql) | | | | | OK* (2)|
||Merge sort|[merge_sort_topdown.py](./algorithm/python/merge_sort_topdown.py), [mergesort_bottomup.py](./algorithm/python/merge_sort_bottomup.py), [MergeSortTopDown.java](https://github.com/yennanliu/CS_basics/blob/master/leetcode_java/src/main/java/AlgorithmJava/MergeSortTopDown.java), [SQL](./algorithm/sql/Mergesort.sql) | | | `Best : O(N Log N), Avg : O(N Log N), Worst : O(N Log N)` | O(N)| OK* (2)|
||Pancake sort| [Python](./algorithm/python/pancake_sort.py) | | | | | AGAIN|
||Selection sort| [Python](./algorithm/python/selection_sort.py), [JS](./algorithm/js/selection_sort.js) | | | | | AGAIN|
||Topological sort| [Python](./algorithm/python/topological_sort.py) | | Topological Sort is a algorithm can find "ordering" on an "order dependency" graph | | | AGAIN|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#---------------------------------------------------------------
# MERGE SORT bottomup
# MERGE SORT - bottomup
#---------------------------------------------------------------

# https://leetcode.com/explore/learn/card/recursion-ii/470/divide-and-conquer/2868/
# https://leetcode.com/problems/sort-an-array/discuss/568255/Python-Merge-Sort
# https://rust-algo.club/sorting/mergesort/

# time : O(N log N)
# space : O(N)
"""
Time complexity
Best : O(N Log N)
Avg : O(N Log N)
Worst : O(N Log N)`
Space complexity
O(N)
"""

class Solution:
def sortArray(self, nums: List[int]) -> List[int]:
Expand Down
18 changes: 15 additions & 3 deletions algorithm/python/merge_sort_topdown.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
#---------------------------------------------------------------
# MERGE SORT topdown
# MERGE SORT - topdown
#---------------------------------------------------------------

# https://leetcode.com/explore/learn/card/recursion-ii/470/divide-and-conquer/2868/
# https://rust-algo.club/sorting/mergesort/

# time : O(N)
# space : O(N)
"""
Time complexity
Best : O(N Log N)
Avg : O(N Log N)
Worst : O(N Log N)`
Space complexity
O(N)
"""

def merge_sort(nums):
# bottom cases: empty or list of a single element.
Expand Down
20 changes: 19 additions & 1 deletion algorithm/python/quick_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
# QUICK SORT V1
#---------------------------------------------------------------

"""
Time complexity
Best O(n log n)
Average O(n log n)
Worst O(n^2)
Space complexity
Worst space $O(log n) $ or $O(n) $ auxiliary
"""

# https://rust-algo.club/sorting/quicksort/index.html

# V0
# https://www.bilibili.com/video/BV1at411T75o/
# https://hackmd.io/@Aquamay/H1nxBOLcO/https%3A%2F%2Fhackmd.io%2F%40Aquamay%2FB1SPnfRq_
Expand Down Expand Up @@ -202,4 +220,4 @@ def three_way_radix_quicksort(sorting: list) -> list:
three_way_radix_quicksort([i for i in sorting if i < sorting[0]])
+ [i for i in sorting if i == sorting[0]]
+ three_way_radix_quicksort([i for i in sorting if i > sorting[0]])
)
)
17 changes: 17 additions & 0 deletions algorithm/python/quick_sort_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
#---------------------------------------------------------------

# https://leetcode.com/explore/learn/card/recursion-ii/470/divide-and-conquer/2870/
# https://rust-algo.club/sorting/quicksort/index.html

"""
Time complexity
Best O(n log n)
Average O(n log n)
Worst O(n^2)
Space complexity
Worst space $O(log n) $ or $O(n) $ auxiliary
"""

def quicksort(lst):
"""
Expand Down

0 comments on commit 25b9da4

Please sign in to comment.