# Value in unsorted partition swaps lowest value with

• 3

This preview shows page 3 out of 3 pages.

value in unsorted partition, swaps lowest value with final value, 1 st value counted as sorted, finds the next lowest value in the unsorted partition, swaps it with 1 st value in the unsorted partition or behind the first value in the sorted parition, etc Insertion sort: starts left to right; calls first value sorted, moves right 1, compares first 2 values and swaps if neccesary, now calls first 2 values sorted, moves right 1, compares value with values in sorted and swaps if neccesary, then continues swapping if value is still lower than the values in sorted(7 8 5->7 5 8->5 7 8) moves right 1, and keeps going. Exponential Big O=O(2^n). Worst code, Ex: stooge sort, where u randomize the array and check if sorted, if not, randomize again and keep checking. Big O allows programmer to see if storage and speed is effective. If huge amount of data, don’t use slow methods like Quadratic sort Array: Traversing-O(N), search-O(N) or O(log N), remove or get unknown location item- O(N), add item-O(1), put item at specific location-O(N) Best Case Average Case Worst Case Linear Search O(1) O(N) O(N) Binary Search O(1) O(log N) O(log N) Selection Sort O(N^2) O(N^2) O(N^2) Bubble Sort O(N^2) O(N^2) O(N^2) Insertion Sort O(N) O(N^2) O(N^2) Merge Sort O(N log N) O(N log N) O(N log N) Quick Sort O(N log N) O(N log N) O(N^2) Heap Sort O(N log N) O(N log N) O(N log N)
• • • 