Sorting Algorithms

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Heap sort time complexity

O(n log n) in all cases

Mergesort time complexity

O(n log n) in all cases

Selection sort time complexity

O(n^2) in all cases

Quicksort time complexity

O(n^2) in the very unlikely worst case, O(n log n) in other cases

Bubble sort time complexity

O(n^2) worst case, O(n) best case

Insertion sort time complexity

O(n^2) worst case, O(n) best case

Insertion Sort

Sorts a list by placing each element in the position it should be in and gradually adding more elements one by one., A sort in which each item in a set is inserted into its proper position in the sorted set according to a specified criterion.

Selection Sort

Sorts a list by searching for the 1st element, then the 2nd, and so on until all the elements are in place., A sort in which the items in a set are examined to find an item that fits specified criteria. This item is appended to the sorted set and removed from further consideration, and the process is repeated until all items are in the sorted set.

Mergesort

Splits the list into sub-lists and then reconstructs the original list.

Quicksort

A sort in which a list is first partitioned into lower and upper sublists for which all keys are, respectively, less than some pivot key or greater than the pivot key. See also the definitions for "bubble sort", "selection sort" and "insertion sort".

Bubble Sort

A sort in which the first two items to be sorted are examined and exchanged if necessary to place them in the specified order; the second item is then compared with the third (exchanging them if required), the third is compared with the fourth, and the process is repeated until all pairs have been examined and all items are in the proper sequence.

Comparison sort

A sort that ranks items by comparing them to each other. As opposed to a sort that uses some other method, like the radix sort that analyzes the bits of each number.

Stable sort

Any sort method that does not change the order of equal-rank elements.

Heap sort

This algorithm is based on the heap data structure, and is a more efficient version of selection sort. It determines the largest element. Then, it places that element at the end (or beginning) of the list, and then repeats the process with the rest of the list Recall that in a heap, the top element of the heap is always "next" in order (either the next highest or next lowest, in the case of numbers). If you were to take all of your input values and store them in a heap, and remove one element at a time, the elements will be removed in sorted order. Depending on the data list being sorted, this could have performance consequences. Heap sort is considered an "instable" sort because it doesn't preserve the original order of equal elements.


Kaugnay na mga set ng pag-aaral

FNCE 495 - Chapter 11 - Final Exam

View Set

Unit 3 Quiz - Mandatory Disclosures

View Set

Mood, Adjustment, and Dementia Disorders

View Set

Test Bank Q: Chapter 18: Planning Nursing Care

View Set

Code, Standards, and Practices 2, Level II - 2020 Lesson 5

View Set

Subject SAT - US History (Before Contact)

View Set