Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Algorithms and Analysis

COSC 2123/1285

Assignment 2: Algorithm Design & Complexity Analysis

IMPORTANT NOTES

•  If you are asked to design an algorithm, you need to describe it in plain En- glish rst,  say a paragraph,  and then provide an unambiguous pseudo code, unless specied otherwise. The description must include enough details to under- stand how the algorithm runs and what the complexity is roughly. All algorithm descriptions and pseudo codes required in this assignment are at most half a page in length. Worst-case complexity is assumed unless specified otherwise.

•  Standard array operations such as sorting,  linear search, binary search,  sum, max/min elements, as well as algorithms discussed in the pre-recorded lectures can be used straight away (but make sure to include the input and output if you are using them as a library). However, if some modification is needed, you have to provide a full description.  If you are not clear whether certain algorithms/opera- tions are standard or not, post it to Ed Discussion Forum or drop Hoang a Team message.

• Marks are given based on correctness, conciseness (with page limits), and clar- ity of your answers. If the marker thinks that the answer is completely not under- standable, a zero mark might be given.  If correct, ambiguous solutions may still receive a deduction of 0.5 mark for the lack of clarity.

•  Page limits apply to ALL problems in this assignment. Over-length answers may attract mark deduction (0.5 per question). We do this to (1) make sure you develop a concise solution and (2) to keep the reading/marking time under control. Please do NOT include the problem statements in your submission because this may increase Turnitin’s similarity scores significantly.

• This is an individual assignment. While you are encouraged to seek clarifications for questions on Ed Forum, please do NOT discuss solutions or post hints leading to solutions.

•  In the submission (your PDF le), you will be required to certify that the submitted solution represents your own work only by agreeing to the following statement:

I certify that this is all my own original work.   If I took any parts from elsewhere, then they were non-essential parts of the assignment, and they are clearly attributed in my submission.  I will show that I agree to this honour code by typing Yes":

1   Part I: Fundamental

Problem 1 (8 marks, 1 page). Consider the algorithm mystery() whose input consists of an array A of n integers, two nonnegative integers e, u satisfying 0 s e s u s n - 1, and an integer k. We assume that n is a power of 2.

Algorithm  mystery(A[0, . . . , (n - 1)], e, u, k)

if e == u then

if A [e] == k then

return  1;

else

return  0;

end if

else

m = l(e + u - 1)/2」;

return  mystery(A, e, m, k) +mystery(A, m + 1, u, k);

end if

a)  [2 marks] What does mystery(A[0..(n - 1)], 0, n - 1, k) compute (0.5 mark)? Justify your answer (1.5 marks).

b)  [1 mark] What is the algorithmic paradigm that the algorithm belongs to?

c)  [2 marks] Write the recurrence relation for C(n), the number of additions required by mystery(A, 0, n - 1, k).

d)  [2 marks] Solve the above recurrence relation by the backward substitution method to obtain an explicit formula for C(n) in n.

e)  [1 mark] Write the complexity class that C(n) belongs to using the Big-o notation.

Problem 2 (8 marks, 1.5 pages). Let A be an array of n integers.

a)  [2 marks] Describe a brute-force algorithm that nds the minimum difference be- tween two distinct elements of the array, where the difference between a and b is defined to be la - bl [1 mark].  Analyse the time complexity (worst-case) of the algorithm using the big-O notation [1 mark]. Pseudocode/example demonstration are NOT required. Example: A = [3, -6, 1, -3, 20, 6, -9, -15], output is 2 = 3-1.

b)  [2 marks] Design a transform-and-conquer algorithm that nds the minimum dif- ference between two distinct elements of the array with worst-case time complexity O(n log(n)):  description [1 mark], complexity analysis [1 mark].  Pseudocode/ex- ample demonstration are NOT required. If your algorithm only has average-case complexity O(n log(n)) then a 0.5 mark deduction applies.

c)  [4 marks] Given that A is already sorted in a non-decreasing order, design an al- gorithm with worst-case time complexity O(n) that outputs the absolute values of the elements of A in an increasing order with no duplications: description and pseudocode [2 marks], complexity analysis [1 mark], example demonstration on the provided A [1 mark]. If your algorithm only has average-case complexity O(n) then 2 marks will be deducted.  Example:  for A = [-15, -9, -6, -3, 1, 3, 6, 20], the output is B = [1, 3, 6, 9, 15, 20].

Problem 3. [10 marks, 1.5 pages] (Dijkstras algorithm + min-heap) Given a graph as in Fig. 1, we are interested in nding the shortest paths from the source a to all other vertices using the Dijkstras algorithm and a min-heap as a priority queue. Note that a min-heap is the same as a max-heap, except that the key stored at a parent node is required to be smaller than or equal to the keys stored at its two child nodes.  In the context of the Dijkstra’s algorithm, a node in the min-heap tree has the format v(pv , dv), where dv  is the length of the current shortest path from the source to v and pv  is the second to last node along that part (right before v). For example, c(a, 1) is one such node. We treat dv as the key of Node v in the heap, where v e {a, b, c, d, e, f , g, h}.

2            e

7              g

Figure 1: An input graph for the Dijkstra’s algorithm. Edge weights are given as integers next to the edges. For example, the weight of the edge (a, b) is 7.

a)  [1 mark] The min-heap after a(a, 0) is removed is given in Fig. 2. The next node to be removed from the heap is c(a, 1). Draw the heap after c(a, 1) has been removed and the tree has been heapified, assuming that o > o (note: no need to swap if both parent and children are o). No intermediate steps are required.

c(a,1)

h(─ , ~)

b(a,7)       e(─ , ~)      f(─ , ~)     g(─ , ~)

Figure 2: The min-heap (priority queue) after a(a, 0) has been removed.

b)  [2 marks] Draw the heap(s) after each neighbour of c has been updated and the tree has been heapified (see the pseudocode in the lecture Slide 30, Week 9). If there are multiple updates then draw multiple heaps, each of which is obtained after one update. Note that neighbours are updated in the alphabetical order, e.g., d must be updated before e.  No intermediate steps, i.e., swaps, are required.  Follow the discussion on Ed Forum for how to update a node in a heap.

 

S :  vertices whose shortest paths have been known

Priority queue of remaining vertices

1

a(a, 0)

b(a, 7), c(a, 1), d(a, 5), e(-, o), f(-, o), g(-, o), h(-, o)

2

a(a, 0), c(a, 1)

 

3

 

 

4

 

 

5

 

 

6

 

 

7

 

 

8

 

 

Table 1: Complete this table for Part c).

c)  [5 marks] Complete Table 1with correct answers. You are required to follow strictly the steps in the Dijkstra’s algorithm taught in the lecture of Week 9.

d)  [2 marks] Fill Table 2with the shortest paths AND the corresponding distances from a to ALL other vertices in the format a 一? 一? v l dv, for instance, a  c l 1.

 

Shortest Paths

Distances

a

a a

0

b

 

 

c

a  c

1

d

 

 

e

 

 

f

 

 

g

 

 

h

 

 

Table 2: Complete this table for Part d).

2   Part II: Advanced

Problem 4 (9 marks, 1.5 pages). A database of n records, each of which has size m bits (we assume that m is large) is maintained at two different servers X and Y. As sometimes a record may get updated at one server and not at the other, the servers X and Y have to sync their (possibly different) databases y = (x1 , . . . , xn) and y = (y1 , . . . , yn) from time to time to make sure they are the same.  At the synchronization time, the two servers exchange some data in one or several rounds of communications.

trivial synchronisation algorithm is as follows: X sends y via the internet to Y, which verifies every record of y against that of its database y; for each 1 s i s n, ifxi = yi then Y does nothing, otherwise, it will either update yi - xi if xi is newer or send (i, yi) to X if its record is newer; upon receiving a pair (i, yi), X updates xi  - yi .  We assume there is an efficient mechanism (which is not our focus) to decide which version of the record is newer (e.g., using a naming convention like ver-1.2.1 is newer than ver-1.2.0). While this solution works, it requires a huge bandwidth because at least n records have to be sent across the network.

Our goal is to design a more efficient protocol/algorithms using a tool called crypto- graphic hash function.  A cryptographic hash function h(.) takes as input any piece of data x of any size and returns a xed-size string h(x) (e.g., h(x) is of size 256 bits for SHA-256). Moreover, different from a non-cryptographic hash function (Week 11), they are collision-resistant, that is, it’s hard to nd two different inputs that hash to the same output. As a consequence, in practice, we can assume that if a \= b then h(a) \= h(b). For simplicity, we assume that the following assumptions hold.

• At most one item is different between the two databases, that is, either xi = yi for all i = 1, . . . , n, or there exists an index i * such that xi*  \= yi*  and xi = yi for all i \= i* .

• The computation complexity is measured by the number of hashes required to be computed by both X and Y and also by the amount of data that are hashed. For instance, the trivial protocol described above requires no hash computation, and hence, the computation complexity is zero.

• The communication complexity is measured by the number of hashes and the number of records communicated between X and Y. For instance, the trivial proto- col sends no hashes and n records, which is very expensive (a record is much larger than a hash).

Your task is to design a synchronisation algorithm that requires a small communi- cation complexity (most important) and also a reasonable computation complexity. More specifically, you need to include the following in your answer.

a)  (Overview - 2 mark) An overview of how your algorithm works, why it solves the problem, and what are the communication and computation complexities.

b)  (Detailed description - 3 marks) A detailed description of the main steps of the algorithm, describing what X and Y do to sync the two databases. You could also write your description using a pseudocode. The goal is to guarantee that other peo- ple can understand clearly how the algorithm works. The format of the pseudocode is not important.

c)  (Demonstration - 2 marks) A demonstration of how the algorithm works on a small example, e.g., when n = 8.

d)  (Analysis - 2 marks) State the communication and computation complexities of your algorithm and explain why it has these complexities. The input size is (n, m).

The given marks are maximum possible for the parts.  Your actual marks depend on how efcient your algorithm is (regarding the communication complexity (major crite- ria) AND the computation complexity) and also how well it is presented. A correct and efficient but poorly written solution could still attract a low mark. An incorrect solution will get a zero mark.

Problem 5 (5 marks, 2 pages). Research a well-known problem of your own interest in any field (science, engineering, technology) that can be solved by a computer algorithm. Write a 1- to 2-page report on a popular algorithm that solves that particular prob- lem and include in your report: (1) a problem description and why it is important and/or interesting, (2) the algorithm description, (3) a pseudocode, (4) a demonstration on a toy example, and (5) a complexity analysis.

You could include a few (1-5) references that you used when researching the prob- lem/algorithm, but the writing should be your own. A similarity score of 25% and above between your report and any existing source may indicate plagiarism. The report should be typed in a text editor, e.g., words or Latex, and not handwritten. Marks will be decided based on the correctness, clarity, and the sophistication of the problem/al- gorithm discussed.  A report that is not well written or about a trivial/straightforward problem/algorithm will receive a low mark.

Note that the problem/algorithm should NOT be among those already discussed in the pre-recorded lectures/workshops. If you present a problem/algorithm that has been discussed in the lectures/workshops, you will get a zero mark for Problem 5.

You could start from our textbook or check the following list from Wiki for a start. https://en.wikipedia.org/wiki/List_of_algorithms

3   Submission

The nal submission (via Canvas) will consist of:

• Your solutions to all questions in a PDF le of font size 12pt and your agreement to the honour code (see the rst page).

Late Submission Penalty: Late submissions will incur a 10% penalty on the total marks of the corresponding assessment task per day or part of day late, i.e, 4 marks per day. Submissions that are late by 5 days or more are not accepted and will be awarded zero, unless Special Consideration has been granted.  Granted Special Considerations

with new due date set after the results have been released (typically 2 weeks after the deadline) will automatically result in an equivalent assessment in the form of a practical test, assessing the same knowledge and skills of the assignment (location and time to be arranged by the coordinator).  Please ensure your submission is correct and up-to-date, re-submissions after the due date and time will be considered as late sub- missions. The core teaching servers and Canvas can be slow, so please do double check ensure you have your assignments done and submitted a little before the submission deadline to avoid submitting late.

Assessment declaration: By submitting this assessment, you agree to the assess- ment declaration - https://www.rmit.edu.au/students/student-essentials/ assessment-and- exams/assessment/assessment-declaration

4   Plagiarism Policy

University Policy on Academic Honesty and Plagiarism: You are reminded that all sub- mitted work in this subject is to be the work of you alone. It should not be shared with other students. Multiple automated similarity checking software will be used to compare submissions. It is University policy that cheating by students in any form is not permit- ted, and that work submitted for assessment purposes must be the independent work of the student(s) concerned. Plagiarism of any form will result in zero marks being given for this assessment, and can result in disciplinary action.

For more details, please see the policy at                                                                             https://www.rmit.edu.au/students/student-essentials/assessment-and-results/ academic-integrity.

5   Getting Help

There are multiple venues to get help. We will hold separate Q&A sessions exclusively for Assignment 2. We encourage you to check and participate in the Ed Discussion Fo- rum, on which we have a pinned discussion thread for this assignment.  Although we

encourage participation in the forums, please refrain from posting solutions or sugges- tions leading to solutions.