diff --git a/assets/R8-1_1.png b/assets/R8-1_1.png new file mode 100644 index 0000000..224c45d Binary files /dev/null and b/assets/R8-1_1.png differ diff --git a/out/reviews/R7.pdf b/out/reviews/R7.pdf new file mode 100644 index 0000000..034f6d2 --- /dev/null +++ b/out/reviews/R7.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1065bba490c5a6158066a94503c5154b94c4eaf50ba16d9467c9a7811e3bc6d +size 163970 diff --git a/out/reviews/R7X.pdf b/out/reviews/R7X.pdf new file mode 100644 index 0000000..448fb0e --- /dev/null +++ b/out/reviews/R7X.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1282993305abd65bdc352c1c775ddd13a5c74240cb58049be5323ce868cc000 +size 34795 diff --git a/out/reviews/R8a.pdf b/out/reviews/R8a.pdf new file mode 100644 index 0000000..2c00b18 --- /dev/null +++ b/out/reviews/R8a.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bdc74816f6f88cb7a55d0191eb8b4fbe8435ade9ebb99e78587ca85f0c819861 +size 254664 diff --git a/reviews/R7.md b/reviews/R7.md new file mode 100644 index 0000000..754c62b --- /dev/null +++ b/reviews/R7.md @@ -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) +``` \ No newline at end of file diff --git a/reviews/R7X.md b/reviews/R7X.md new file mode 100644 index 0000000..eeb9005 --- /dev/null +++ b/reviews/R7X.md @@ -0,0 +1,11 @@ +# Review DataStructure + +* Hajin Ju, 2024062806 + +| * | Arrays
(not sorted) | Arrays
(sorted) | LinkedLists
(not sorted) | LinkedList
(sorted) | Binary ST
(avg) | Balanced ST | HashTables
(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$)
(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)$ | diff --git a/reviews/R8a.md b/reviews/R8a.md new file mode 100644 index 0000000..27e6714 --- /dev/null +++ b/reviews/R8a.md @@ -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 +``` \ No newline at end of file diff --git a/reviews/__pyfunc__/r7.py b/reviews/__pyfunc__/r7.py new file mode 100644 index 0000000..dbdbfaf --- /dev/null +++ b/reviews/__pyfunc__/r7.py @@ -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 + \ No newline at end of file