public Tuple <double, double> RunInsertion(int arraySize, int nbArrays) { Init(arraySize, nbArrays); Stopwatch watch; double elapsedMsRedBlack = 0; double elapsedMsAVL = 0; for (int i = 0; i < nbArrays; i++) { RedBlackTree <int, string> rbTree = new RedBlackTree <int, string>(); watch = Stopwatch.StartNew(); rbTree.Add(0, "0"); watch.Stop(); double ticks = watch.ElapsedTicks; double microseconds = (ticks / Stopwatch.Frequency) * 1000000; elapsedMsRedBlack += microseconds; AVL avltree = new AVL(arrays[i]); watch = Stopwatch.StartNew(); avltree.Add(0); watch.Stop(); ticks = watch.ElapsedTicks; microseconds = (ticks / Stopwatch.Frequency) * 1000000; elapsedMsAVL += microseconds; } elapsedMsRedBlack /= nbArrays; elapsedMsAVL /= nbArrays; return(new Tuple <double, double>(elapsedMsRedBlack, elapsedMsAVL)); }
public override Tuple <double, double> RunDeletion(int arraySize, int nbArrays) { Init(arraySize, nbArrays); Stopwatch watch; double elapsedMsAVL = 0; double elapsedMsHeap = 0; for (int i = 0; i < nbArrays; i++) { AVL tree = new AVL(arrays[i]); tree.Add(0); watch = Stopwatch.StartNew(); tree.Delete(0); watch.Stop(); double ticks = watch.ElapsedTicks; double microseconds = (ticks / Stopwatch.Frequency) * 1000000; elapsedMsAVL += microseconds; MinHeap heap = new MinHeap(arrays[i]); heap.Insert(0); watch = Stopwatch.StartNew(); heap.Pop(); watch.Stop(); ticks = watch.ElapsedTicks; microseconds = (ticks / Stopwatch.Frequency) * 1000000; elapsedMsHeap += microseconds; } elapsedMsAVL /= nbArrays; elapsedMsHeap /= nbArrays; return(new Tuple <double, double>(elapsedMsAVL, elapsedMsHeap)); }
public override Tuple <double, double> RunDeletion(int arraySize, int nbArrays) { Init(arraySize, nbArrays); Stopwatch watch; double elapsedMsMutable = 0; double elapsedMsImmutable = 0; for (int i = 0; i < nbArrays; i++) { AVL tree = new AVL(arrays[i]); tree.Add(0); watch = Stopwatch.StartNew(); tree.Delete(0); watch.Stop(); double ticks = watch.ElapsedTicks; double microseconds = (ticks / Stopwatch.Frequency) * 1000000; elapsedMsMutable += microseconds; ImmutableAVL immutableAvl = new ImmutableAVL(arrays[i]); immutableAvl.Add(0); watch = Stopwatch.StartNew(); immutableAvl.Delete(0); watch.Stop(); ticks = watch.ElapsedTicks; microseconds = (ticks / Stopwatch.Frequency) * 1000000; elapsedMsImmutable += microseconds; } elapsedMsMutable /= nbArrays; elapsedMsImmutable /= nbArrays; return(new Tuple <double, double>(elapsedMsMutable, elapsedMsImmutable)); }
public void Insert(int[] values) { AVL tree = new AVL(values); tree.Add(5); Assert.AreEqual(values.Length + 1, tree.Count()); Assert.IsTrue(isAVLTreeValid(tree)); }
private void dichotomyTree(AVL tree, int[] array, int start, int end) { double middle = (end - start) / 2; int rootIndex = (int)Math.Floor(middle); tree.Add(array[start + rootIndex]); if (end - start > 0) { if (start + rootIndex - 1 >= 0) { dichotomyTree(tree, array, start, start + rootIndex - 1); } if (start + rootIndex + 1 >= 0 && end >= 0) { dichotomyTree(tree, array, start + rootIndex + 1, end); } } }
public static void Driver() { AVL avlTree = new AVL(); for (int i = 1; i <= 40; i++) { avlTree.Add(i); } avlTree.DisplayTree(); Console.WriteLine(); avlTree.Delete(15); avlTree.DisplayTree(); Console.WriteLine(); avlTree.Delete(3); avlTree.DisplayTree(); Console.WriteLine(); }