🎁BACK-TO-SCHOOL DEAL. Subscribe Now to get 40% OFF at only 8.49 USD/month, only valid until Sep 30th, 2024

Question

This question asks you to perform competitive analysis of transpose (TR) and frequency count (FC).
(i) [5 marks] Suppose that you are maintaining a list of n elements under access operation only. The cost of access to the i-th element in the list is i. Let S be a 
request sequence of m access operations over this list. For any sufficiently large m, construct a request sequence S such that for this request sequence, the total cost of TR divided by the total cost of MTF is ω(1).
(ii) [5 marks] Use the result of (i) to argue that TR is not competitive.
Hint: You just have to use the definition of competitiveness. Therefore, You can 
solve this subquestion without having to solve (i) first.
(iii) [5 marks] Further prove that FC is not competitive, either.

Asked By StormySkies20 at

Answered By Expert

Jay

Expert · 5.9k answers · 5k people helped

Step 1/1

Step 1 The question is related to computer science, specifically in the area of algorithm analysis and competitive analysis of caching algorithms. This question asks you to perform a competitive analysis of transpose (TR) and frequency count (FC). (i) Suppose that you are maintaining a list of n elements under access operation only. The cost of access to the i-th element in the list is i. Let S be a request sequence of m access operations over this list. For any sufficiently large m, construct a request sequence S such that for this request sequence, the total cost of TR divided by the total cost of MTF is ω(1). (ii) Use the result of (i) to argue that TR is not competitive. Hint: You just have to use the definition of competitiveness. Therefore, You can solve this subquestion without having to solve (i) first. (iii) Further prove that FC is not competitive, either. Step 2 (i) To construct a request sequence S such that the total cost of TR divided by the total cost of MTF is ω(1), we can design S as follows: Access the elements in reverse order, so the cost of accessing the i-th element is n - i + 1. Repeat the access sequence S multiple times. By accessing the elements in reverse order and repeating the sequence multiple times, the total cost of TR will be O(n^2) because each access will require swapping n-i+1 elements. The total cost of MTF, on the other hand, will be O(nm) because each access may require moving up to m elements to the front of the list. Therefore, the total cost of TR divided by the total cost of MTF is ω(1). (ii) To show that TR is not competitive, we can use the definition of competitiveness, which states that a caching algorithm A is c-competitive if, for any request sequence S of length m, the total cost of A on S is at most c times the optimal offline algorithm OPT on S, plus some constant factor. From part (i), we have shown that there exists a request sequence S such that the total cost of TR divided by the total cost of MTF is ω(1). Therefore, TR cannot be c-competitive for any constant c, because for sufficiently large m, the total cost of TR on S will be much larger than the total cost of MTF on S. (iii) To show that FC is not competitive, we can use a similar argument as in part (ii). Suppose we have a request sequence S such that the first m/2 accesses are to the same element x, and the second m/2 accesses are to another element y. Then, the total cost of FC on S will be O(m), because it will need to count the frequency of each element before moving x and y to the front of the list. However, the optimal offline algorithm OPT can simply move x to the front of the list for the first m/2 accesses, and then move y to the front for the remaining accesses, resulting in a total cost of O(m/2). Therefore, the total cost of FC on S divided by the total cost of OPT on S is ω(1), and FC is not c-competitive for any constant c.

Final Answer

Hence the answer above explained the final answer are given above accordingly to the question

🧑‍🏫 More Questions

Problem 2: Recursive Binary Search Write a recursive function binary_search that takes an ordered array of numbers a and a number to search for n as parameters and returns the index of the first occurrence of the number in the array, or -1 otherwise. For full credit, the search should be implemented using recursion, rather than a loop. Given a = [-1, 1, 3, 5, 7, 9]: Example call Returns linear_search(a, 1) 1 linear_search (a,0) -1 linear_search(a, -1) 0 linear_search(a, 2) -1 linear_search(a, -2) -1 linear_search(a, 4) -1 binary_search.py 1 # MODIFY ME TO IMPLEMENT YOUR SOLUTION 2 # TO PROBLEM 2: Recursive Binary Search 3 # 4 # NAME: FIXME 5 # ASSIGNMENT: Technical HW: Sorting & Searching 6 7 # Write a recursive function 'binary_search that 8 # takes an ordered array of numbers as a parameter 9 # and a number to search for and returns the index 10 # of the number in the array, or -1 otherwise. For 11 # full credit, the search should be implemented using 12 # recursion, rather than a loop. 13 def binary_search(array, num): 14 | return search(array, num, 0, len(array) - 1) 15 16 def search(array, num, min, max): 17 TIT return -1 18 19 def main(): 20 a = [i for i in range(-1, 10, 2)] 21 print(a) 22 for n in (1, 0, -1, 2, -2, 4, 5, 6, 7, -67, 134]: 23 print("%5d index? %d" % (n, binary_search(a, n)) ) 24 main() 25 I'I binary_search_test.py From binary_search import binary_search 1 2 3 def test_empty(): assert binary_search([], 0) == -1 4 5 6 7 8 9 def test_1(): a = [-67, -44, -2, 33, 45, 67, 134] accont hinary_search(a, 1) == == -1 test_o() def test 0(): a = [-67, -44, -2, 33, 45, 67, 134] assert binary_search(a,0) == -1 10 11 12 13 14 15 def test__1(): a = [-67, -44, -2, 33, 45, 67, 134] assert binary_search(a, -1) == -1 16 17 18 19 def test_2(): a = [-67, -44, -2, 33, 45, 67, 134] assert binary_search(a, 2) == -1 20 21 22 23 def test_2(): a = [-67, -44, -2, 33, 45, 67, 134] assert binary_search(a, -2) == 2 24 25 binary_search_test.py - 3 3 25 26 def test_134(): 27 a = [-67, -44, -2, 33, 45, 67, 134] 28 assert binary_search(a, 134) == 6 29 30 def test_67(): 31 a = [-67, -44, -2, 33, 45, 67, 134] 32 assert binary_search(a, 67) == 5 33 34 E def test__67(): 35 a = [-67, -44, -2, 33, 45, 67, 134] 36 assert binary_search(a, -67) 37 38 E def test_first(): 39 a = [1, 1, 1, 2, 2, 2, 2, 2, 2] 40 assert binary_search(a, 2) == 3 41 42 E def test_first1(): 43 a = [1, 1, 1, 2, 2, 2, 2, 2, 2] 44 assert binary_search(a, 1) == 0 45 46 def test_last(): 47 a = [1, 1, 1, 2, 2, 2, 2, 2, 2, 3] 48 assert binary_search(a, 3) == 9 49 5 50

<p>Identify the components contained in each of the following lipids.</p> <p><strong>Part A</strong></p> <p>glycerophospholipid</p> <p>Check all that apply.</p> <p>Check all that apply.</p> <table> <tbody> <tr> <td>&nbsp;</td> <td>glycerol</td> </tr> <tr> <td>&nbsp;</td> <td>fatty acid</td> </tr> <tr> <td>&nbsp;</td> <td>phosphate</td> </tr> <tr> <td>&nbsp;</td> <td>amino alcohol</td> </tr> <tr> <td>&nbsp;</td> <td>steroid nucleus</td> </tr> <tr> <td>&nbsp;</td> <td>sphingosine</td> </tr> </tbody> </table> <p> <strong>Submit</strong><strong>My&nbsp;Answers</strong><strong>Give&nbsp;Up</strong></p> <p><strong>Part B</strong></p> <p>sphingomyelin</p> <p>Check all that apply.</p> <p>Check all that apply.</p> <table> <tbody> <tr> <td>&nbsp;</td> <td>glycerol</td> </tr> <tr> <td>&nbsp;</td> <td>fatty acid</td> </tr> <tr> <td>&nbsp;</td> <td>phosphate</td> </tr> <tr> <td>&nbsp;</td> <td>amino alcohol</td> </tr> <tr> <td>&nbsp;</td> <td>steroid nucleus</td> </tr> <tr> <td>&nbsp;</td> <td>sphingosine</td> </tr> </tbody> </table> <p> <strong>Submit</strong><strong>My&nbsp;Answers</strong><strong>Give&nbsp;Up</strong></p> <p><strong>Part C</strong></p> <p>aldosterone</p> <p>Check all that apply.</p> <p>Check all that apply.</p> <table> <tbody> <tr> <td>&nbsp;</td> <td>glycerol</td> </tr> <tr> <td>&nbsp;</td> <td>fatty acid</td> </tr> <tr> <td>&nbsp;</td> <td>phosphate</td> </tr> <tr> <td>&nbsp;</td> <td>amino alcohol</td> </tr> <tr> <td>&nbsp;</td> <td>steroid nucleus</td> </tr> <tr> <td>&nbsp;</td> <td>sphingosine</td> </tr> </tbody> </table> <p> <strong>Submit</strong><strong>My&nbsp;Answers</strong><strong>Give&nbsp;Up</strong></p> <p><strong>Part D</strong></p> <p>linoleic acid</p> <p>Check all that apply.</p> <p>Check all that apply.</p> <table> <tbody> <tr> <td>&nbsp;</td> <td>glycerol</td> </tr> <tr> <td>&nbsp;</td> <td>fatty acid</td> </tr> <tr> <td>&nbsp;</td> <td>phosphate</td> </tr> <tr> <td>&nbsp;</td> <td>amino alcohol</td> </tr> <tr> <td>&nbsp;</td> <td>steroid nucleus</td> </tr> <tr> <td>&nbsp;</td> <td>sphingosine</td> </tr> </tbody> </table>