Files
2025-10-05 17:53:11 +09:00

3.7 KiB

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

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)



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

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)