- Merge Sort: It is divider and conquer technique.
- Divide the array into two halves using MergeSort() function.
- Merge the two sub arrays into single in sorted order using Merge() function.
- Merge sort program in c#
- Time complexity O(n logn).
- Insertion Sort:
- Its like Playing cards., take an element, Find location / index to insert this new element, by Comparing with all existing elements.
- InsertionSort in C#
- Time complexity O(n * n).
- Selection Sort:
- Sorts an array by repeatedly finding the minimum element from unsorted part of array.
- Selection sort in c#
- Time complexity O(n * n).
Sunday, September 16, 2018
Sorting Algorithms
Thursday, September 6, 2018
LINQ Single vs SingleOrDefault vs First vs FirstOrDefault
Single() | SingleOrDefault() | First() | FirstOrDefault() | |
---|---|---|---|---|
Description | Returns a single, specific element of a sequence | Returns a single, specific element of a sequence, or a default value if that element is not found | Returns the first element of a sequence | Returns the first element of a sequence, or a default value if no element is found |
Exception thrown when | There are 0 or more than 1 elements in the result | There is more than one element in the result | There are no elements in the result | Only if the source is null (they all do this) |
When to use | If exactly 1 element is expected; not 0 or more than 1 | When 0 or 1 elements are expected | When more than 1 element is expected and you want only the first | When more than 1 element is expected and you want only the first. Also it is ok for the result to be empty |
Subscribe to:
Posts (Atom)