## Archive for July 19th, 2012

In computational complexity theory, 3SUM is the following computational problem conjectured to require roughly quadratic time:

Given a set S of n integers, are there elements a, b, c in S such that a + b + c = 0?

It is possible to solve the algorithm in O(n2) time using simple algorithms, and matching lower bounds are known for some specialized models of computation.

The program mentioned below works only with sorted List

``` public static void SortedList3SumProblem(int[] inputArray)
{
int a, b, c;
int length = inputArray.Length;
for (int i = 0; i < length - 3; i++)
{

a = inputArray[i];
int k = i + 1;
int l = length  - 1;

while (k < l)
{
b = inputArray[k];
c = inputArray[l];
if (a + b + c == 0)
{
Console.WriteLine(a + "," + b + "," + c); ;
break;
}
else if (a + b + c > 0)
l = l - 1;
else
k = k + 1;
}

}
}```

# Input

0, -25, -10, -7, -3, 2, 4, 8, 10

# Output

Input Array

0;-25;-10;-7;-3;2;4;8;10

——————————–

0,-10,10

-10,2,8

-7,-3,10

``` public static void RepeatedEvenTimes(int[] inputArray)
{
Dictionary<int, int> numbers = new Dictionary<int, int>();
int length = inputArray.Length;
int num = -1;
for (int i = 0; i < length; i++)
{
if (numbers.Keys.Contains(inputArray[i]))
{
numbers[inputArray[i]] = numbers[inputArray[i]] + 1;
}
else
{

}
}

Console.Write("input Array ");
Console.WriteLine(string.Join(",", inputArray));

foreach (var item in numbers)
{
if (item.Value % 2 == 0)
{
num = item.Key;
Console.WriteLine("{0} Repeated {1} times ", item.Key, item.Value);
break;
}

}

if (num == -1)
{
Console.WriteLine("No number Repeated even number of times");
}

Console.WriteLine("-----------------------------------------------");
}```
` `

input Array 3,3,3,5,5,5,2,2,2
No number Repeated even number of times
———————————————–
input Array 100,1,1,3,5,3,3
1 Repeated 2 times
———————————————–
input Array 2,2,2,2,2
No number Repeated even number of times
———————————————–