COMP2123 Assignment 1
COMP2123 Assignment 1
This assignment is due on March 22. Submit your assignment via Grade-
scope. All submitted work must be done individually without consulting some-
one else’s solutions in accordance with the University’s “Academic Dishonesty
and Plagiarism” policies.
As a first step, go to the last page and read the section: Advice on how to do
the homework.
1: function algorithm(A)
2: n ← length of A
3: num_matches ← 0
4: for i ∈ [0 : n] do ▷ i ranges from 0 to n − 1
5: for j ∈ [i + 1 : n] do ▷ j ranges from i + 1 to n − 1
6: if A[i ] == A[ j] then
7: num_matches ← num_matches + 1
8: return num_matches
1
ds & a Assignment 1 s1 2024
Example:
B = [1, 4, 4, 6], m = 7 → return 4
2
ds & a Assignment 1 s1 2024
• When designing an algorithm or data structure, it might help you (and us)
if you briefly describe your general idea, and after that you might want to
develop and elaborate on details. If we don’t see/understand your general
idea, we cannot give you points for it.
• Some of the questions are very easy (with the help of the lecture notes or
book). You can use the material presented in the lecture or book without
proving it. You do not need to write more than necessary.
• If you do give (pseudo-)code, then you still have to explain your code and
your ideas in plain English.
• If you use additional resources (books, scientific papers, the internet, etc.)
to formulate your answers, then add references to your sources.