Opertaion | Unsorted Array | Sorted Array |
---|---|---|
Search | O(n) | O(log n) |
Insert | O(1) [Shove it at the end] | O(n) [Have to find insertion point and remaing elements down one] |
Delete | O(n)
--or-- O(1) [If you know where in the array it is and us the trick above] | O(n) [Have to move other populated elements up one] |
Next | O(n) [Preusumes next means 'the item with the next highest key value] | O(1) |
Previous | O(n) [Preusumes next means 'the item with the next lowest key value] | O(1) |
Min key | O(n) | O(1) [First populated element of the array] |
Max key | O(n)
--or-- O(1) if you maintain a copy of the maximum key and update it during add and delete operations AND your delete operation is the O(n) version. | O(1) [Last populated element of the array] |
List<Func<int>> actions = new List<Func<int>>(); for (int i = 0; i < 5; i++) { actions.Add(() => i * 5); } foreach (Func<int> func in actions) Console.WriteLine(func.Invoke()); // Prints 25 five times
var results = from c in Categories join p in Products on c.Id equals p.CategoryId select new { CatName = c.Name, CatId = c.Id, ProdName = p.Name }; foreach (var result in results) Console.WriteLine("{0},{1},{2}", result.CatName, result.CatId, result.ProdName);
XElement e = new XElement("x", new XElement("y", null)); Console.WriteLine(e.ToString()); // <x><y /></x>
// First non-repeating character var x = (from c in "First non-repeating character".ToUpperInvariant() group c by c into g where g.Count() == 1 select g).FirstOrDefault(); Console.WriteLine(x.Key);