Results 1 to 7 of 7

Math Help - algorthims

  1. #1
    Newbie
    Joined
    Apr 2008
    Posts
    19

    algorthims

    i need to verify that the following algorthims works on the list 2, 3,6,2,6

    Begin
    input x_1 x_2... x_n
    count := 0
    for i:= 2 to n do
    begin
    for j:=1 to (i-1) do
    begin
    if x_i = x_j then
    begin
    count := count +1
    end
    end
    output count
    end

    much thanks
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Aug 2007
    From
    USA
    Posts
    3,111
    Thanks
    2
    What's it supposed to do? If you are counting duplicates, that's not it. Try 2 3 6 2 6 5 5 5 5 to disprove it.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Apr 2008
    Posts
    19
    it is meant to count the number of pairs of integers in a list
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Aug 2007
    From
    USA
    Posts
    3,111
    Thanks
    2
    In your universe of inputs, will there EVER be more than two of any single integer?

    Your algorithm will produce 3 from 2 2 2. If the trio condition never occurs, then perhaps you are done.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Apr 2008
    Posts
    19
    Quote Originally Posted by TKHunny View Post

    Your algorithm will produce 3 from 2 2 2. If the trio condition never occurs, then perhaps you are done.

    i don't understand that how can you get 2 2 2, when there are only two 2's in the list
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor
    Joined
    Aug 2007
    From
    USA
    Posts
    3,111
    Thanks
    2
    I'm reviewing your algorithm, not your data. I made up my own data.

    Why would you need an algorithm to count pairs if the data you provided was the entire universe of data? Just count them. Pair of 2's Pair of 6's. There, 2 pairs. Done.

    Should your algorithm work with ANY data, or just some clear subset, such as that you have provided? If it needs to work on ANY data, then you'll get some double counting. If you can guarantee that there never will be a trio or a quartet or worse, then perhaps you are done.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Apr 2008
    Posts
    19
    it only need to work with the subsetthat i gace of 2.3.6.2.6

    many many thanks
    Follow Math Help Forum on Facebook and Google+

Search Tags


/mathhelpforum @mathhelpforum