Sorting Flashcards
Sorting is the process…
Converting a list of elements into ascending order
What is Selection Sort?
Sorting algorithm that treats the input as 2 parts.
A sorted part and an unsorted part
What is Insertion Sort?
An algorithm that starts at the i = 1 element and skips over the 0th element
What is a nearly sorted list?
A list that only contains a few elements not in sorted order
What is the best case for insertion sort?
When the list is in ascending order
What is the worst case for insertion sort?
When the list is in descending order
What is QuickSort?
Repeatedly sorts the input into low and high partions and then recursively sorts those parts
What is the pivot?
The pivot can be any value but it is commonly the middle of the array
numbers[midpoint val] = pivot
What is the formula for the midpoint?
i + (k -i)/ 2
i is the value of the index
If the midpoint is calculated and the number of the array is even, what is the number?
Round the number down and that is your midpoint. Example(3/2 = 1.5 round down to 1)
The pivot of an even array would be…
The index of the midpoint calculated. Example(Midpoint = 1, index 1 is equal to whatever the number is)
How many levels are required for a list of 1024 elements
N -1 = levels
1024 -1 = 1023
How many total comparisons are required for a list of 1024 elements
(N-1)N
=(1024-1)1024=1047552
What is merge sort?
Divides a list into 2 halves, recursively sorts each half and hen merges the sorted haves to produce a list
How many variables are used to keep track of the elements?
3