CrazyEngineers
  • Algorithm to delete all occurence of duplicate elements from a list of array

    Ishita H.Katiyar

    Ishita H.Katiyar

    @ishita-hkatiyar-FHFBYP
    Updated: Oct 26, 2024
    Views: 1.5K
    what will be the algorithm for "to delete all occurence of duplicate elements from a list of array"?
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Kaustubh Katdare

    AdministratorOct 5, 2015

    Ishita H.Katiyar
    what will be the algorithm for "to delete all occurence of duplicate elements from a list of array"?
    Welcome to CE, #-Link-Snipped-# . Have you made any attempts to write the algorithm? If yes, please share them with us. Do not worry about being right or wrong. I'm sure our fellow engineers will help you out with all your questions.
    Are you sure? This action cannot be undone.
    Cancel
  • Ramani Aswath

    MemberOct 5, 2015

    #-Link-Snipped-#
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberOct 8, 2015

    Ishita H.Katiyar
    what will be the algorithm for "to delete all occurence of duplicate elements from a list of array"?
    There can be multiple algorithms to achieve any particular task.
    For example, a workable algorithm will be, to check each element to all the elements after it, and in case of any match, delete that element. ☕
    Are you sure? This action cannot be undone.
    Cancel
  • Ramani Aswath

    MemberOct 8, 2015

    rahul69
    in case of any match, delete that element.
    Agree. However, since there can be more than one match it may be better to delete the matching ones.
    Are you sure? This action cannot be undone.
    Cancel
  • Jai Krishna

    MemberOct 8, 2015

    Start with a brute for algorithm e.g. sort the array and iterate through it once. If a number changes from one array index to the next keep it otherwise dont.

    This can then be improved depending on runtime and space requirements, whether holes are allowed in the result or not etc.
    Are you sure? This action cannot be undone.
    Cancel
  • pratap singh, upendra

    MemberOct 11, 2015

    1. Store the elements in the array say a[].
    2. Now create a dynamic linked list to store the output.
    3. Select elements from the array a[] one at a time
    4. Put this element in linked list only when it is not already present in the linked list .
    5. Iterate steps 3 and 4 through the array a[].
    That's all.... Hope it helps.

    This method also reduces the space complexity of the program compared to storing the output in another array.
    Are you sure? This action cannot be undone.
    Cancel
  • simplycoder

    MemberOct 23, 2015

    1)Sort the elements.
    2)Delete the groups.
    Are you sure? This action cannot be undone.
    Cancel
  • pratap singh, upendra

    MemberOct 23, 2015

    simplycoder
    1)Sort the elements.
    2)Delete the groups.
    Could you please elaborate?
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberOct 26, 2015

    proffy
    Could you please elaborate?
    I guess he says that, After sorting, duplicate elements will come together, thus those could be deleted in groups.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register