# Math Help - algorthims

1. ## 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

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.

3. it is meant to count the number of pairs of integers in a list

4. 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.

5. Originally Posted by TKHunny

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

6. 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.

7. it only need to work with the subsetthat i gace of 2.3.6.2.6

many many thanks