Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
based on comparisons
M Shoaib Farooq
5/14/2012
Sorting So Far
Insertion sort:
Easy to code
Fast on small inputs (less than ~50 elements)
Fast on nearly-sorted inputs
O(n2) worst case
O(n2) average (equally-likely inputs) case
O(n2) reverse-sorted case
M Shoaib Farooq
5/14/2012
Sorting So Far
Merge sort:
Divide-and-conquer:
Split
array in half
Recursively sort subarrays
Linear-time merge step
M Shoaib Farooq
5/14/2012
Sorting So Far
Heap sort:
binary tree
Heap property: parent key > childrens keys
M Shoaib Farooq
5/14/2012
Sorting So Far
Quick sort:
Divide-and-conquer:
Partition
5/14/2012
M Shoaib Farooq
5/14/2012
M Shoaib Farooq
5/14/2012
Decision Trees
M Shoaib Farooq
5/14/2012
Decision Trees
(Example)
M Shoaib Farooq
5/14/2012
n
n!
e
M Shoaib Farooq
n
h lg
e
10
5/14/2012
So we have
n
h lg
e
n lg n n lg e
n lg n
M Shoaib Farooq
11
5/14/2012