Rabin-Karp

internal override SearchResult Search(string text, string pattern) { if (pattern.Length > text.Length) return SearchResult.Empty(); SearchResult searchResult = new SearchResult() { Matches = new List<Match>() }; int patternHashValue = pattern.GetHashCode(); for(int index = 0; index + pattern.Length < text.Length; index++) { string indexString = text.Substring(index, pattern.Length); int indexHashValue = indexString.GetHashCode(); if(patternHashValue == indexHashValue) if (string.CompareOrdinal(pattern, indexString) …

Heapsort

internal class Heap : StorageObjectSort { private object[] items; public int Size { get; set; } = 0; public override IEnumerable<T> Sort<T>(IComparer<T> sortFunction, IEnumerable<T> collection) { List<T> objectList = collection.ToList(); Initialize(objectList.Count); objectList.ForEach(o => Insert(o, sortFunction)); objectList.Clear(); while (Size > 0) objectList.Add((T)Remove(sortFunction)); return objectList; } protected override void Insert<T>(object item, IComparer<T> sortFunction) { items[Size] = item; …

Combosort

public override IEnumerable<T> Sort<T>(IComparer<T> sortFunction, IEnumerable<T> collection) { List<T> objectList = collection.ToList(); //Calculate an efficient step size. //Ofc it depends on many factors and it won’t be perfect in every case. int divideValue = (int)Math.Pow(objectList.Count, 1 / 3); for (int partCount = divideValue; partCount > 0; partCount–) { //Split the objectList up into smaller lists …

Shellsort

public override IEnumerable<T> Sort<T>(IComparer<T> sortFunction, IEnumerable<T> collection) { List<T> objectList = collection.ToList(); //Calculate an efficient step size. //Ofc it depends on many factors and it won’t be perfect in every case. int divideValue = (int)Math.Pow(objectList.Count, 1 / 3); for (int partCount = divideValue; partCount > 0; partCount–) { //Split the objectList up into smaller lists …

Inserationsort

internal class Insertion : ObjectSort { public override IEnumerable<T> Sort<T>(IComparer<T> sortFunction, IEnumerable<T> collection) { List<T> objectList = collection.ToList(); for (int currentIndex = 1; currentIndex < objectList.Count; currentIndex++) { //Put the current object into a buffer. T objectBuffer = objectList[currentIndex]; //The index we have to shift. int shiftIndex = 0; //Shift all from 0 to the …

Heapsort

  Die Datenstruktur des Heapsortes ist ein Binärbaum. An der “Wurzel” des Baumes befindet sich immer das Element, welches als nächstes benötigt wird. (Min,Max,Priority,etc.) Somit muss beim Einfügen und beim Entfernen eines Elementes der Baum immer wieder sortiert werden. Die Laufzeit ist hierbei asymptotisch und beträgt O(n * log(n)).