(a) Let take Array to be the name of the array and n be its size
Array[n] /* Array declaration */
Int i, j, n /* Variables declaration */
for (i = 0, i< n - 1, i++) /* Checking if ith index value has a
duplicate */
for (j = i + 1, j < n, j++) /* Range of next value (i+1) to n */
if (Array[i]==Array[j]) /* Making comparison to check if the
values are the same */
return TRUE /* return if duplicates are found*/
return FALSE /* return if duplicates are not found */
(b)
(c) Time complexity
Let’s use the example below:
If Array[10]={10, 20, 30, 40, 50, 60, 70, 80, 90, 100}, then the algorithm will not find any
duplicates.
for (j = i + 1, j < n, j++) iterates as below:
(n)*(n – 1)/2 = n2 – n/2
The worst case is therefore O(n2)