0% found this document useful (0 votes)
17 views

Implementation of Randomized Algorithm

The document implements a randomized algorithm to find repeated elements in an array. It defines an array with sample data, includes header files for random number generation and input/output functions. The main function calls a repetation function, passing the array and size, and the repetation function randomly swaps array elements and checks for matches over 100 iterations, printing the index of any repeated elements found. The output shows the indexes of repeated elements (values of 30 and 10) detected during the random swapping process.

Uploaded by

Maadurim Maaduri
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Implementation of Randomized Algorithm

The document implements a randomized algorithm to find repeated elements in an array. It defines an array with sample data, includes header files for random number generation and input/output functions. The main function calls a repetation function, passing the array and size, and the repetation function randomly swaps array elements and checks for matches over 100 iterations, printing the index of any repeated elements found. The output shows the indexes of repeated elements (values of 30 and 10) detected during the random swapping process.

Uploaded by

Maadurim Maaduri
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

IMPLEMENTATION OF RANDOMIZED ALGORITHM

PROGRAM: #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<time.h> int main() { int a[10]={10,20,30,40,11,12,13,10,30,30}; int n=10; void repetation(int q[],int n); clrscr(); printf("\n\tProgram Files the repeated element"); repetation(a,n); getch(); return 0; } void repetation(int a[],int n) { int i,j,count,t; time_t; srand((unsigned)time(&t)); count=1; while(count<100) { i=rand()%(n+1); j=rand()%(n+1); if((i!=j)&&(a[i]==a[j])) { printf("\nRepeated Element is present at Index %d",i); } count++; } }

OUTPUT: Program Files the repeated element Repeated Element is present at Index 0 Repeated Element is present at Index 8 Repeated Element is present at Index 0 Repeated Element is present at Index 2 Repeated Element is present at Index 7 Repeated Element is present at Index 9 Repeated Element is present at Index 9 Repeated Element is present at Index 2

You might also like