Write an algorithm ie Pseudocode for the following problem I
Write an algorithm (i.e. Pseudocode) for the following problem: Input: An Array named A of size \"n\" of type \"Integer\" Output: if there exist indices 1<=i<=n and 1<=j<=n, i NOT equal to j, such that A[i]=A[j] then return true, otherwise return false. Once you write a solution to this problem, describe what is the Big-O running time of your algorithm. Justify your answer.
Solution
For j=1 to n
if A[i] == A[j] and i !=j then
return true;
end For
end For
end
The above given algorithm is used to identify whether there are two similar elements in the given array. Time complexity is given as
O(n^2)
this is because, outer for loop with \'i\' as loop variable will run for \'n\' times and inner for loop with \'j\' as loop variable will run for \'n\' times each and so total those two loops will run for n*n times
