Sorts Flashcards
Internal need for sorting
Binary search
External need for sorting
Names in alphabetical order
What are total orders?
Assignment of an ordering to every pair of elements
What are partial orders?
Not an assignment for an ordering for every pair of elements
What is a sort algorithm?
The placement of a structure into the order induced by the sort order
How does an insertion sort work?
- walk along a list
- if value is larger than one of its left, do nothing
- if it is smaller, shuffle the elements to its left and insert it into the correct place
What is the average time for an insertion sort?
O(n^2)
What is the space for insertion sort?
O(1)
Describe the workings of a selection sort
- Search for the lowest value
- Swap it with the first element
- Continue from the second element
Average complexity of selection sort
O(n^2)
What are the three stages in a divide and conquer algorithm?
Divide
Recurse
Conquer
Describe the divide stage of divide and conquer
Take a problem S and split it into two smaller sub problems S1 and S2
Describe the recurse stage of divide and conquer
Recursively solve S1 and S2, either directly (by the base case) or by further division
Describe the conquer stage of divide and conquer
Combine the solutions to S1 and S2 into a solution to S
What type of algorithm is a merge sort?
Divide and conquer
Structural