Sairam
BAN USERI have found out more now...
down vote
This page summarises some of the time comlplexities for various collection types with Java, though they should be exactly the same for .NET.
I've taken the tables from that page and altered/expanded them for the .NET framework. See also the MSDN pages for SortedDictionary and SortedList, which detail the time complexities required for various operations.
--------------------------------------------------------------------------------
Searching
Type of Search/Collection Types Complexity Comments
Linear search Array/ArrayList/LinkedList O(N) Unsorted data.
Binary search sorted Array/ArrayList/ O(log N) Requires sorted data.
Search Hashtable/Dictionary<T> O(1) Uses hash function.
Binary search SortedDictionary/SortedKey O(log N) Sorting is automated.
static void Main(string[] args)
{
int[] input = { 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 12, 3, 34, 1 };
int firstNumber = input[0], secondNumber = input[0];
var number2 = new HashSet<int>();
var numbers = new Dictionary<int, int>();
foreach (int t in input)
{
if (numbers.ContainsKey(t))
{
numbers[t]++;
}
else
{
numbers.Add(t, 1);
continue;
}
}
foreach (KeyValuePair<int, int> abc in numbers)
{
if (abc.Value == 1)
{
Console.WriteLine(abc.Key);
break;
}
}
Console.ReadLine();
}
instead what i was thinking the hash map what you are calling i will call it is a key value pair or a dictionary(i am more a .Net guy).
for every element we will check if the entry is present in the dictionary or not by simple trying to retrieve the value by passing the ky, if it is present let us increment the count of the value.
at the end we can check whose count is only one and then print the output. how does that sound
static void Main(string[] args)
{
int[] input = {1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6,1, 12, 3, 34, 1};
int firstNumber= input[0], secondNumber = input[0];
var numbers = new Dictionary<int, int>();
foreach (int t in input)
{
try
{
if (numbers[t] == 0)
{ }
}
catch (Exception)
{
numbers.Add(t, 1);
continue;
}
numbers[t]++;
}
foreach (KeyValuePair<int, int> abc in numbers)
{
if (abc.Value == 1)
{
Console.WriteLine(abc.Key);
break;
}
}
Console.ReadLine();
}
Store user and product withslist information in table or data structure. When new stock comes in, do a join on the product id and get the list of customers with the corresponding product wish list and send a notification to them..
just another thought, is this simple, or there is something underthe hood for the problem
as per my understanding, what is the reason we need to consider only till a group of 10.
say we have an array essentially a integer array in which each array member refers to 100 locations each. The array can take values from 1 to 10 0 saying that there is no place avaible. a value of 1 means that a slot is available in the first 10 slots of the level.
to take it more generic. 100 will be the number of cars a level of car parking can host. and 0 will be the a not available state, and starting from 1 we can basically say whether the slot is available or not, if it is not zero then where it is available.
Thoughts ?
permutation and combination problem, reminds me the dynamic programming approach
- Sairam May 16, 2012