From 54353f6e82133d6024727b7745cce9d5b602b2c4 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Sun, 28 Sep 2025 20:56:53 +0900 Subject: [PATCH] update R6 and rebuild at 9.28 --- .gitignore | 4 +- out/reviews/R1.pdf | 2 +- out/reviews/R2.pdf | 2 +- out/reviews/R3.pdf | 2 +- out/reviews/R4-1.pdf | 2 +- out/reviews/R4-2.pdf | 2 +- out/reviews/R5.pdf | 2 +- out/reviews/R6.pdf | 3 + reviews/R6.md | 117 ++++++++++++++++++++++++++++++++++++++- reviews/__pyfunc__/r6.py | 54 ++++++++++++++++++ 10 files changed, 182 insertions(+), 8 deletions(-) create mode 100644 out/reviews/R6.pdf create mode 100644 reviews/__pyfunc__/r6.py diff --git a/.gitignore b/.gitignore index 506b89e..3d74853 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ .vscode node_modules/ -.npm \ No newline at end of file +.npm + +__pycache__ \ No newline at end of file diff --git a/out/reviews/R1.pdf b/out/reviews/R1.pdf index f13f5a7..a17419f 100644 --- a/out/reviews/R1.pdf +++ b/out/reviews/R1.pdf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5917bf8de35dd726270f9d4f69587adeeaa653d64094b8abdafa94fb8c0dc3f7 +oid sha256:0682ac085acd453363e5702e75c9ccc6a6468a7ba81541fc7742cb0d61ad980c size 67664 diff --git a/out/reviews/R2.pdf b/out/reviews/R2.pdf index 6e0b22e..57893cb 100644 --- a/out/reviews/R2.pdf +++ b/out/reviews/R2.pdf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f963ee931023c455b7e64a9b7543386f7a2e454ec7f365822fba4cc82e9e6b92 +oid sha256:cbb95d6b5faa96f699794bd91c8e6e50f857e856f2500e074f138b3e459ffe0e size 102912 diff --git a/out/reviews/R3.pdf b/out/reviews/R3.pdf index c1879ee..bd90d18 100644 --- a/out/reviews/R3.pdf +++ b/out/reviews/R3.pdf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a25a757ea83a7ae9d2e96ceaeca3bda302bf79fa14fbc75c04da928af1cb966b +oid sha256:9e2e9a97e86b86e89d0aa2e4ca76f84bcadd5f2c892260c46e71f412e0621d2b size 71667 diff --git a/out/reviews/R4-1.pdf b/out/reviews/R4-1.pdf index 6050d51..a8a5729 100644 --- a/out/reviews/R4-1.pdf +++ b/out/reviews/R4-1.pdf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:60e1f742ab5b577b2aa00732f7a7ada178f1d1ff60d067c00db4a05a8b474b89 +oid sha256:6afb9a9a224aedafe5eba8f282e9ec5bd3713ba7d762f7152bb18047b43b6d75 size 64621 diff --git a/out/reviews/R4-2.pdf b/out/reviews/R4-2.pdf index c82a804..a6934f7 100644 --- a/out/reviews/R4-2.pdf +++ b/out/reviews/R4-2.pdf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2773e0067f9467fc508437cd8dd8405c36b84ba7715652a50012fb4a4cfbe5eb +oid sha256:dcc84341731084b6313d195c8092b27dac7db3e7101fecb0f6a69c75831ccbab size 36204 diff --git a/out/reviews/R5.pdf b/out/reviews/R5.pdf index 396e44e..a6fa80a 100644 --- a/out/reviews/R5.pdf +++ b/out/reviews/R5.pdf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1c10b6b712dbeaba1d1bb2baa3167208628c770c09e65d5a5af735a949f0ed67 +oid sha256:2369d614dadf6a989ccb16bb388b3808abe86295b4750b0399584fb97495a724 size 149208 diff --git a/out/reviews/R6.pdf b/out/reviews/R6.pdf new file mode 100644 index 0000000..ee51cc2 --- /dev/null +++ b/out/reviews/R6.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed0ed13fa6850c7b49f48e44092310e5ce84e829d7268ee99467ae528fa9b8f7 +size 104271 diff --git a/reviews/R6.md b/reviews/R6.md index 6a793bf..eebbf08 100644 --- a/reviews/R6.md +++ b/reviews/R6.md @@ -2,4 +2,119 @@ * Hajin Ju, 2024062806 -## Problem 1 \ No newline at end of file +## Problem 1 + +Illustrate the operation of `PARTITION` on the array $A = \set{2, 8, 7, 1, 3, 5, 6, 4}$ + +### Solution 1 + +```python {cmd output=html hide} +from __pyfunc__.r6 import * +from bs4 import BeautifulSoup + +data = [2, 8, 7, 1, 3, 5, 6, 4] +hl = [0, 0, 0, 0, 0, 0, 1, 0] + +print( + create_array_table(data, + [0, 0, 0, 0, 0, 0, 1, 0] + , 0, 0), +) + +print( + create_array_table(data, + [1, 0, 0, 0, 0, 0, 1, 0], + 1, 0) +) + +print( + create_array_table( + [2, 8, 7, 1, 3, 5, 6, 4], + [1, 1, 0, 0, 0, 0, 1, 0], + 1, 1) +) + +print(create_array_table( + [2, 8, 7, 1, 3, 5, 6, 4], + [1, 0, 1, 0, 0, 0, 1, 0], + 1, 2 +)) + +print(create_array_table( + [2, 1, 7, 8, 3, 5, 6, 4], + [0, 1, 0, 1, 0, 0, 1, 0], + 2, 2 +)) + +print(create_array_table( + [2, 1, 3, 8, 7, 5, 6, 4], + [0, 0, 1, 0, 1, 0, 1, 0], + 3, 2 +)) + +print(create_array_table( + [2, 1, 3, 8, 7, 5, 6, 4], + [0, 0, 1, 0, 0, 1, 1, 0], + 3, 3 +)) + +print(create_array_table( + [2, 1, 3, 8, 7, 5, 6, 4], + [0, 0, 1, 0, 0, 0, 1, 0], + 3, 4 +)) + +print(create_array_table( + [2, 1, 3, 4, 8, 7, 5, 6], + [0, 0, 1, 1, 0, 0, 0, 1], + 0, 0 +)) + +``` + +## Problem 2 + +Answer questions about the following function `SELECT(A, p, r, i)` where $r-p + 1 = n$ + +```py +SELECT(A, p, r, i) + if p == r + return A[p] + q = PARTITION(A, p, r) + k = q - p + 1 + if i == k + return A[q] + else if i < k + return SELECT(A, p, q - 1, i) + else + return SELECT(A, q + 1, r, i - k) +``` + +* What does it do? +* What is the worst-case running time? +* What is the best-case running time? + + +### Solution 2-a + +`SELECT` selects `i`-th smallest element in the array `A`. + +### Solution 2-b + +The worst-case occurs when the `PARTITION` partitiend the array unbalanced. + +So, time-complexity of the case is: + +$$T(n) = T(n-1) + O(n)$$ + +$$\therefore T(n) = O(n^2)$$ + +### Solution 2-c + +The best-case occurs when the `PARTITION` partitiend the array balanced, which means pivot is median. + +So, time-complexity of the case is: + +$$T(n) = T(n/2) + O(n)$$ + +$$\therefore T(n) = O(n)$$ diff --git a/reviews/__pyfunc__/r6.py b/reviews/__pyfunc__/r6.py new file mode 100644 index 0000000..218727e --- /dev/null +++ b/reviews/__pyfunc__/r6.py @@ -0,0 +1,54 @@ +from bs4 import BeautifulSoup + +def create_array_table(data: list, border: list, cnt_p1: int, cnt_p2: int) -> str: + STYLE_ARRAY_TABLE = "border-collapse: collapse;" + STYLE_TD_TEMPLATE = "border: 1px solid black; width: 1.2em; height: 1.6rem; text-align: center; font-size: 1.3rem;" + + def style_with_rborder(style: str): + style += "border-right: 6px solid black;" + return style + + def style_with_p1(style: str): + style += "background-color: lightgray;" + return style + def style_with_p2(style: str): + style += "background-color: gray;" + return style + + if len(data) != len(border): + return "" + + soup = BeautifulSoup("", "html.parser") + table = soup.new_tag('table', attrs={'style': STYLE_ARRAY_TABLE}) + tr = soup.new_tag('tr') + + for i in range(len(data)): + style = STYLE_TD_TEMPLATE + if i < cnt_p1: + style = style_with_p1(style) + if border[i]: + style = style_with_rborder(style) + elif cnt_p1 <= i < cnt_p1 + cnt_p2: + style = style_with_p2(style) + if border[i]: + style = style_with_rborder(style) + else: + if border[i]: + style = style_with_rborder(style) + td = soup.new_tag('td', attrs={'style': style}) + td.string = str(data[i]) + + tr.append(td) + + table.append(tr) + soup.append(table) + + return str(soup) + + + + + + + +