Re: repeating elements in an array



mohangupta13 wrote:
hello all,
Hope everyone is in the pink of perfection ! ...i was out for a long
time i think ..

anyway i had two problems to discuss ...

1. Given an array in which only one pair of number ( say integers ) is
repeating ,all other numbers are distinct ..what is the best possible
algo to find such number ..?? ( say for both cases when we dont have
any constraint on the numbers and when we do define some constrain say
the range of possible numbers in the array)...

Lacking a definition of "best", the simplest way is to sort the array, and then iterate through it looking for adjacent elements with the same value.

2. (this may not be suited here but still ) What is the probability
that out of 5 persons, no two person have birthday on the same day of
a week (..i.e all 5 have birthdays on different days of a week)..???

7! / (7-5)!
-----------
5
7

= 7 * 6 * 5 * 4 * 3
-----------------
7 * 7 * 7 * 7 * 7

= 360/2401, or slightly over 0.14993752603.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
.



Relevant Pages

  • Re: repeating elements in an array
    ... Hope everyone is in the pink of perfection! ... any constraint on the numbers and when we do define some constrain say ... Several people have suggested sorting the array. ...
    (comp.programming)
  • Re: repeating elements in an array
    ... Hope everyone is in the pink of perfection! ... any constraint on the numbers and when we do define some constrain say ... no two person have birthday on the same day of ...
    (comp.programming)
  • repeating elements in an array
    ... Hope everyone is in the pink of perfection! ... any constraint on the numbers and when we do define some constrain say ... What is the probability ... that no day can have more than 1 birthday. ...
    (comp.programming)
  • Re: Whats a Bday for if not to be daft?
    ... moved together and started to sing Happy Birthday to You ... She was carrying one of their iced fairy cakes and in the ... I cut the cake in half and we shared it! ... matured to perfection. ...
    (uk.people.silversurfers)
  • Re: repeating elements in an array
    ... Given an array in which only one pair of number is ... Now, if there is some constraint, it would be cool to know the constraint. ... repeating and one is missing, and you can find out which by adding all ... Also: google "birthday paradox". ...
    (comp.programming)