150 likes | 355 Views
Sort and Tree. 2014 Spring CS32 Discussion Jungseock Joo. Selection Sort. - From wikipedia.com. Bubble Sort. Merge Sort. Quicksort. Time Complexity. Divide-and-conquer : O(n log 2 n) Otherwise, O(n 2 ). When use what?. In practice std::sort();
E N D
Sort and Tree 2014 Spring CS32 Discussion JungseockJoo
Selection Sort - From wikipedia.com
Time Complexity • Divide-and-conquer : O(n log2n) • Otherwise, O(n2)
When use what? • In practice • std::sort(); • If n is small, you may choose simpler ones. • Considerations • Worst-case performance? • Already sorted? Partially-already sorted? Reversed order? • # of comparisons vs. # of swap/shift
Binary Search Tree • Find 7?
Binary Search Tree • Find 7? – O(log n) Depth of tree ~ log n If balanced.
Binary Search Tree • But, O(n) in unbalanced BSTs • Depth >> log n Depth of tree ~ n If unbalanced.