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

Begin

input ...

count := 0

fori:= 2 to ndo

begin

forj:=1 to (i-1)do

begin

ifthen

begin

count := count +1

end

end

output count

end

much thanks

Results 1 to 7 of 7

- April 17th 2008, 10:36 AM #1

- Joined
- Apr 2008
- Posts
- 19

- April 17th 2008, 11:52 AM #2

- Joined
- Aug 2007
- From
- USA
- Posts
- 3,110
- Thanks
- 2

- April 17th 2008, 11:55 AM #3

- Joined
- Apr 2008
- Posts
- 19

- April 17th 2008, 12:11 PM #4

- Joined
- Aug 2007
- From
- USA
- Posts
- 3,110
- Thanks
- 2

- April 17th 2008, 12:22 PM #5

- Joined
- Apr 2008
- Posts
- 19

- April 17th 2008, 12:34 PM #6

- Joined
- Aug 2007
- From
- USA
- Posts
- 3,110
- 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.

- April 17th 2008, 12:38 PM #7

- Joined
- Apr 2008
- Posts
- 19