Assign #8 Questions - faculty at Chemeketa

General
For ALL Word processing documents, you must submit your documents in one of the following formats: MS-Word
(.doc/.docx) or PDF (common read only format). They will be returned ungraded if submitted in any other format.
Submit assignments all assignments via elearn - attach your word document to your submission. Do NOT copy and paste
your document into the submission text box. (It mangles formatting and makes it much harder for me to read
submissions).
Assignment Instructions
Below are the questions for the assignment. Write your answers in the separate Answer document Optional challenge
questions are just for your own learning; they do not count toward grading.
Part 1: Mergesort & Divide and Conquer
Q1: Show this list being merge sorted. Display the contents of the list after each merge step runs:
12
5
9
8
16
4
13
22
20
18
14
15
3
1
11
24
Q2: Run the sort timer program from the CS160Reader (bottom of this page):
http://computerscience.chemeketa.edu/cs160Reader/Algorithms/MergeSortEfficiency2.html
Use it to fill out this table with the Approximate Computer Time used to sort an array of the given size (set
Number of arrays to 1) using the given algorithm:
Items
Insertion Sort
Merge Sort
100
1,000
10,000
100,000
SKIP
a) Use your timing for sorting 10,000 items to predict how long it would take to sort 100,000,000 items with
insertion sort. Use the estimation technique from week 7 - show work. Express your answer in years.
Hint: When solving, make sure to use work done, not number of items
b) Use your timing from sorting 100,000 items to predict how many seconds it would take to sort 100,000,000
items with merge sort – show work.
Part 2: SNAP Recursion
Q3: Make versions of the tree script that do the following - replace my picture with a picture of your code. Hint - it is
easier to debug a 2 level tree than a 10 level one…
A) Expanding tree - new branches are longer than the B) Unbalanced triple tree. Three branches, but
trunk they grow out of.
leaning to one side.
Q4: We can do division via successive subtraction using this recipe:
π‘₯ = 0:0
π·π‘–π‘£π‘–π‘ π‘œπ‘›(π‘₯, 𝑦) {
π‘₯ > 0 : 1 + π·π‘–π‘£π‘–π‘ π‘–π‘œπ‘›(π‘₯ βˆ’ 𝑦, 𝑦)
A) Complete this evaluation of the function and show that it produces the correct answer:
(See BYOB Tutorial for sample… you should keep evaluating until you reach a numeric value).
Division(18, 3)
= 1 + Division(15,3)
= 1 + (1 + Division(12, 3))
= …
B) Paste in a screenshot that shows a BYOB block that reports the answer to a division problem by calculating it with
this recursive algorithm.
Q5: Euclid's algorithm (https://www.youtube.com/watch?v=JUzYl1TYMcU) for finding the greatest common divisor of
two numbers x and y is defined recursively as this:
𝐺𝐢𝐷(π‘₯, 𝑦) {
𝑦 𝑑𝑖𝑣𝑖𝑑𝑒𝑠 𝑒𝑣𝑒𝑛𝑙𝑦 π‘–π‘›π‘‘π‘œ π‘₯ ∢ 𝑦
𝑦 π‘‘π‘œπ‘’π‘  π‘›π‘œπ‘‘ 𝑑𝑖𝑣𝑖𝑑𝑒 π‘₯ 𝑒𝑣𝑒𝑛𝑙𝑦 ∢ 𝐺𝐢𝐷(𝑦, π‘₯ π‘šπ‘œπ‘‘ 𝑦)
Where mod is "clock" arithmetic - divide x by y and keep the remainder.
A) Complete this evaluation of the function and show that it produces the correct answer:
(See BYOB Tutorial for sample… you should keep evaluating until you reach a numeric value).
GCD(3084, 1424)
= GCD(1424, 236)
= …
B) Paste in a screenshot that shows a BYOB version of this recursive GCD block. Hints:
β€’ BYOB has a mod block built in:
β€’ Testing "does y divide evenly into x?" is the same as testing "is (x mod y) equal to 0?" If y divides evenly into x,
the remainder after dividing is 0.
Q6: Make a divide and conquer (recursive) style block that determines if any of the items in a list are greater than 100:
There are not explicit levels of credit on this one, but submit a picture of your best attempt. You can get partial credit
for using the right approach even if your block is flawed and does not produce the correct answer all the time.
Hint: the logic for this is almost identical to the <(list) contains (thing)> block from BYOB video 4-4.
Part 3: Search
Solve each of the following problems using a best-first search method as described in the weekly supplement. Diagram
out your search trees; note that you will need to design a representation of each state in the tree that is appropriate
to the problem that you are solving IMPORTANT NOTE: Most of the points for these problems will be based on
showing the work to apply the technique correctly. Just showing the correct answer will earn few if any points.
Q7: In the map below, assume that the numbers by each line are minutes it would take to travel from one location to
another. Show a search tree representing finding the best path from location 1 to location 3. (Easiest to do by hand and
paste in a picture/scan)
Q8: What is the minimum number of steps required to transform the eight-puzzle below into its solution state?
Solve this using the method and evaluation functions shown in the background section. Show the tree required to solve
it – and the heuristic β€œcost” of each state, NOT JUST the correct sequence. (Easiest to do by hand and paste in a
picture/scan)