Compare commits

...

2 Commits

Author SHA1 Message Date
aa13f159c2 migrate file format 2025-10-05 17:47:45 +09:00
158facd519 update R7 R7X R8a 2025-10-05 17:44:24 +09:00
14 changed files with 366 additions and 6 deletions

BIN
assets/R8-1_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

BIN
out/reviews/R4-1.pdf (Stored with Git LFS)

Binary file not shown.

BIN
out/reviews/R4-2.pdf (Stored with Git LFS)

Binary file not shown.

BIN
out/reviews/R4a.pdf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
out/reviews/R4b.pdf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
out/reviews/R7.pdf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
out/reviews/R7X.pdf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
out/reviews/R8a.pdf (Stored with Git LFS) Normal file

Binary file not shown.

201
reviews/R7.md Normal file
View File

@@ -0,0 +1,201 @@
# Review 7
* Hajin Ju, 2024062806
## Problem 1
Illustrate the operation of `COUNTING-SORT` on the array $A= \set{6,2,1,3,1,3,2}$
### Solution 1
```python {cmd output=html hide}
from __pyfunc__.r7 import *
from bs4 import BeautifulSoup as bs
soup = bs("", "lxml")
soup.append(create_array_block(soup, "A", None, [6, 2, 1, 3, 1, 3, 2]))
print(soup)
```
```python {cmd output=html hide}
from __pyfunc__.r7 import *
from bs4 import BeautifulSoup as bs
soup = bs("", "lxml")
main = soup.append(create_main(soup))
col1 = main.append(create_col(soup))
col2 = main.append(create_col(soup))
col1.append(
create_array_block(
soup, "C",
list(range(1,6+1)), [2, 2, 2, 0, 0, 1]))
col2.append(
create_array_block(
soup, "C",
[1, 2, 3, 4, 5, 6],
[2, 4, 6, 6, 6, 7]))
col1.append(
create_array_block(
soup, "B",
[1, 2, 3, 4, 5, 6, 7],
["", "", "", 2, "", "", ""]))
col2.append(
create_array_block(
soup, "C",
[1, 2, 3, 4, 5, 6],
[2, 3, 6, 6, 6, 7]))
col1.append(
create_array_block(
soup, "B",
[1, 2, 3, 4, 5, 6, 7],
["", "", "", 2, "", 3, ""]))
col2.append(
create_array_block(
soup, "C",
[1, 2, 3, 4, 5, 6],
[2, 3, 5, 6, 6, 7]))
col1.append(
create_array_block(
soup, "B",
[1, 2, 3, 4, 5, 6, 7],
["", 1, "", 2, "", 3, ""]))
col2.append(
create_array_block(
soup, "C",
[1, 2, 3, 4, 5, 6],
[1, 3, 5, 6, 6, 7]))
col1.append(
create_array_block(
soup, "B",
[1, 2, 3, 4, 5, 6, 7],
["", 1, "", 2, 3, 3, ""]))
col2.append(
create_array_block(
soup, "C",
[1, 2, 3, 4, 5, 6],
[1, 3, 4, 6, 6, 7]))
col1.append(
create_array_block(
soup, "B",
[1, 2, 3, 4, 5, 6, 7],
[1, 1, "", 2, 3, 3, ""]))
col2.append(
create_array_block(
soup, "C",
[1, 2, 3, 4, 5, 6],
[0, 3, 4, 6, 6, 7]))
col1.append(
create_array_block(
soup, "B",
[1, 2, 3, 4, 5, 6, 7],
[1, 1, 2, 2, 3, 3, ""]))
col2.append(
create_array_block(
soup, "C",
[1, 2, 3, 4, 5, 6],
[0, 2, 4, 6, 6, 7]))
col1.append(
create_array_block(
soup, "B",
[1, 2, 3, 4, 5, 6, 7],
[1, 1, 2, 2, 3, 3, 6]))
col2.append(
create_array_block(
soup, "C",
[1, 2, 3, 4, 5, 6],
[0, 2, 4, 6, 6, 6]))
print(soup)
```
## Problem 2
Fill in the following `RADIX-SORT` example.
### Solution 2
```python {cmd output=html hide}
from __pyfunc__.r7 import *
from bs4 import BeautifulSoup as bs
soup = bs("", "lxml")
main = soup.append(create_main(soup))
col1 = main.append(create_col(soup))
col2 = main.append(create_col(soup))
col3 = main.append(create_col(soup))
col4 = main.append(create_col(soup))
col1.append(create_radix_table(soup,
[
"COW",
"DOG",
"SEA",
"RUG",
"ROW",
"MOB",
"BOX",
"TAB",
"BAR",
"EAR",
"TAR"]
))
col2.append(create_radix_table(soup,
[
"SEA",
"MOB",
"TAB",
"DOG",
"RUG",
"BAR",
"EAR",
"TAR",
"COW",
"ROW",
"BOX"], [2]
))
col3.append(create_radix_table(soup,
[
"TAB",
"BAR",
"EAR",
"TAR",
"SEA",
"MOB",
"DOG",
"COW",
"ROW",
"BOX",
"RUG",], [1, 2]
))
col4.append(create_radix_table(soup,
[
"BAR",
"BOX",
"COW",
"DOG",
"EAR",
"MOB",
"ROW",
"RUG",
"SEA",
"TAB",
"TAR",], [0, 1, 2]
))
print(soup)
```

11
reviews/R7X.md Normal file
View File

@@ -0,0 +1,11 @@
# Review DataStructure
* Hajin Ju, 2024062806
| * | Arrays<br>(not sorted) | Arrays<br>(sorted) | LinkedLists<br>(not sorted) | LinkedList<br>(sorted) | Binary ST<br>(avg) | Balanced ST | HashTables<br>(avg) |
| --------------------------- | ---------------------- | ------------------ | --------------------------- | ---------------------- | ------------------ | ----------- | ------------------- |
| Search($x$) | $O(n)$ | $O(\lg n)$ | $O(n)$ | $O(n)$ | $O(\lg n)$ | $O(\lg n)$ | $O(1)$ |
| Insert($x$) | $O(1)$ | $O(n)$ | $O(1)$ | $O(n)$ | $O(\lg n)$ | $O(\lg n)$ | $O(1)$ |
| Insert($x$)<br>(dup search) | $O(n)$ | $O(n)$ | $O(n)$ | $O(n)$ | $O(\lg n)$ | $O(\lg n)$ | $O(1)$ |
| Delete($i$) | $O(1)$ | $O(n)$ | $O(1)$ | $O(1)$ | $O(\lg n)$ | $O(\lg n)$ | $O(1)$ |
| Delete($x$) | $O(n)$ | $O(n)$ | $O(n)$ | $O(n)$ | $O(\lg n)$ | $O(\lg n)$ | $O(1)$ |

58
reviews/R8a.md Normal file
View File

@@ -0,0 +1,58 @@
# Review 7
* Hajin Ju, 2024062806
## Problem 1
Fill in the blanks in the following assembly-line scheduling example.
### Solution 1
![](/assets/R8-1_1.png)
**table $s$**
| $s$ | 1 | 2 | 3 | 4 | 5 | 6 |
| --- | --- | --- | --- | --- | --- | --- |
| 1 | 9 | 18 | 20 | 24 | 32 | 35 |
| 2 | 12 | 16 | 22 | 25 | 30 | 37 |
**table $l$**
| $l$ | 1 | 2 | 3 | 4 | 5 | 6 |
| --- | --- | --- | --- | --- | --- | --- |
| 1 | - | 1 | 2 | 1 | 1 | 2 |
| 2 | - | 1 | 2 | 1 | 2 | 2 |
$$\begin{align*}s^* &= 38\\l^* &= 1\end{align*}$$
## Problem 2
Fill in the blanks in the following pseudocode for assembly-line scheduling
### Solution 2
```python
FASTEST-WAY(a, t, e, x, n)
s[1][1] = e[1] + a[1][1]
s[2][1] = e[2] + a[2][1]
for j = 2 to n
do
if s[1][j-1] + a[1][j] <= s[2][j-1] + t[2][j-1] + a[1][j]
then s[1][j] = s[1][j-1] + a[1][j]
l[1][j] = 1
else s[1][j] = s[2][j-1] + t[2][j-1] + a[1][j]
l[1][j] = 2
if s[2][j-1] <= s[1][j-1] + t[1][j-1]
then s[2][j] = s[2][j-1] + a[2][j]
l[2][j] = 2
else s[2][j] = s[1][j-1] + t[1][j-1] + a[2][j]
l[2][j] = 1
if s[1][n] + x[1] <= s[2][n] + x[2]
then s* = s[1][n] + x[1]
l* = 1
else s* = s[2][n] + x[2]
l* = 2
```

81
reviews/__pyfunc__/r7.py Normal file
View File

@@ -0,0 +1,81 @@
from bs4 import BeautifulSoup
MAIN_STYLE = "display: flex; gap: 50px;"
COLUMN_STYLE = "display: flex; flex-direction: column; gap: 12px;"
ARRAY_BLOCK_STYLE = "display: flex; align-items: center; gap: 8px;"
ARRAY_TABLE_TEMPLATE = "border-collapse: collapse; "
LABEL_STYLE = "font-size: 1.2em; font-weight: bold; width: 20px; text-align: center;"
TD_STYLE_TEMPLATE = "border: 1px solid black; width: 1.2em; height: 1.2rem; text-align: center; font-size: 0.8em;"
TH_STYLE_TEMPLATE = "font-weight: normal; border: none; width: 1.2em; height: 0.3rem; text-align: center; font-size: 0.8em;"
def td_style_with_gray(style):
return style + "background-color: lightgray;"
def td_style_with_no_right_border(style):
return style + "border-right: none;"
def create_array_block(soup: BeautifulSoup, label: str, head: list[int] | None, data: list[int]):
block = soup.new_tag("div", attrs = {'style': ARRAY_BLOCK_STYLE})
if label:
block.append(
soup.new_tag("span", string=label, attrs={"style": LABEL_STYLE})
)
table = soup.new_tag("table",
attrs = {"style": ARRAY_TABLE_TEMPLATE}
)
if head:
upper = soup.new_tag("thead")
tr = soup.new_tag("tr")
for h in head:
tr.append(soup.new_tag("th", string=str(h), attrs={"style": TH_STYLE_TEMPLATE}))
upper.append(tr)
table.append(upper)
body = soup.new_tag("tbody");
tr = soup.new_tag("tr")
for d in data:
tr.append(soup.new_tag("td", string=str(d), attrs={"style": TD_STYLE_TEMPLATE}))
body.append(tr)
table.append(body)
block.append(table)
return block
def create_main(soup: BeautifulSoup):
main = soup.new_tag("div", attrs={"style": MAIN_STYLE})
return main
def create_col(soup: BeautifulSoup):
col = soup.new_tag("div", attrs={"style": COLUMN_STYLE})
return col
def create_radix_table(soup: BeautifulSoup,
data = list[str],
highlighted: None | list[int] = None):
table = soup.new_tag("table")
tbody = soup.new_tag("tbody")
for word in data:
tr = soup.new_tag("tr")
for i, char in enumerate(word):
style = TD_STYLE_TEMPLATE
if i != len(word) - 1:
style = td_style_with_no_right_border(style)
if highlighted and i in highlighted:
style = td_style_with_gray(style)
td = soup.new_tag("td", string=char, attrs= {"style": style})
tr.append(td)
tbody.append(tr)
table.append(tbody)
return table