CREATE OWN LIBRARY

Find out the unique elements from the Array

Back to Programming

Description

The elements of the array are taken as input. The program is to find out the unique elements from the array. Unique elements refer to those elements which appear exactly ones in the array.

 

Algorithm

INPUT: The array elements
OUTPUT: the unique elements of the array
PROCESS:
Step 1: [Taking inputs from the user]
	Read n [number of elements]
	For i = 0 to n-1 repeat
		Read a[i]
	[End of ‘for’ loop]
Step 2: [Finding the unique elements]
For i=0 to n-1 repeat
        		Set c<-0
	    	For j=0 to i-1 repeat
            			If a[i]=a[j] then
                			Set c<-c+1
            			[End of ‘if’]
        		[End of ‘for’ loop]
       		For k=i+1 to n-1 repeat
            			If a[i]=a[k] then
                			Set c<-c+1
            			[End of ‘if’]
        		[End of ‘for’ loop]
		If c=0 then
          			Print a[i]
		[End of ‘if’]
        [End of ‘for’ loop]

Code

Complexity: