In: Computer Science
Q1. Write an algorithm to do the following operation on an array passed as parameter: If an element of the array is having more than one occurrence, then keep the first occurrence and remove all other occurrences of the element.
Please find the answer below.
There can be two types of array
1) Sorted array : { 1, 2, 3 , 4, 5, 5 }
2) Unsorted array : { 1, 4, 5, 2, 6, 4 }
1) Algorithm to remove duplicate elements in a sorted array:
2) Algorithm to remove duplicate elements in an unsorted array :