Thank you for your helpful answer Consider the following met


Thank you for your helpful answer!
Consider the following method: bool hasDuplicates(int V[], int n) {for (int i=0; i

Solution

1)

So we can see that the total number of times the sequence of statements executes is:

N + N-1 + N-2 + ... + 3 + 2 + 1. the total is O(N2).

2)

Use count array to store frequency of each element in an array

traverse the entire array and find maximum element

create an array with size of maximum element and instantiate to zero

now traverse count array and see if it has value 2 for any index

if it has then array has duplicates

else no

O(n) complexity

Value of i Number of iterations of inner loop
0 N
1 N-1
2 N-2
... ...
N-2 2
N-1 1
 Thank you for your helpful answer! Consider the following method: bool hasDuplicates(int V[], int n) {for (int i=0; iSolution1) So we can see that the total nu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site