update R6 and rebuild at 9.28

This commit is contained in:
yenru0 committed 2025-09-28 20:56:53 +09:00
1 parent 1692611987
commit 54353f6e82
10 files changed
+180 -6

No files matched your search

+2
View File
@@ -3,3 +3,5 @@
node_modules/
.npm
__pycache__
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+115
View File
@@ -3,3 +3,118 @@
* Hajin Ju, 2024062806
## 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)$$
+54
View File
@@ -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)