Explore
ProGrad Programs
Placement Prep
About Us

Edit
Reply

Edit

# Program to find non repeating element in an array (Unique elements)

Published on 09 Mar 2020

Finding the non repeating element in an array can be done in 2 different ways.

Method 1: Use two loops, one for the current element and the other to check if the element is already present in the array or not.

Method 2: Traverse the array and insert the array elements and their number of occurences in the hash table. Traverse the array again and print the array elements with count = 1.

## Method 1 to find non repeating element in an array

An easier approach to find all non-repeating element in an array is to use two loops. Use the first loop for traversing the array and the second loop to check if the current element is already present in the array or not.

Algorithm

• Declare the array and input the array elements.
• Start traversing the array and check if the current element is already present in the array.
• If it is already present in the array, move to the next element in the array and continue.
• If not, output the element as the non-repeating element.

C
C++

Output
Input- Enter the number of elements: 5 Input the array elements:1 2 3 4 1 Output- Non-repeating element[1]:2 Non-repeating element[2]:3 Non-repeating element[3]:4

## Method 2 for finding non repeating element in an array

The time complexity of this problem can be reduced by using hash tables. The array is traversed and the array elements along with their counts is stored in the hash table. Then the array is traversed again and the elements having their counts = 1 are displayed as non-repeating elements or unique elements in the array.

Algorithm

• Declare the array and input the array elements.
• Insert all the array elements in the hash table.
• Traverse the array again and display the array elements having their count = 1.

C++
Python 3

Output
Input- Enter the number of elements: 5 Input the array elements:1 2 3 4 1 Output- Non-repeating element[1]:2 Non-repeating element[2]:3 Non-repeating element[3]:4

### Recommended Programs

If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in
Explore 'c'