You are on page 1of 10

/*write a C program to remove

duplicate number from an unsorted


process using deletion process*\
Roll No:23B81A0556
Btech- CSE
Section-A
Explanation of the problem:

• To solve the problem of removing duplicate numbers from an


unsorted array in C through deletion, you can follow these steps:
• Iterate through the array.
• For each element, check if it appears later in the array.
• If a duplicate is found, shift the remaining elements to fill the gap.
• Update the array size accordingly.
Code of the program:
Sample input:2 4 3 2 3 1

Sample output:2 4 3 1
Tracing:
• Given Array: 4, 2, 8, 3, 6, 4, 8, 2, 9
• Step 1:Intialization
• Size=9
• Step 2:Printing original array
• Original array: 4 2 8 3 6 4 8 2 9
• Step 3:Iteration
• Iterating through each element of array
• i=0;
• arr[0]=4
Inner loop:
• J=1;4==2(no match)
• J=2;4==8(no match)
• J=3;4==3(no match)
• J=4;4==6(no match)
• J=5;4==4(duplicate found)
• Shifting: ‘2 8 3 6 4 2 9’
• Updated size:’8’
• J decremented to recheck the current index
i=1;
arr[i]=2
• J=2;2==8(no match)
• J=3;2==3(no match)
• J=4;2==6(no match)
• J=5;2==4(no match)
• J=6;2==8(duplicate found)
• Shifting: ‘8 3 6 4 8 2 9’
• Updated size:’7’
• J decremented to recheck the current index
i=2;
arr[2]=8
• J=3;2==3(no match)
• J=4;2==6(no match)
• J=5;2==4(no match)
• J=6;2=(duplicate found)
• Shifting: ‘3 6 4 8 2 9’
• Updated size:’6’
• J decremented to recheck the current index
• ….and so until the end of the array.
Step 4:
• Printing array after removing Duplicates:

• Array after removing duplicates: 3 6 4 8 2 9


Any Queries?

You might also like