Question 4 (10 pts): Counting Duplicate Pairs in a Sequence
This algorithm counts the number of duplicate pairs in a sequence.
Analysis:
The worst-case time complexity of the algorithm is O(n^2).
Input: a1, a2,...,an, where n is the length of the sequence.
Output: count = the number of duplicate pairs.
count := 0
For i = 1 to n-1
For j = i+1 to n
If (ai = aj)
count := count + 1
End-for
End-for
Return count